Skip to content

Commit

Permalink
[#noissue] Refactor Chart
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Nov 13, 2017
1 parent 50ee197 commit 97a763b
Show file tree
Hide file tree
Showing 20 changed files with 358 additions and 314 deletions.
Expand Up @@ -20,7 +20,9 @@
import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceHistogram;
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;
Expand All @@ -45,28 +47,30 @@ public SampledActiveTrace sampleDataPoints(int timeWindowIndex, long timestamp,

final HistogramSchema schema = BaseHistogramSchema.getDefaultHistogramSchemaByTypeCode(dataPoints.get(0).getHistogramSchemaType());
if (schema == null) {
SampledActiveTrace sampledActiveTrace = new SampledActiveTrace();
sampledActiveTrace.setFastCounts(SampledActiveTrace.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp));
sampledActiveTrace.setNormalCounts(SampledActiveTrace.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp));
sampledActiveTrace.setSlowCounts(SampledActiveTrace.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp));
sampledActiveTrace.setVerySlowCounts(SampledActiveTrace.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp));
return sampledActiveTrace;
return newUnSampledActiveTrace(timestamp);
}

SampledActiveTrace sampledActiveTrace = new SampledActiveTrace();
List<Integer> fastCounts = filterActiveTraceBoList(dataPoints, ActiveTraceHistogram::getFastCount);
sampledActiveTrace.setFastCounts(createSampledTitledPoint(schema.getFastSlot().getSlotName(), timestamp, fastCounts));
AgentStatPoint<Integer> fast = newAgentStatPoint(schema.getFastSlot(), timestamp, dataPoints, ActiveTraceHistogram::getFastCount);
AgentStatPoint<Integer> normal = newAgentStatPoint(schema.getNormalSlot(), timestamp, dataPoints, ActiveTraceHistogram::getNormalCount);
AgentStatPoint<Integer> slow = newAgentStatPoint(schema.getSlowSlot(), timestamp, dataPoints, ActiveTraceHistogram::getSlowCount);
AgentStatPoint<Integer> verySlow = newAgentStatPoint(schema.getVerySlowSlot(), timestamp, dataPoints, ActiveTraceHistogram::getVerySlowCount);
SampledActiveTrace sampledActiveTrace = new SampledActiveTrace(fast, normal, slow, verySlow);

List<Integer> normalCounts = filterActiveTraceBoList(dataPoints, ActiveTraceHistogram::getNormalCount);
sampledActiveTrace.setNormalCounts(createSampledTitledPoint(schema.getNormalSlot().getSlotName(), timestamp, normalCounts));

List<Integer> slowCounts = filterActiveTraceBoList(dataPoints, ActiveTraceHistogram::getSlowCount);
sampledActiveTrace.setSlowCounts(createSampledTitledPoint(schema.getSlowSlot().getSlotName(), timestamp, slowCounts));
return sampledActiveTrace;
}

List<Integer> verySlowCounts = filterActiveTraceBoList(dataPoints, ActiveTraceHistogram::getVerySlowCount);
sampledActiveTrace.setVerySlowCounts(createSampledTitledPoint(schema.getVerySlowSlot().getSlotName(), timestamp, verySlowCounts));
private SampledActiveTrace newUnSampledActiveTrace(long timestamp) {
Point.UncollectedPointCreator<AgentStatPoint<Integer>> uncollected = SampledActiveTrace.UNCOLLECTED_POINT_CREATOR;
AgentStatPoint<Integer> fast = uncollected.createUnCollectedPoint(timestamp);
AgentStatPoint<Integer> normal = uncollected.createUnCollectedPoint(timestamp);
AgentStatPoint<Integer> slow = uncollected.createUnCollectedPoint(timestamp);
AgentStatPoint<Integer> verySlow = uncollected.createUnCollectedPoint(timestamp);
return new SampledActiveTrace(fast, normal, slow, verySlow);
}

return sampledActiveTrace;
private AgentStatPoint<Integer> newAgentStatPoint(HistogramSlot slot, long timestamp, List<ActiveTraceBo> dataPoints, ToIntFunction<ActiveTraceHistogram> counter) {
List<Integer> fastCounts = filterActiveTraceBoList(dataPoints, counter);
return createSampledTitledPoint(slot.getSlotName(), timestamp, fastCounts);
}

