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 47ba6e9 commit 23dac92
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package com.navercorp.pinpoint.web.applicationmap.histogram;

import com.google.common.collect.Ordering;
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.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 static final Ordering<TimeHistogram> histogramOrdering = Ordering.from(TimeHistogram.TIME_STAMP_ASC_COMPARATOR);

Expand All @@ -66,17 +68,17 @@ 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();
builder.comparator(AGENT_NAME_COMPARATOR);
for (AgentHistogram agentHistogram : agentHistogramList.getAgentHistogramList()) {
Application agentId = agentHistogram.getAgentId();
List<TimeHistogram> timeList = histogramOrdering.sortedCopy(agentHistogram.getTimeHistogram());
AgentResponseTimeViewModel model = createAgentResponseTimeViewModel(agentId, timeList, timeHistogramFormat);
result.add(model);
JsonField<AgentNameView, List<TimeViewModel>> model = createAgentResponseTimeViewModel(agentId, timeList, timeHistogramFormat);
builder.addField(model);
}
result.sort(AGENT_NAME_COMPARATOR);
return result;
return builder.build();
}

public Map<String, List<TimeHistogram>> getTimeHistogramMap() {
Expand All @@ -89,9 +91,9 @@ public Map<String, List<TimeHistogram>> getTimeHistogramMap() {
}


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) {
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();
for (AgentHistogram agentHistogram : agentHistogramList.getAgentHistogramList()) {
String agentName = agentHistogram.getAgentId().getName();
AgentNameView agentName = AgentNameView.of(agentHistogram.getAgentId());
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 23dac92

Please sign in to comment.