Skip to content

Commit

Permalink
[#8843] Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed May 16, 2022
1 parent 4969984 commit 2212bd8
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.navercorp.pinpoint.web.vo.stat.chart.application.DoubleApplicationStatPoint;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -40,13 +39,15 @@
/**
* most of the features have been delegated to AgentHistorgramList upon refactoring
* TODO: functionality reduced to creating views - need to be renamed or removed
*
* @author emeroad
*/
public class AgentTimeHistogram {

private static final Double DEFAULT_MIN_APDEX_SCORE = 2D;
private static final Double DEFAULT_MAX_APDEX_SCORE = -2D;
private static final String DEFAULT_AGENT_ID = "defaultAgentId";

private static final Comparator<AgentResponseTimeViewModel> AGENT_NAME_COMPARATOR
= Comparator.comparing(AgentResponseTimeViewModel::getAgentName);

Expand Down Expand Up @@ -102,7 +103,7 @@ public List<SampledApdexScore> getSampledAgentApdexScoreList(String agentName) {
}

List<SampledApdexScore> result = new ArrayList<>();
for(TimeHistogram timeHistogram : agentHistogram.getTimeHistogram()) {
for (TimeHistogram timeHistogram : agentHistogram.getTimeHistogram()) {
if (timeHistogram.getTotalCount() != 0) {
AgentStatPoint<Double> agentStatPoint = new AgentStatPoint<>(timeHistogram.getTimeStamp(), ApdexScore.toDoubleFromHistogram(timeHistogram));
result.add(new SampledApdexScore(agentStatPoint));
Expand All @@ -114,7 +115,7 @@ public List<SampledApdexScore> getSampledAgentApdexScoreList(String agentName) {
private AgentHistogram selectAgentHistogram(String agentName) {
for (AgentHistogram agentHistogram : agentHistogramList.getAgentHistogramList()) {
Application agentId = agentHistogram.getAgentId();
if (agentId.getName().equals(agentName)){
if (agentId.getName().equals(agentName)) {
return agentHistogram;
}
}
Expand All @@ -123,19 +124,16 @@ private AgentHistogram selectAgentHistogram(String agentName) {

public List<DoubleApplicationStatPoint> getApplicationApdexScoreList(TimeWindow window) {
int size = (int) window.getWindowRangeCount();
List<Double> min = new ArrayList<>(Arrays.asList(new Double[size]));
List<String> minAgentId = new ArrayList<>(Arrays.asList(new String[size]));
List<Double> max = new ArrayList<>(Arrays.asList(new Double[size]));
List<String> maxAgentId = new ArrayList<>(Arrays.asList(new String[size]));
Collections.fill(min, DEFAULT_MIN_APDEX_SCORE);
Collections.fill(minAgentId, DEFAULT_AGENT_ID);
Collections.fill(max, DEFAULT_MAX_APDEX_SCORE);
Collections.fill(maxAgentId, DEFAULT_AGENT_ID);
List<Double> min = newList(size, DEFAULT_MIN_APDEX_SCORE);
List<String> minAgentId = newList(size, DEFAULT_AGENT_ID);
List<Double> max = newList(size, DEFAULT_MAX_APDEX_SCORE);
List<String> maxAgentId = newList(size, DEFAULT_AGENT_ID);

List<Histogram> sumHistogram = getDefaultHistograms(window, application.getServiceType());

for (AgentHistogram agentHistogram : agentHistogramList.getAgentHistogramList()) {
for (TimeHistogram timeHistogram: agentHistogram.getTimeHistogram()){
if (timeHistogram.getTotalCount() != 0){
for (TimeHistogram timeHistogram : agentHistogram.getTimeHistogram()) {
if (timeHistogram.getTotalCount() != 0) {
int index = window.getWindowIndex(timeHistogram.getTimeStamp());
double apdex = ApdexScore.toDoubleFromHistogram(timeHistogram);
String agentId = agentHistogram.getId();
Expand All @@ -149,6 +147,12 @@ public List<DoubleApplicationStatPoint> getApplicationApdexScoreList(TimeWindow
return createDoubleApplicationStatPoints(window, min, minAgentId, max, maxAgentId, sumHistogram);
}

private <T> List<T> newList(int size, T defaultValue) {
List<T> list = new ArrayList<>(size);
Collections.fill(list, defaultValue);
return list;
}

private void updateMinMaxValue(int index, double apdex, String agentId,
List<Double> min, List<String> minAgentId, List<Double> max, List<String> maxAgentId) {
if (min.get(index) > apdex) {
Expand All @@ -166,17 +170,18 @@ private List<DoubleApplicationStatPoint> createDoubleApplicationStatPoints(TimeW
for (long timestamp : window) {
int index = window.getWindowIndex(timestamp);
Histogram histogram = sumHistrogram.get(index);
if (histogram.getTotalCount() != 0){
if (histogram.getTotalCount() != 0) {
double avg = ApdexScore.toDoubleFromHistogram(histogram);
applicationStatPoints.add(new DoubleApplicationStatPoint(timestamp, min.get(index), minAgentId.get(index), max.get(index), maxAgentId.get(index), avg));
DoubleApplicationStatPoint point = new DoubleApplicationStatPoint(timestamp, min.get(index), minAgentId.get(index), max.get(index), maxAgentId.get(index), avg);
applicationStatPoints.add(point);
}
}
return applicationStatPoints;
}

private List<Histogram> getDefaultHistograms(TimeWindow window, ServiceType serviceType) {
List<Histogram> sum = new ArrayList<>((int) window.getWindowRangeCount());
for (long timestamp : window){
for (long timestamp : window) {
sum.add(new TimeHistogram(serviceType, timestamp));
}
return sum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@
import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.vo.ResponseTime;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* @author emeroad
*/
public class AgentTimeHistogramBuilder {

private final Logger logger = LogManager.getLogger(this.getClass());

private final Application application;
private final Range range;
private final TimeWindow window;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Objects;

/**
* https://en.wikipedia.org/wiki/Apdex
* <a href="https://en.wikipedia.org/wiki/Apdex">https://en.wikipedia.org/wiki/Apdex</a>
*/
public class ApdexScore {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,4 @@ public int hashCode() {
return result;
}

public Tag copy() {
return new Tag(this.name, this.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Service
public class ApdexScoreServiceImpl implements ApdexScoreService {
Expand All @@ -31,7 +32,7 @@ public class ApdexScoreServiceImpl implements ApdexScoreService {
private final MapResponseDao mapResponseDao;

public ApdexScoreServiceImpl(MapResponseDao mapResponseDao) {
this.mapResponseDao = mapResponseDao;
this.mapResponseDao = Objects.requireNonNull(mapResponseDao, "mapResponseDao");
}

private AgentTimeHistogram createAgentTimeHistogram(Application application, Range range, TimeWindow timeWindow, List<ResponseTime> responseHistogramList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.Objects;

public class SampledApdexScore implements SampledAgentStatDataPoint{
public class SampledApdexScore implements SampledAgentStatDataPoint {

public static final Double UNCOLLECTED_SCORE = -1D;
public static final Point.UncollectedPointCreator<AgentStatPoint<Double>> UNCOLLECTED_POINT_CREATOR = UncollectedPointCreatorFactory.createDoublePointCreator(UNCOLLECTED_SCORE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public InspectorValueGroupBuilder(Point.UncollectedPointCreator<P> uncollectedPo
this.uncollectedPointCreator = Objects.requireNonNull(uncollectedPointCreator, "uncollectedPointCreator");
}

public InspectorValueGroup build(TimeWindow timeWindow, String groupName, List<P> sampledPoints){
public InspectorValueGroup build(TimeWindow timeWindow, String groupName, List<P> sampledPoints) {
List<P> points = createInitialPoints(timeWindow);
for (P sampledPoint : sampledPoints) {
int timeslotIndex = timeWindow.getWindowIndex(sampledPoint.getXVal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import java.util.List;

public class AgentApdexScoreChart extends DefaultAgentChart<SampledApdexScore, Double>{
public class AgentApdexScoreChart extends DefaultAgentChart<SampledApdexScore, Double> {

public enum ApdexScoreChartType implements StatChartGroup.AgentChartType{
public enum ApdexScoreChartType implements StatChartGroup.AgentChartType {
APDEX_SCORE
}

Expand All @@ -25,7 +25,7 @@ static ChartGroupBuilder<SampledApdexScore, AgentStatPoint<Double>> newChartBuil
return builder;
}

static InspectorDataBuilder<SampledApdexScore, AgentStatPoint<Double>> newViewBuilder(){
static InspectorDataBuilder<SampledApdexScore, AgentStatPoint<Double>> newViewBuilder() {
InspectorDataBuilder<SampledApdexScore, AgentStatPoint<Double>> builder = new InspectorDataBuilder<>(SampledApdexScore.UNCOLLECTED_POINT_CREATOR, "agentApdexScore", "noUnit");
builder.addValueFunction("min", AgentStatPoint::getMinYVal);
builder.addValueFunction("max", AgentStatPoint::getMaxYVal);
Expand All @@ -40,7 +40,7 @@ public AgentApdexScoreChart(TimeWindow timeWindow, List<SampledApdexScore> statL
super(timeWindow, statList, BUILDER);
}

public InspectorData getInspectorData(TimeWindow timeWindow, List<SampledApdexScore> statList){
public InspectorData getInspectorData(TimeWindow timeWindow, List<SampledApdexScore> statList) {
return INSPECTOR_VIEW_DATA_BUILDER.build(timeWindow, statList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.web.util.TimeWindow;
import com.navercorp.pinpoint.web.util.TimeWindowSlotCentricSampler;
import com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel;
import com.navercorp.pinpoint.web.vo.Application;
import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.vo.ResponseTime;

import com.navercorp.pinpoint.web.vo.stat.SampledApdexScore;
import com.navercorp.pinpoint.web.vo.stat.chart.application.DoubleApplicationStatPoint;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Assert;
import org.junit.Test;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import java.io.IOException;
import java.io.StringWriter;
Expand All @@ -52,7 +51,7 @@ public class AgentTimeHistogramTest {
public void testViewModel() throws IOException {

Application app = new Application("test", ServiceType.STAND_ALONE);
AgentTimeHistogramBuilder builder = new AgentTimeHistogramBuilder(app, Range.between(0, 1000*60));
AgentTimeHistogramBuilder builder = new AgentTimeHistogramBuilder(app, Range.between(0, 1000 * 60));
List<ResponseTime> responseHistogramList = createResponseTime(app, "test1", "test2");
AgentTimeHistogram histogram = builder.build(responseHistogramList);

Expand All @@ -76,7 +75,7 @@ public void testViewModel() throws IOException {
@Test
public void getSampledAgentApdexScoreListTest() {
Application app = new Application("test", ServiceType.STAND_ALONE);
Range range = Range.between(0, 1000*60);
Range range = Range.between(0, 1000 * 60);
TimeWindow timeWindow = new TimeWindow(range, new TimeWindowSlotCentricSampler());
AgentTimeHistogramBuilder builder = new AgentTimeHistogramBuilder(app, range, timeWindow);
List<ResponseTime> responseHistogramList = createResponseTime(app, "test3", "test4");
Expand All @@ -95,7 +94,7 @@ public void getSampledAgentApdexScoreListTest() {
@Test
public void getApplicationApdexScoreListTest() {
Application app = new Application("test", ServiceType.STAND_ALONE);
Range range = Range.between(0, 1000*60);
Range range = Range.between(0, 1000 * 60);
TimeWindow timeWindow = new TimeWindow(range, new TimeWindowSlotCentricSampler());
AgentTimeHistogramBuilder builder = new AgentTimeHistogramBuilder(app, range, timeWindow);
List<ResponseTime> responseHistogramList = createResponseTime(app, "test5", "test6");
Expand All @@ -105,7 +104,7 @@ public void getApplicationApdexScoreListTest() {
Assert.assertEquals(applicationStatPointList.size(), 2);
Assert.assertEquals(applicationStatPointList.get(0).getXVal(), 0);
Assert.assertEquals(applicationStatPointList.get(0).getYValForAvg(), 1.0, 0.001);
Assert.assertEquals(applicationStatPointList.get(1).getXVal(), 1000*60);
Assert.assertEquals(applicationStatPointList.get(1).getXVal(), 1000 * 60);
Assert.assertEquals(applicationStatPointList.get(1).getYValForAvg(), 0.5, 0.001);
}

Expand All @@ -116,15 +115,15 @@ private List<ResponseTime> createResponseTime(Application app, String agentName1
one.addResponseTime(agentName1, (short) 1000, 1);
responseTimeList.add(one);

ResponseTime two = new ResponseTime(app.getName(), app.getServiceType(), 1000*60);
ResponseTime two = new ResponseTime(app.getName(), app.getServiceType(), 1000 * 60);
two.addResponseTime(agentName1, (short) 3000, 1);
responseTimeList.add(two);

ResponseTime three = new ResponseTime(app.getName(), app.getServiceType(), 0);
three.addResponseTime(agentName2, (short) 1000, 1);
responseTimeList.add(three);

ResponseTime four = new ResponseTime(app.getName(), app.getServiceType(), 1000*60);
ResponseTime four = new ResponseTime(app.getName(), app.getServiceType(), 1000 * 60);
four.addResponseTime(agentName2, (short) 3000, 1);
responseTimeList.add(four);
return responseTimeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class InspectorViewTest {

private enum TestChartType implements StatChartGroup.AgentChartType{
private enum TestChartType implements StatChartGroup.AgentChartType {
TEST_CHART_TYPE
}

Expand All @@ -41,19 +41,19 @@ public AgentStatPoint<Integer> getAgentStatPoint() {
}

@Test
public void inspectorViewTest(){
public void inspectorViewTest() {
String title = "testTitle";
String unit = "testUnit";
Map<String, Function<AgentStatPoint<Integer>, ?>> valueFunctionMap = new HashMap<>();
valueFunctionMap.put("function1", AgentStatPoint::getMinYVal);
valueFunctionMap.put("function2", AgentStatPoint::getMinYVal);
valueFunctionMap.put("function3", AgentStatPoint::getMinYVal);
Range range = Range.between(0, 1000*60);
Range range = Range.between(0, 1000 * 60);
TimeWindow timeWindow = new TimeWindow(range, new TimeWindowSlotCentricSampler());
List<TestAgentStatDataPoint> testAgentStatDataPoints = createTestAgentStatDataPoint();

InspectorDataBuilder<TestAgentStatDataPoint, AgentStatPoint<Integer>> inspectorDataBuilder = new InspectorDataBuilder<>(TestAgentStatDataPoint.UNCOLLECTED_POINT_CREATOR, title, unit);
for (Map.Entry<String, Function<AgentStatPoint<Integer>, ?>> e : valueFunctionMap.entrySet()){
for (Map.Entry<String, Function<AgentStatPoint<Integer>, ?>> e : valueFunctionMap.entrySet()) {
inspectorDataBuilder.addValueFunction(e.getKey(), e.getValue());
}
inspectorDataBuilder.addPointFunction(TestChartType.TEST_CHART_TYPE, TestAgentStatDataPoint::getAgentStatPoint);
Expand Down

0 comments on commit 2212bd8

Please sign in to comment.