private List<Integer> filterActiveTraceBoList(List<ActiveTraceBo> dataPoints, ToIntFunction<ActiveTraceHistogram> counter) {
Expand Down
Expand Up @@ -25,6 +25,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.ToDoubleFunction;

/**
* @author HyunGil Jeong
Expand All @@ -37,32 +38,40 @@ public class CpuLoadSampler implements AgentStatSampler<CpuLoadBo, SampledCpuLoa

@Override
public SampledCpuLoad sampleDataPoints(int timeWindowIndex, long timestamp, List<CpuLoadBo> dataPoints, CpuLoadBo previousDataPoint) {
List<Double> jvmCpuLoads = new ArrayList<>(dataPoints.size());
List<Double> systemCpuLoads = new ArrayList<>(dataPoints.size());
final AgentStatPoint<Double> jvmCpuLoad = newAgentStatPoint(timestamp, dataPoints, CpuLoadBo::getJvmCpuLoad);
final AgentStatPoint<Double> systemCpuLoad = newAgentStatPoint(timestamp, dataPoints, CpuLoadBo::getSystemCpuLoad);

SampledCpuLoad sampledCpuLoad = new SampledCpuLoad(jvmCpuLoad, systemCpuLoad);
return sampledCpuLoad;
}

private AgentStatPoint<Double> newAgentStatPoint(long timestamp, List<CpuLoadBo> dataPoints, ToDoubleFunction<CpuLoadBo> filter) {
List<Double> jvmCpuLoads = filter(dataPoints, filter);
return createPoint(timestamp, jvmCpuLoads);
}

private List<Double> filter(List<CpuLoadBo> dataPoints, ToDoubleFunction<CpuLoadBo> filter) {
final List<Double> result = new ArrayList<>(dataPoints.size());
for (CpuLoadBo cpuLoadBo : dataPoints) {
if (cpuLoadBo.getJvmCpuLoad() != CpuLoadBo.UNCOLLECTED_VALUE) {
jvmCpuLoads.add(cpuLoadBo.getJvmCpuLoad() * 100);
}
if (cpuLoadBo.getSystemCpuLoad() != CpuLoadBo.UNCOLLECTED_VALUE) {
systemCpuLoads.add(cpuLoadBo.getSystemCpuLoad() * 100);
final double apply = filter.applyAsDouble(cpuLoadBo);
if (apply != CpuLoadBo.UNCOLLECTED_VALUE) {
result.add(apply * 100);
}
}
SampledCpuLoad sampledCpuLoad = new SampledCpuLoad();
sampledCpuLoad.setJvmCpuLoad(createPoint(timestamp, jvmCpuLoads));
sampledCpuLoad.setSystemCpuLoad(createPoint(timestamp, systemCpuLoads));
return sampledCpuLoad;
return result;
}

private AgentStatPoint<Double> createPoint(long timestamp, List<Double> values) {
if (values.isEmpty()) {
return SampledCpuLoad.UNCOLLECTED_POINT_CREATOR.createUnCollectedPoint(timestamp);
} else {
return new AgentStatPoint<>(
timestamp,
DOUBLE_DOWN_SAMPLER.sampleMin(values),
DOUBLE_DOWN_SAMPLER.sampleMax(values),
DOUBLE_DOWN_SAMPLER.sampleAvg(values),
DOUBLE_DOWN_SAMPLER.sampleSum(values));
}

return new AgentStatPoint<>(
timestamp,
DOUBLE_DOWN_SAMPLER.sampleMin(values),
DOUBLE_DOWN_SAMPLER.sampleMax(values),
DOUBLE_DOWN_SAMPLER.sampleAvg(values),
DOUBLE_DOWN_SAMPLER.sampleSum(values));

}
}
Expand Up @@ -36,29 +36,34 @@ public class DeadlockSampler implements AgentStatSampler<DeadlockBo, SampledDead

@Override
public SampledDeadlock sampleDataPoints(int index, long timestamp, List<DeadlockBo> deadlockBoList, DeadlockBo previousDataPoint) {
List<Integer> deadlockedThreadCountList = filter(deadlockBoList);

AgentStatPoint<Integer> point = createPoint(timestamp, deadlockedThreadCountList);
SampledDeadlock sampledDeadlock = new SampledDeadlock(point);

return sampledDeadlock;
}

public List<Integer> filter(List<DeadlockBo> deadlockBoList) {
List<Integer> deadlockedThreadCountList = new ArrayList<>(deadlockBoList.size());

for (DeadlockBo deadlockBo : deadlockBoList) {
deadlockedThreadCountList.add(deadlockBo.getDeadlockedThreadCount());
}

SampledDeadlock sampledDeadlock = new SampledDeadlock();
sampledDeadlock.setDeadlockedThreadCount(createPoint(timestamp, deadlockedThreadCountList));

return sampledDeadlock;
return deadlockedThreadCountList;
}

private AgentStatPoint<Integer> createPoint(long timestamp, List<Integer> values) {
if (values.isEmpty()) {
return SampledDeadlock.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),
INTEGER_DOWN_SAMPLER.sampleSum(values));
}

return new AgentStatPoint<>(
timestamp,
INTEGER_DOWN_SAMPLER.sampleMin(values),
INTEGER_DOWN_SAMPLER.sampleMax(values),
INTEGER_DOWN_SAMPLER.sampleAvg(values),
INTEGER_DOWN_SAMPLER.sampleSum(values));
}

}
Expand Up @@ -17,6 +17,7 @@

import com.navercorp.pinpoint.common.server.bo.stat.join.JoinActiveTraceBo;
import com.navercorp.pinpoint.web.vo.stat.AggreJoinActiveTraceBo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -29,7 +30,7 @@ public class JoinActiveTraceSampler implements ApplicationStatSampler<JoinActive

@Override
public AggreJoinActiveTraceBo sampleDataPoints(int index, long timestamp, List<JoinActiveTraceBo> joinActiveTraceBoList, JoinActiveTraceBo previousDataPoint) {
if (joinActiveTraceBoList.size() == 0) {
if (CollectionUtils.isEmpty(joinActiveTraceBoList)) {
return AggreJoinActiveTraceBo.createUncollectedObject(timestamp);
}

Expand Down
Expand Up @@ -17,6 +17,7 @@

import com.navercorp.pinpoint.common.server.bo.stat.join.JoinCpuLoadBo;
import com.navercorp.pinpoint.web.vo.stat.AggreJoinCpuLoadBo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
Expand All @@ -31,7 +32,7 @@ public class JoinCpuLoadSampler implements ApplicationStatSampler<JoinCpuLoadBo>

@Override
public AggreJoinCpuLoadBo sampleDataPoints(int timeWindowIndex, long timestamp, List<JoinCpuLoadBo> joinCpuLoadBoList, JoinCpuLoadBo previousDataPoint) {
if (joinCpuLoadBoList.size() == 0) {
if (CollectionUtils.isEmpty(joinCpuLoadBoList)) {
return AggreJoinCpuLoadBo.createUncollectedObject(timestamp);
}

Expand Down
Expand Up @@ -15,12 +15,11 @@
*/
package com.navercorp.pinpoint.web.mapper.stat.sampling.sampler;

import com.navercorp.pinpoint.common.server.bo.stat.join.JoinCpuLoadBo;
import com.navercorp.pinpoint.common.server.bo.stat.join.JoinDataSourceBo;
import com.navercorp.pinpoint.common.server.bo.stat.join.JoinDataSourceListBo;
import com.navercorp.pinpoint.web.vo.stat.AggreJoinDataSourceBo;
import com.navercorp.pinpoint.web.vo.stat.AggreJoinDataSourceListBo;
import com.navercorp.pinpoint.web.vo.stat.AggregationStatData;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
Expand All @@ -34,20 +33,26 @@ public class JoinDataSourceSampler implements ApplicationStatSampler<JoinDataSou

@Override
public AggreJoinDataSourceListBo sampleDataPoints(int index, long timestamp, List<JoinDataSourceListBo> joinDataSourceListBoList, JoinDataSourceListBo previousJoinDataSourceListBo) {
if (joinDataSourceListBoList.size() == 0) {
if (CollectionUtils.isEmpty(joinDataSourceListBoList)) {
return AggreJoinDataSourceListBo.createUncollectedObject(timestamp);
}

JoinDataSourceListBo joinDataSourceListBo = JoinDataSourceListBo.joinDataSourceListBoList(joinDataSourceListBoList, timestamp);
String id = joinDataSourceListBo.getId();
List<JoinDataSourceBo> joinDataSourceBoList = joinDataSourceListBo.getJoinDataSourceBoList();
List<JoinDataSourceBo> aggreJoinDataSourceBoList = new ArrayList<>(joinDataSourceBoList.size());

for (JoinDataSourceBo joinDataSourceBo : joinDataSourceBoList) {
aggreJoinDataSourceBoList.add(new AggreJoinDataSourceBo(joinDataSourceBo.getServiceTypeCode(), joinDataSourceBo.getUrl(), joinDataSourceBo.getAvgActiveConnectionSize(), joinDataSourceBo.getMinActiveConnectionSize(), joinDataSourceBo.getMinActiveConnectionAgentId(), joinDataSourceBo.getMaxActiveConnectionSize(), joinDataSourceBo.getMaxActiveConnectionAgentId(), timestamp));
}
List<JoinDataSourceBo> aggreJoinDataSourceBoList = getJoinDataSourceBoList(timestamp, joinDataSourceBoList);

AggreJoinDataSourceListBo aggreJoinDataSourceListBo = new AggreJoinDataSourceListBo(id, aggreJoinDataSourceBoList, timestamp);
return aggreJoinDataSourceListBo;
}

public List<JoinDataSourceBo> getJoinDataSourceBoList(long timestamp, List<JoinDataSourceBo> joinDataSourceBoList) {
List<JoinDataSourceBo> aggreJoinDataSourceBoList = new ArrayList<>(joinDataSourceBoList.size());
for (JoinDataSourceBo ds : joinDataSourceBoList) {
AggreJoinDataSourceBo dataSourceBo = new AggreJoinDataSourceBo(ds.getServiceTypeCode(), ds.getUrl(), ds.getAvgActiveConnectionSize(),
ds.getMinActiveConnectionSize(), ds.getMinActiveConnectionAgentId(), ds.getMaxActiveConnectionSize(), ds.getMaxActiveConnectionAgentId(), timestamp);
aggreJoinDataSourceBoList.add(dataSourceBo);
}
return aggreJoinDataSourceBoList;
}
}
Expand Up @@ -17,6 +17,7 @@

import com.navercorp.pinpoint.common.server.bo.stat.join.JoinMemoryBo;
import com.navercorp.pinpoint.web.vo.stat.AggreJoinMemoryBo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -29,7 +30,7 @@ public class JoinMemorySampler implements ApplicationStatSampler<JoinMemoryBo> {

@Override
public AggreJoinMemoryBo sampleDataPoints(int index, long timestamp, List<JoinMemoryBo> joinMemoryBoList, JoinMemoryBo previousDataPoint) {
if (joinMemoryBoList.size() == 0) {
if (CollectionUtils.isEmpty(joinMemoryBoList)) {
return AggreJoinMemoryBo.createUncollectedObject(timestamp);
}

Expand Down
Expand Up @@ -17,6 +17,7 @@

import com.navercorp.pinpoint.common.server.bo.stat.join.JoinResponseTimeBo;
import com.navercorp.pinpoint.web.vo.stat.AggreJoinResponseTimeBo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -29,7 +30,7 @@ public class JoinResponseTimeSampler implements ApplicationStatSampler<JoinRespo

@Override
public AggreJoinResponseTimeBo sampleDataPoints(int index, long timestamp, List<JoinResponseTimeBo> joinResponseTimeBoList, JoinResponseTimeBo previousDataPoint) {
if (joinResponseTimeBoList.size() == 0) {
if (CollectionUtils.isEmpty(joinResponseTimeBoList)) {
return AggreJoinResponseTimeBo.createUncollectedObject(timestamp);
}

Expand Down
Expand Up @@ -17,6 +17,7 @@

import com.navercorp.pinpoint.common.server.bo.stat.join.JoinTransactionBo;
import com.navercorp.pinpoint.web.vo.stat.AggreJoinTransactionBo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -29,7 +30,7 @@ public class JoinTransactionSampler implements ApplicationStatSampler<JoinTransa

@Override
public AggreJoinTransactionBo sampleDataPoints(int index, long timestamp, List<JoinTransactionBo> joinTransactionBoList, JoinTransactionBo previousDataPoint) {
if (joinTransactionBoList.size() == 0) {
if (CollectionUtils.isEmpty(joinTransactionBoList)) {
return AggreJoinTransactionBo.createUncollectedObject(timestamp);
}

Expand Down

0 comments on commit 97a763b

Please sign in to comment.