Skip to content

Commit

Permalink
[pinpoint-apm#8778] Apply SummaryStatistics
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Apr 15, 2022
1 parent f7d2357 commit 8318e99
Show file tree
Hide file tree
Showing 30 changed files with 161 additions and 713 deletions.
4 changes: 4 additions & 0 deletions commons-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* @author Taejin Koo
*/
public interface JoinEncodingStrategy<T extends JoinFieldBo> extends EncodingStrategy<T> {
public interface JoinEncodingStrategy<T extends JoinFieldBo<? extends Number>> extends EncodingStrategy<T> {

byte[] getCodes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
/**
* @author Taejin Koo
*/
public interface JoinFieldStrategyAnalyzer<T extends JoinFieldBo> {
public interface JoinFieldStrategyAnalyzer<T extends JoinFieldBo<? extends Number>> {

EncodingStrategy<T> getBestStrategy();

List<T> getValues();

interface JoinFieldStrategyAnalyzerBuilder<T extends JoinFieldBo> {
interface JoinFieldStrategyAnalyzerBuilder<T extends JoinFieldBo<? extends Number>> {

JoinFieldStrategyAnalyzerBuilder<T> addValue(T value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.navercorp.pinpoint.common.server.bo.serializer.stat;

import java.math.BigDecimal;
import org.apache.commons.math3.util.Precision;

import static com.navercorp.pinpoint.common.hbase.HbaseColumnFamily.AGENT_STAT_STATISTICS;

Expand Down Expand Up @@ -45,7 +45,7 @@ public static double calculateRate(long count, long timeMs, int numDecimals, dou
if (timeMs < 1) {
return defaultRate;
}
return new BigDecimal(count / (timeMs / 1000D)).setScale(numDecimals, BigDecimal.ROUND_HALF_UP).doubleValue();
return Precision.round(count / (timeMs / 1000D), numDecimals);
}

public static long getBaseTimestamp(long timestamp) {
Expand Down
4 changes: 4 additions & 0 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import com.navercorp.pinpoint.common.trace.BaseHistogramSchema;
import com.navercorp.pinpoint.common.trace.HistogramSchema;
import com.navercorp.pinpoint.common.trace.HistogramSlot;
import com.navercorp.pinpoint.common.util.CollectionUtils;
import com.navercorp.pinpoint.web.vo.chart.Point;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers;
import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.TitledAgentStatPoint;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.math3.util.Precision;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.function.ToIntFunction;

Expand All @@ -40,8 +40,6 @@
@Component
public class ActiveTraceSampler implements AgentStatSampler<ActiveTraceBo, SampledActiveTrace> {

private static final DownSampler<Integer> INTEGER_DOWN_SAMPLER = DownSamplers.getIntegerDownSampler(SampledActiveTrace.UNCOLLECTED_COUNT);

@Override
public SampledActiveTrace sampleDataPoints(int timeWindowIndex, long timestamp, List<ActiveTraceBo> dataPoints, ActiveTraceBo previousDataPoint) {

Expand Down Expand Up @@ -89,13 +87,16 @@ private AgentStatPoint<Integer> createSampledTitledPoint(String title, long time
if (CollectionUtils.isEmpty(values)) {
return SampledActiveTrace.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp);
}

IntSummaryStatistics stats = values.stream()
.mapToInt(Integer::intValue)
.summaryStatistics();
double avg = Precision.round(stats.getAverage(), 1);
return new TitledAgentStatPoint<>(
title,
timestamp,
INTEGER_DOWN_SAMPLER.sampleMin(values),
INTEGER_DOWN_SAMPLER.sampleMax(values),
INTEGER_DOWN_SAMPLER.sampleAvg(values, 1),
INTEGER_DOWN_SAMPLER.sampleSum(values));
stats.getMin(),
stats.getMax(),
avg,
(int) stats.getSum());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import com.navercorp.pinpoint.web.vo.chart.Point;
import com.navercorp.pinpoint.web.vo.chart.UncollectedPointCreatorFactory;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

Expand All @@ -30,13 +30,8 @@
public class AgentStatPointFactory {

private final Point.UncollectedPointCreator<AgentStatPoint<Integer>> uncollectedIntValuePointCreator;
private final DownSampler<Integer> intDownSampler;

private final Point.UncollectedPointCreator<AgentStatPoint<Long>> uncollectedLongValuePointCreator;
private final DownSampler<Long> longDownSampler;

private final Point.UncollectedPointCreator<AgentStatPoint<Double>> uncollectedDoubleValuePointCreator;
private final DownSampler<Double> doubleDownSampler;

private final int defaultValueDecimal;

Expand All @@ -46,13 +41,8 @@ public AgentStatPointFactory(int uncollectedIntValue, long uncollectedLongValue,

public AgentStatPointFactory(int uncollectedIntValue, long uncollectedLongValue, double uncollectedDoubleValue, int defaultValueDecimal) {
this.uncollectedIntValuePointCreator = UncollectedPointCreatorFactory.createIntPointCreator(uncollectedIntValue);
this.intDownSampler = DownSamplers.getIntegerDownSampler(uncollectedIntValue);

this.uncollectedLongValuePointCreator = UncollectedPointCreatorFactory.createLongPointCreator(uncollectedLongValue);
this.longDownSampler = DownSamplers.getLongDownSampler(uncollectedLongValue);

this.uncollectedDoubleValuePointCreator = UncollectedPointCreatorFactory.createDoublePointCreator(uncollectedDoubleValue);
this.doubleDownSampler = DownSamplers.getDoubleDownSampler(uncollectedDoubleValue);

this.defaultValueDecimal = defaultValueDecimal;
}
Expand All @@ -62,50 +52,32 @@ public AgentStatPoint<Integer> createIntPoint(long timestamp, List<Integer> valu
}

public AgentStatPoint<Integer> createIntPoint(long timestamp, List<Integer> values, int numDecimals) {
if (values.isEmpty()) {
if (CollectionUtils.isEmpty(values)) {
return uncollectedIntValuePointCreator.createUnCollectedPoint(timestamp);
}

return new AgentStatPoint<>(
timestamp,
intDownSampler.sampleMin(values),
intDownSampler.sampleMax(values),
intDownSampler.sampleAvg(values, numDecimals),
intDownSampler.sampleSum(values));
return AgentStatPointSummary.intSummary(timestamp, values, numDecimals);
}

public AgentStatPoint<Long> createLongPoint(long timestamp, List<Long> values) {
return createLongPoint(timestamp, values, defaultValueDecimal);
}

public AgentStatPoint<Long> createLongPoint(long timestamp, List<Long> values, int numDecimals) {
if (values.isEmpty()) {
if (CollectionUtils.isEmpty(values)) {
return uncollectedLongValuePointCreator.createUnCollectedPoint(timestamp);
}

return new AgentStatPoint<>(
timestamp,
longDownSampler.sampleMin(values),
longDownSampler.sampleMax(values),
longDownSampler.sampleAvg(values, numDecimals),
longDownSampler.sampleSum(values));
return AgentStatPointSummary.longSummary(timestamp, values, numDecimals);
}

public AgentStatPoint<Double> createDoublePoint(long timestamp, List<Double> values) {
return createDoublePoint(timestamp, values, defaultValueDecimal);
}

public AgentStatPoint<Double> createDoublePoint(long timestamp, List<Double> values, int numDecimals) {
if (values.isEmpty()) {
if (CollectionUtils.isEmpty(values)) {
return uncollectedDoubleValuePointCreator.createUnCollectedPoint(timestamp);
}

return new AgentStatPoint<>(
timestamp,
doubleDownSampler.sampleMin(values),
doubleDownSampler.sampleMax(values),
doubleDownSampler.sampleAvg(values, numDecimals),
doubleDownSampler.sampleSum(values));
return AgentStatPointSummary.doubleSummary(timestamp, values, numDecimals);
}

public Point.UncollectedPointCreator<AgentStatPoint<Integer>> getUncollectedIntValuePointCreator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo;
import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint;

import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
Expand All @@ -35,7 +35,6 @@
public class CpuLoadSampler implements AgentStatSampler<CpuLoadBo, SampledCpuLoad> {

private static final int NUM_DECIMAL_PLACES = 1;
private static final DownSampler<Double> DOUBLE_DOWN_SAMPLER = DownSamplers.getDoubleDownSampler(SampledCpuLoad.UNCOLLECTED_PERCENTAGE, NUM_DECIMAL_PLACES);

@Override
public SampledCpuLoad sampleDataPoints(int timeWindowIndex, long timestamp, List<CpuLoadBo> dataPoints, CpuLoadBo previousDataPoint) {
Expand Down Expand Up @@ -63,9 +62,9 @@ private List<Double> filter(List<CpuLoadBo> dataPoints, ToDoubleFunction<CpuLoad
}

private AgentStatPoint<Double> createPoint(long timestamp, List<Double> values) {
if (values.isEmpty()) {
if (CollectionUtils.isEmpty(values)) {
return SampledCpuLoad.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp);
}
return new AgentStatPoint<>(timestamp, values, DOUBLE_DOWN_SAMPLER);
return AgentStatPointSummary.doubleSummaryWithAllScale(timestamp, values, NUM_DECIMAL_PLACES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
package com.navercorp.pinpoint.web.mapper.stat.sampling.sampler;

import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo;
import com.navercorp.pinpoint.common.util.CollectionUtils;
import com.navercorp.pinpoint.web.vo.stat.SampledDataSource;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
Expand All @@ -33,8 +32,6 @@
@Component
public class DataSourceSampler implements AgentStatSampler<DataSourceBo, SampledDataSource> {

private static final DownSampler<Integer> INTEGER_DOWN_SAMPLER = DownSamplers.getIntegerDownSampler(SampledDataSource.UNCOLLECTED_VALUE);

@Override
public SampledDataSource sampleDataPoints(int timeWindowIndex, long timestamp, List<DataSourceBo> dataSourceBoList, DataSourceBo previousDataSourceBo) {
if (CollectionUtils.isEmpty(dataSourceBoList)) {
Expand Down Expand Up @@ -88,16 +85,11 @@ public SampledDataSource sampleDataPoints(int timeWindowIndex, long timestamp, L
}

private AgentStatPoint<Integer> createPoint(long timestamp, List<Integer> values) {
if (values.isEmpty()) {
if (CollectionUtils.isEmpty(values)) {
return SampledDataSource.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp);
} else {
return new AgentStatPoint<>(
timestamp,
INTEGER_DOWN_SAMPLER.sampleMin(values),
INTEGER_DOWN_SAMPLER.sampleMax(values),
INTEGER_DOWN_SAMPLER.sampleAvg(values, 3),
INTEGER_DOWN_SAMPLER.sampleSum(values));
}

return AgentStatPointSummary.intSummary(timestamp, values, 3);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import com.navercorp.pinpoint.common.server.bo.stat.DeadlockThreadCountBo;
import com.navercorp.pinpoint.web.vo.stat.SampledDeadlock;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint;

import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
Expand All @@ -33,8 +33,6 @@
@Component
public class DeadlockSampler implements AgentStatSampler<DeadlockThreadCountBo, SampledDeadlock> {

private static final DownSampler<Integer> INTEGER_DOWN_SAMPLER = DownSamplers.getIntegerDownSampler(SampledDeadlock.UNCOLLECTED_COUNT);

@Override
public SampledDeadlock sampleDataPoints(int index, long timestamp, List<DeadlockThreadCountBo> deadlockThreadCountBoList, DeadlockThreadCountBo previousDataPoint) {
List<Integer> deadlockedThreadCountList = filter(deadlockThreadCountBoList);
Expand All @@ -55,10 +53,10 @@ public List<Integer> filter(List<DeadlockThreadCountBo> deadlockThreadCountBoLis
}

private AgentStatPoint<Integer> createPoint(long timestamp, List<Integer> values) {
if (values.isEmpty()) {
if (CollectionUtils.isEmpty(values)) {
return SampledDeadlock.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp);
}
return new AgentStatPoint<>(timestamp, values, INTEGER_DOWN_SAMPLER);
return AgentStatPointSummary.intSummary(timestamp, values);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import com.navercorp.pinpoint.common.server.bo.stat.DirectBufferBo;
import com.navercorp.pinpoint.web.vo.stat.SampledDirectBuffer;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
Expand All @@ -33,9 +33,6 @@
@Component
public class DirectBufferSampler implements AgentStatSampler<DirectBufferBo, SampledDirectBuffer> {

private static final DownSampler<Long> LONG_DOWN_SAMPLER = DownSamplers.getLongDownSampler(SampledDirectBuffer.UNCOLLECTED_VALUE);


@Override
public SampledDirectBuffer sampleDataPoints(int timeWindowIndex, long timestamp, List<DirectBufferBo> dataPoints, DirectBufferBo previousDataPoint) {
final AgentStatPoint<Long> directCount = newAgentStatPoint(timestamp, dataPoints, DirectBufferBo::getDirectCount);
Expand Down Expand Up @@ -64,9 +61,9 @@ private List<Long> filter(List<DirectBufferBo> dataPoints, ToLongFunction<Direct
}

private AgentStatPoint<Long> createPoint(long timestamp, List<Long> values) {
if (values.isEmpty()) {
if (CollectionUtils.isEmpty(values)) {
return SampledDirectBuffer.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp);
}
return new AgentStatPoint<>(timestamp, values, LONG_DOWN_SAMPLER);
return AgentStatPointSummary.longSummary(timestamp, values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

import com.navercorp.pinpoint.common.server.bo.stat.FileDescriptorBo;
import com.navercorp.pinpoint.web.vo.stat.SampledFileDescriptor;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler;
import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPointSummary;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
Expand All @@ -33,8 +32,6 @@
@Component
public class FileDescriptorSampler implements AgentStatSampler<FileDescriptorBo, SampledFileDescriptor> {

private static final DownSampler<Long> LONG_DOWN_SAMPLER = DownSamplers.getLongDownSampler(SampledFileDescriptor.UNCOLLECTED_VALUE);


@Override
public SampledFileDescriptor sampleDataPoints(int timeWindowIndex, long timestamp, List<FileDescriptorBo> dataPoints, FileDescriptorBo previousDataPoint) {
Expand Down Expand Up @@ -64,6 +61,6 @@ private AgentStatPoint<Long> createPoint(long timestamp, List<Long> values) {
if (values.isEmpty()) {
return SampledFileDescriptor.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp);
}
return new AgentStatPoint<>(timestamp, values, LONG_DOWN_SAMPLER);
return AgentStatPointSummary.longSummary(timestamp, values);
}
}
Loading

0 comments on commit 8318e99

Please sign in to comment.