Skip to content

Commit

Permalink
[#11021] Apply JsonFields
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed May 17, 2024
1 parent 86f4ef7 commit 5ca7a22
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package com.navercorp.pinpoint.web.applicationmap.histogram;

import com.navercorp.pinpoint.common.server.util.json.JsonField;
import com.navercorp.pinpoint.common.server.util.json.JsonFields;
import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogram;
import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogramList;
import com.navercorp.pinpoint.common.server.util.timewindow.TimeWindow;
import com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel;
import com.navercorp.pinpoint.web.view.TimeViewModel;
import com.navercorp.pinpoint.web.view.id.AgentNameView;
import com.navercorp.pinpoint.web.vo.Application;
import com.navercorp.pinpoint.web.vo.stat.SampledApdexScore;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint;
Expand All @@ -48,8 +50,8 @@ public class AgentTimeHistogram {
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);
private static final Comparator<JsonField<AgentNameView, List<TimeViewModel>>> AGENT_NAME_COMPARATOR
= Comparator.comparing((jsonField) -> jsonField.name().agentName());

private final Application application;
private final AgentHistogramList agentHistogramList;
Expand All @@ -64,15 +66,16 @@ public AgentTimeHistogram(Application application, AgentHistogramList agentHisto
this.agentHistogramList = Objects.requireNonNull(agentHistogramList, "agentHistogramList");
}

public JsonFields<AgentNameView, List<TimeViewModel>> createViewModel(TimeHistogramFormat timeHistogramFormat) {

public List<AgentResponseTimeViewModel> createViewModel(TimeHistogramFormat timeHistogramFormat) {
final List<AgentResponseTimeViewModel> result = new ArrayList<>();
JsonFields.Builder<AgentNameView, List<TimeViewModel>> builder = JsonFields.newBuilder();
for (AgentHistogram agentHistogram : agentHistogramList.getAgentHistogramList()) {
Application agentId = agentHistogram.getAgentId();
List<TimeHistogram> timeList = sortTimeHistogram(agentHistogram.getTimeHistogram());
AgentResponseTimeViewModel model = createAgentResponseTimeViewModel(agentId, timeList, timeHistogramFormat);
result.add(model);
JsonField<AgentNameView, List<TimeViewModel>> model = createAgentResponseTimeViewModel(agentId, timeList, timeHistogramFormat);
builder.addField(model);
}
JsonFields<AgentNameView, List<TimeViewModel>> result = builder.build();
result.sort(AGENT_NAME_COMPARATOR);
return result;
}
Expand All @@ -91,13 +94,15 @@ private List<TimeHistogram> sortTimeHistogram(Collection<TimeHistogram> timeMap)
return timeList;
}

private AgentResponseTimeViewModel createAgentResponseTimeViewModel(Application agentName, List<TimeHistogram> timeHistogramList, TimeHistogramFormat timeHistogramFormat) {
private JsonField<AgentNameView, List<TimeViewModel>> createAgentResponseTimeViewModel(Application agentName, List<TimeHistogram> timeHistogramList, TimeHistogramFormat timeHistogramFormat) {
List<TimeViewModel> responseTimeViewModel = createResponseTimeViewModel(timeHistogramList, timeHistogramFormat);
return new AgentResponseTimeViewModel(agentName, responseTimeViewModel);
return JsonField.of(AgentNameView.of(agentName), responseTimeViewModel);
}

private List<TimeViewModel> createResponseTimeViewModel(List<TimeHistogram> timeHistogramList, TimeHistogramFormat timeHistogramFormat) {
return new TimeViewModel.TimeViewModelBuilder(application, timeHistogramList).setTimeHistogramFormat(timeHistogramFormat).build();
TimeViewModel.TimeViewModelBuilder builder = new TimeViewModel.TimeViewModelBuilder(application, timeHistogramList);
return builder.setTimeHistogramFormat(timeHistogramFormat)
.build();
}

public List<SampledApdexScore> getSampledAgentApdexScoreList(String agentName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package com.navercorp.pinpoint.web.applicationmap.histogram;

import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.view.AgentResponseTimeViewModelList;
import com.navercorp.pinpoint.web.view.TimeViewModel;
import com.navercorp.pinpoint.web.view.histogram.HistogramView;
import com.navercorp.pinpoint.web.vo.Application;
import com.navercorp.pinpoint.web.vo.ResponseTime;
Expand Down Expand Up @@ -118,12 +116,9 @@ public Map<String, ResponseTimeStatics> getAgentResponseStatisticsMap() {
return map;
}

public List<TimeViewModel> getApplicationTimeHistogram(TimeHistogramFormat timeHistogramFormat) {
return applicationTimeHistogram.createViewModel(timeHistogramFormat);
}

public AgentResponseTimeViewModelList getAgentTimeHistogram(TimeHistogramFormat timeHistogramFormat) {
return new AgentResponseTimeViewModelList(agentTimeHistogram.createViewModel(timeHistogramFormat));
public AgentTimeHistogram getAgentTimeHistogram() {
return agentTimeHistogram;
}

public List<HistogramView> createAgentHistogramViewList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.navercorp.pinpoint.common.server.util.json.JsonFields;
import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.web.applicationmap.histogram.AgentTimeHistogram;
Expand All @@ -30,9 +31,9 @@
import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogramList;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkCallData;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkCallDataMap;
import com.navercorp.pinpoint.web.view.AgentResponseTimeViewModelList;
import com.navercorp.pinpoint.web.view.LinkSerializer;
import com.navercorp.pinpoint.web.view.TimeViewModel;
import com.navercorp.pinpoint.web.view.id.AgentNameView;
import com.navercorp.pinpoint.web.vo.Application;

import java.util.Collection;
Expand Down Expand Up @@ -213,11 +214,12 @@ public void addOutLink(LinkCallDataMap outLinkCallDataMap) {
this.outLink.addLinkDataMap(outLinkCallDataMap);
}

public AgentResponseTimeViewModelList getSourceAgentTimeSeriesHistogram() {
public JsonFields<AgentNameView, List<TimeViewModel>> getSourceAgentTimeSeriesHistogram() {
// we need Target (to)'s time since time in link is RPC-based
AgentTimeHistogramBuilder builder = new AgentTimeHistogramBuilder(toNode.getApplication(), range);
AgentTimeHistogram applicationTimeSeriesHistogram = builder.buildSource(inLink);
return new AgentResponseTimeViewModelList(applicationTimeSeriesHistogram.createViewModel(timeHistogramFormat));

return applicationTimeSeriesHistogram.createViewModel(timeHistogramFormat);
}

public AgentTimeHistogram getTargetAgentTimeHistogram() {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogramFormat;
import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogram;
import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogramList;
import com.navercorp.pinpoint.web.view.id.AgentNameView;
import com.navercorp.pinpoint.web.vo.Application;

import java.util.List;
Expand Down Expand Up @@ -48,10 +49,10 @@ public ApplicationTimeHistogramViewModel(TimeHistogramFormat format, Application
/**
* @return JsonFields(String:AgentId, Histogram)
*/
public JsonFields<String, Histogram> getSummary() {
JsonFields.Builder<String, Histogram> builder = JsonFields.newBuilder();
public JsonFields<AgentNameView, Histogram> getSummary() {
JsonFields.Builder<AgentNameView, Histogram> builder = JsonFields.newBuilder();

Check warning on line 53 in web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationTimeHistogramViewModel.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationTimeHistogramViewModel.java#L53

Added line #L53 was not covered by tests
for (AgentHistogram agentHistogram : agentHistogramList.getAgentHistogramList()) {
String agentName = agentHistogram.getAgentId().getName();
AgentNameView agentName = AgentNameView.of(agentHistogram.getAgentId());

Check warning on line 55 in web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationTimeHistogramViewModel.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationTimeHistogramViewModel.java#L55

Added line #L55 was not covered by tests
Histogram histogram = agentHistogram.getHistogram();
builder.addField(agentName, histogram);
}
Expand All @@ -61,19 +62,7 @@ public JsonFields<String, Histogram> getSummary() {
/**
* @return JsonFields(String:AgentId, value:List<TimeViewModel>)
*/
public JsonFields<String, List<TimeViewModel>> getTimeSeries() {
List<AgentResponseTimeViewModel> timeSeriesViewModel = getTimeSeriesViewModel();

JsonFields.Builder<String, List<TimeViewModel>> builder = JsonFields.newBuilder();
for (AgentResponseTimeViewModel model : timeSeriesViewModel) {
String agentName = model.getAgentName();
List<TimeViewModel> responseTimeViewModel = model.getResponseTimeViewModel();
builder.addField(agentName, responseTimeViewModel);
}
return builder.build();
}

private List<AgentResponseTimeViewModel> getTimeSeriesViewModel() {
public JsonFields<AgentNameView, List<TimeViewModel>> getTimeSeries() {
AgentTimeHistogram histogram = new AgentTimeHistogram(application, agentHistogramList);
return histogram.createViewModel(format);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.navercorp.pinpoint.common.server.util.json.JsonFields;
import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram;
import com.navercorp.pinpoint.web.applicationmap.link.Link;
import com.navercorp.pinpoint.web.applicationmap.link.LinkViews;
import com.navercorp.pinpoint.web.applicationmap.nodes.Node;
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerGroupList;
import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogram;
import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogramList;
import com.navercorp.pinpoint.web.view.id.AgentNameView;
import com.navercorp.pinpoint.web.vo.Application;
import com.navercorp.pinpoint.web.vo.ResponseTimeStatics;

Expand Down Expand Up @@ -172,8 +174,9 @@ private void writeAgentHistogram(String fieldName, AgentHistogramList agentHisto
}

private void writeSourceAgentTimeSeriesHistogram(Link link, JsonGenerator jgen) throws IOException {
AgentResponseTimeViewModelList sourceAgentTimeSeriesHistogram = link.getSourceAgentTimeSeriesHistogram();
sourceAgentTimeSeriesHistogram.setFieldName("sourceTimeSeriesHistogram");
JsonFields<AgentNameView, List<TimeViewModel>> sourceAgentTimeSeriesHistogram = link.getSourceAgentTimeSeriesHistogram();
// sourceAgentTimeSeriesHistogram.setFieldName("sourceTimeSeriesHistogram");
jgen.writeFieldName("sourceTimeSeriesHistogram");
jgen.writeObject(sourceAgentTimeSeriesHistogram);
}

Expand Down
Loading

0 comments on commit 5ca7a22

Please sign in to comment.