Skip to content

Commit

Permalink
[#11944] Fix incorrect logic for chart calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
intr3p1d committed Jan 24, 2025
1 parent 6409d79 commit 6509131
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
*/
public class UriStatSummaryEntity extends UriStatChartEntity {
private String uri;
private Double apdexRaw;
private Double totalApdexRaw;
private Double totalCount;
private Double failureCount;
private Double maxTimeMs;
private Double totalTimeMs;
private Double sumOfTotalTimeMs;
private String version;

public UriStatSummaryEntity() {
Expand All @@ -38,12 +38,12 @@ public void setUri(String uri) {
this.uri = uri;
}

public Double getApdexRaw() {
return apdexRaw;
public Double getTotalApdexRaw() {
return totalApdexRaw;
}

public void setApdexRaw(Double apdexRaw) {
this.apdexRaw = apdexRaw;
public void setTotalApdexRaw(Double totalApdexRaw) {
this.totalApdexRaw = totalApdexRaw;
}

public Double getTotalCount() {
Expand All @@ -70,12 +70,12 @@ public void setMaxTimeMs(Double maxTimeMs) {
this.maxTimeMs = maxTimeMs;
}

public Double getTotalTimeMs() {
return totalTimeMs;
public Double getSumOfTotalTimeMs() {
return sumOfTotalTimeMs;
}

public void setTotalTimeMs(Double totalTimeMs) {
this.totalTimeMs = totalTimeMs;
public void setSumOfTotalTimeMs(Double totalTimeMs) {
this.sumOfTotalTimeMs = totalTimeMs;
}

public String getVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import com.navercorp.pinpoint.common.util.MathUtils;
import com.navercorp.pinpoint.uristat.web.entity.UriStatChartEntity;
import com.navercorp.pinpoint.uristat.web.entity.UriStatSummaryEntity;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import org.mapstruct.Named;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
Expand All @@ -51,12 +49,12 @@ static <T> List<T> subList(List<T> list, long limit) {

@Named("toApdex")
public static Double toApdex(UriStatSummaryEntity entity) {
return MathUtils.average(entity.getApdexRaw(), entity.getTotalCount());
return MathUtils.average(entity.getTotalApdexRaw(), entity.getTotalCount());
}

@Named("toAvgTimeMs")
public static Double toAvgTimeMs(UriStatSummaryEntity entity) {
return MathUtils.average(entity.getTotalTimeMs(), entity.getTotalCount());
return MathUtils.average(entity.getSumOfTotalTimeMs(), entity.getTotalCount());
}

@Named("toTotalHistogram")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,34 @@ public boolean isApplicationStat() {

private enum OrderBy {
URI("uri"),
APDEX("apdex", "(apdexRaw / totalCount)"),
APDEX("apdex", "(apdexRaw / totalCount)", "(totalApdexRaw / totalCount)"),
TOTAL("totalCount"),
FAILURE("failureCount"),
MAX("maxTimeMs"),
AVG("avgTimeMs", "(totalTimeMs / totalCount)");
AVG("avgTimeMs", "(totalTimeMs / totalCount)", "(sumOfTotalTimeMs / totalCount)");

private final String name;
private final String desc;
private String optional;

private static final EnumGetter<OrderBy> GETTER = new EnumGetter<>(OrderBy.class);

OrderBy(String name) {
this.name = name;
this.desc = name;
this.optional = name;
}

OrderBy(String name, String desc) {
this.name = name;
this.desc = desc;
this.optional = desc;
}

OrderBy(String name, String desc, String optional) {
this.name = name;
this.desc = desc;
this.optional = optional;
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@
</sql>

<sql id="apdexChart">
sum(apdexRaw) as apdexRaw,
sum("count") as "count",
</sql>

<sql id="latencyChart">
sum(totalTimeMs) as totalTimeMs,
max(maxLatencyMs) as maxLatencyMs,
sum("count") as "count",
</sql>
Expand All @@ -64,10 +66,10 @@
DATETIMECONVERT("timestamp", '1:MILLISECONDS:EPOCH', '1:MILLISECONDS:EPOCH',
'#{timePrecision.timeSize}:${timePrecision.timeUnit}') as "timestamp",
uri,
sum(sum(apdexRaw)) OVER (PARTITION BY uri, version) as apdexRaw,
sum(sum(apdexRaw)) OVER (PARTITION BY uri, version) as totalApdexRaw,
sum(sum("count")) OVER (PARTITION BY uri, version) as totalCount,
max(max(maxLatencyMs)) OVER (PARTITION BY uri, version) as maxTimeMs,
sum(sum(totalTimeMs)) OVER (PARTITION BY uri, version) as totalTimeMs,
sum(sum(totalTimeMs)) OVER (PARTITION BY uri, version) as sumOfTotalTimeMs,
sum(sum(failureCount)) OVER (PARTITION BY uri, version) as failureCount,
version
FROM uriStat
Expand All @@ -78,7 +80,7 @@
</if>
AND "timestamp" BETWEEN #{range.from} AND #{range.to}
GROUP BY "timestamp", uri, version
ORDER BY ${orderBy} ${isDesc}
ORDER BY ${orderBy.optional} ${isDesc}
LIMIT #{tenTimesLimit}
</sql>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void toModel() {
entity.setFailureCount(10.0);
entity.setMaxTimeMs(200.0);
entity.setVersion("version");
entity.setApdexRaw(50.0);
entity.setTotalTimeMs(1000.0);
entity.setTotalApdexRaw(50.0);
entity.setSumOfTotalTimeMs(1000.0);

UriStatSummary model = mapper.toModel(entity);

Expand Down

0 comments on commit 6509131

Please sign in to comment.