Skip to content

Commit

Permalink
[pinpoint-apm#11050] Refactor NodeHistogram
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jun 7, 2024
1 parent a314e90 commit 5ddd983
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.navercorp.pinpoint.web.applicationmap.service.MapServiceOption;
import com.navercorp.pinpoint.web.applicationmap.service.ResponseTimeHistogramService;
import com.navercorp.pinpoint.web.applicationmap.service.ResponseTimeHistogramServiceOption;
import com.navercorp.pinpoint.web.applicationmap.view.NodeHistogramSummaryView;
import com.navercorp.pinpoint.web.component.ApplicationFactory;
import com.navercorp.pinpoint.web.validation.NullOrNotBlank;
import com.navercorp.pinpoint.web.view.ApplicationTimeHistogramViewModel;
Expand Down Expand Up @@ -215,7 +216,7 @@ public ApplicationTimeHistogramViewModel getResponseTimeHistogramData(
}

@PostMapping(value = "/getResponseTimeHistogramDataV2")
public NodeHistogramSummary postResponseTimeHistogramDataV2(
public NodeHistogramSummaryView postResponseTimeHistogramDataV2(
@RequestParam("applicationName") @NotBlank String applicationName,
@RequestParam("serviceTypeCode") Short serviceTypeCode,
@RequestParam("from") @PositiveOrZero long from,
Expand All @@ -241,14 +242,21 @@ public NodeHistogramSummary postResponseTimeHistogramDataV2(
.build();
final NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option);

TimeHistogramFormat format = histogramFormat(useLoadHistogramFormat);

return new NodeHistogramSummaryView(nodeHistogramSummary, nodeHistogramSummary.getServerGroupList(), format);
}

private TimeHistogramFormat histogramFormat(boolean useLoadHistogramFormat) {
if (useLoadHistogramFormat) {
nodeHistogramSummary.setTimeHistogramFormat(TimeHistogramFormat.V2);
return TimeHistogramFormat.V2;
} else {
return TimeHistogramFormat.V1;
}
return nodeHistogramSummary;
}

@GetMapping(value = "/getResponseTimeHistogramDataV2")
public NodeHistogramSummary getResponseTimeHistogramDataV2(
public NodeHistogramSummaryView getResponseTimeHistogramDataV2(
@RequestParam("applicationName") @NotBlank String applicationName,
@RequestParam("serviceTypeCode") Short serviceTypeCode,
@RequestParam("from") @PositiveOrZero long from,
Expand Down Expand Up @@ -288,10 +296,9 @@ public NodeHistogramSummary getResponseTimeHistogramDataV2(
.build();

final NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option);
if (useLoadHistogramFormat) {
nodeHistogramSummary.setTimeHistogramFormat(TimeHistogramFormat.V2);
}
return nodeHistogramSummary;

final TimeHistogramFormat format = getTimeHistogramFormat(useLoadHistogramFormat);
return new NodeHistogramSummaryView(nodeHistogramSummary, nodeHistogramSummary.getServerGroupList(), format);
}

private List<Application> toApplications(List<String> applicationNames, List<Short> serviceTypeCodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

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

import com.navercorp.pinpoint.web.view.TimeSeries.TimeSeriesView;
import com.navercorp.pinpoint.web.view.TimeViewModel;
import com.navercorp.pinpoint.web.view.histogram.TimeHistogramChartBuilder;
import com.navercorp.pinpoint.web.view.histogram.TimeHistogramType;
import com.navercorp.pinpoint.web.vo.Application;

import java.util.Collections;
Expand Down Expand Up @@ -47,10 +44,6 @@ public List<TimeViewModel> createViewModel(TimeHistogramFormat timeHistogramForm
return format.build(application, histogramList);
}

public TimeSeriesView createTimeSeriesView(TimeHistogramType timeHistogramType) {
return new TimeHistogramChartBuilder(histogramList).build(timeHistogramType);
}

public List<TimeHistogram> getHistogramList() {
return histogramList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,32 @@

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

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.navercorp.pinpoint.web.applicationmap.histogram.ApplicationTimeHistogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogramFormat;
import com.navercorp.pinpoint.web.view.NodeHistogramSummarySerializer;
import com.navercorp.pinpoint.web.view.TimeSeries.TimeSeriesView;
import com.navercorp.pinpoint.web.view.histogram.HistogramView;
import com.navercorp.pinpoint.web.view.histogram.ServerHistogramView;
import com.navercorp.pinpoint.web.view.histogram.TimeHistogramType;
import com.navercorp.pinpoint.web.vo.Application;

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

/**
* @author HyunGil Jeong
*/
@JsonSerialize(using = NodeHistogramSummarySerializer.class)
public class NodeHistogramSummary {

private final Application application;
private final ServerGroupList serverGroupList;
private final NodeHistogram nodeHistogram;
private TimeHistogramFormat timeHistogramFormat = TimeHistogramFormat.V1;

public NodeHistogramSummary(Application application, ServerGroupList serverGroupList, NodeHistogram nodeHistogram) {
this.application = Objects.requireNonNull(application, "application");
this.serverGroupList = Objects.requireNonNull(serverGroupList, "serverGroupList");
this.nodeHistogram = Objects.requireNonNull(nodeHistogram, "nodeHistogram");
}

public Application getApplication() {
return application;
}

public ServerGroupList getServerGroupList() {
return serverGroupList;
}
Expand All @@ -60,35 +54,14 @@ public Histogram getHistogram() {
return nodeHistogram.getApplicationHistogram();
}

public TimeSeriesView getNodeTimeHistogram(TimeHistogramType timeHistogramType) {
return nodeHistogram.getApplicationTimeHistogram().createTimeSeriesView(timeHistogramType);
}

public TimeHistogramFormat getTimeHistogramFormat() {
return timeHistogramFormat;
}

public void setTimeHistogramFormat(TimeHistogramFormat timeHistogramFormat) {
this.timeHistogramFormat = timeHistogramFormat;
}

public HistogramView getHistogramView() {
String nodeName = NodeName.toNodeName(application.getName(), application.getServiceType());
Histogram applicationHistogram = nodeHistogram.getApplicationHistogram();
List<TimeHistogram> histogramList = nodeHistogram.getApplicationTimeHistogram().getHistogramList();
return new HistogramView(nodeName, applicationHistogram, histogramList);
}

public ServerHistogramView getAgentHistogramView() {
return new ServerHistogramView(NodeName.of(application), nodeHistogram, serverGroupList);
public ApplicationTimeHistogram getApplicationTimeHistogram() {
return nodeHistogram.getApplicationTimeHistogram();
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("NodeHistogramSummary{");
sb.append("serverGroupList=").append(serverGroupList);
sb.append(", nodeHistogram=").append(nodeHistogram);
sb.append('}');
return sb.toString();
return "NodeHistogramSummary{" + "serverGroupList=" + serverGroupList +
", nodeHistogram=" + nodeHistogram +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.navercorp.pinpoint.web.applicationmap.view;

import com.navercorp.pinpoint.common.server.util.json.JsonFields;
import com.navercorp.pinpoint.web.applicationmap.histogram.ApplicationTimeHistogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogramFormat;
import com.navercorp.pinpoint.web.applicationmap.nodes.NodeHistogramSummary;
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerGroupList;
import com.navercorp.pinpoint.web.view.TimeViewModel;
import com.navercorp.pinpoint.web.view.id.AgentNameView;
import com.navercorp.pinpoint.web.vo.ResponseTimeStatics;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public class NodeHistogramSummaryView {

private final NodeHistogramSummary nodeHistogramSummary;
private final NodeHistogram nodeHistogram;
private final TimeHistogramFormat format;

private final ServerGroupList serverGroupList;

public NodeHistogramSummaryView(NodeHistogramSummary nodeHistogramSummary, ServerGroupList serverGroupList, TimeHistogramFormat format) {
this.nodeHistogramSummary = Objects.requireNonNull(nodeHistogramSummary, "nodeHistogramSummary");
this.nodeHistogram = nodeHistogramSummary.getNodeHistogram();

this.serverGroupList = Objects.requireNonNull(serverGroupList, "serverGroupList");

this.format = Objects.requireNonNull(format, "format");
}

public long getCurrentServerTime() {
return System.currentTimeMillis();
}

public ServerGroupList getServerList() {
return serverGroupList;
}

public ResponseTimeStatics getResponseStatistics() {
return ResponseTimeStatics.fromHistogram(nodeHistogram.getApplicationHistogram());
}

public Histogram getHistogram() {
return nodeHistogram.getApplicationHistogram();
}

public Map<String, Histogram> getAgentHistogram() {
return nodeHistogram.getAgentHistogramMap();
}

public Map<String, ResponseTimeStatics> getAgentResponseStatistics() {
return nodeHistogram.getAgentResponseStatisticsMap();
}


public List<TimeViewModel> getTimeSeriesHistogram() {
ApplicationTimeHistogram applicationTimeHistogram = nodeHistogramSummary.getApplicationTimeHistogram();
if (applicationTimeHistogram == null) {
return List.of();
}
return applicationTimeHistogram.createViewModel(format);
}

public JsonFields<AgentNameView, List<TimeViewModel>> getAgentTimeSeriesHistogram() {
return nodeHistogram.getAgentTimeHistogram().createViewModel(format);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import com.navercorp.pinpoint.web.applicationmap.service.ResponseTimeHistogramService;
import com.navercorp.pinpoint.web.applicationmap.service.ResponseTimeHistogramServiceOption;
import com.navercorp.pinpoint.web.component.ApplicationFactory;
import com.navercorp.pinpoint.web.view.TimeSeries.TimeSeriesView;
import com.navercorp.pinpoint.web.view.histogram.HistogramView;
import com.navercorp.pinpoint.web.view.histogram.ServerHistogramView;
import com.navercorp.pinpoint.web.view.histogram.TimeHistogramChart;
import com.navercorp.pinpoint.web.view.histogram.TimeHistogramChartBuilder;
import com.navercorp.pinpoint.web.view.histogram.TimeHistogramType;
import com.navercorp.pinpoint.web.vo.Application;
import com.navercorp.pinpoint.web.vo.ApplicationPair;
Expand Down Expand Up @@ -85,7 +86,7 @@ public ServerHistogramView getWasServerHistogramData(
.setUseStatisticsAgentState(false) //set useStatisticsAgentState to false for agent data
.build();
NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option);
return nodeHistogramSummary.getAgentHistogramView();
return ServerHistogramView.view(nodeHistogramSummary);
}

@GetMapping(value = "/getWas/histogram")
Expand Down Expand Up @@ -120,7 +121,7 @@ public ResponseTimeStatics getWasResponseTimeStatistics(
}

@GetMapping(value = "/getWas/{type}/chart")
public TimeSeriesView getWasTimeHistogramChart(
public TimeHistogramChart getWasTimeHistogramChart(
@RequestParam("applicationName") @NotBlank String applicationName,
@RequestParam(value = "serviceTypeCode", required = false) Short serviceTypeCode,
@RequestParam(value = "serviceTypeName", required = false) @NotBlank String serviceTypeName,
Expand All @@ -137,7 +138,9 @@ public TimeSeriesView getWasTimeHistogramChart(
.setUseStatisticsAgentState(true)
.build();
NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option);
return nodeHistogramSummary.getNodeTimeHistogram(timeHistogramType);
ApplicationTimeHistogram applicationTimeHistogram = nodeHistogramSummary.getApplicationTimeHistogram();

return chartView(applicationTimeHistogram, timeHistogramType);
}

@GetMapping(value = "/getWas/histogramData")
Expand All @@ -156,7 +159,7 @@ public HistogramView getWasHistogramData(
.setUseStatisticsAgentState(true)
.build();
NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option);
return nodeHistogramSummary.getHistogramView();
return HistogramView.view(nodeHistogramSummary);
}

private ResponseTimeHistogramServiceOption.Builder createWasOptionBuilder(Application application, Range range) {
Expand All @@ -183,7 +186,7 @@ public ServerHistogramView postNodeServerHistogramData(
.setUseStatisticsAgentState(false) //set useStatisticsAgentState to false for agent data
.build();
NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option);
return nodeHistogramSummary.getAgentHistogramView();
return ServerHistogramView.view(nodeHistogramSummary);
}

@PostMapping(value = "/getNode/histogramData")
Expand All @@ -204,11 +207,11 @@ public HistogramView postNodeHistogramData(
.build();
NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option);

return nodeHistogramSummary.getHistogramView();
return HistogramView.view(nodeHistogramSummary);
}

@PostMapping(value = "/getNode/{type}/chart")
public TimeSeriesView postNodeTimeHistogramChart(
public TimeHistogramChart postNodeTimeHistogramChart(
@RequestParam("applicationName") @NotBlank String applicationName,
@RequestParam(value = "serviceTypeCode", required = false) Short serviceTypeCode,
@RequestParam(value = "serviceTypeName", required = false) @NotBlank String serviceTypeName,
Expand All @@ -227,7 +230,14 @@ public TimeSeriesView postNodeTimeHistogramChart(
.build();
NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option);

return nodeHistogramSummary.getNodeTimeHistogram(timeHistogramType);
ApplicationTimeHistogram applicationTimeHistogram = nodeHistogramSummary.getApplicationTimeHistogram();

return chartView(applicationTimeHistogram, timeHistogramType);
}

private TimeHistogramChart chartView(ApplicationTimeHistogram applicationTimeHistogram, TimeHistogramType timeHistogramType) {
return new TimeHistogramChartBuilder(applicationTimeHistogram.getHistogramList())
.build(timeHistogramType);
}

@GetMapping(value = "/getLink/histogramData")
Expand Down Expand Up @@ -261,7 +271,7 @@ public HistogramView newHistogramView(LinkHistogramSummary summary) {
}

@GetMapping(value = "/getLink/{type}/chart")
public TimeSeriesView getLinkTimeHistogramChart(
public TimeHistogramChart getLinkTimeHistogramChart(
@RequestParam("fromApplicationName") @NotBlank String fromApplicationName,
@RequestParam(value = "fromServiceTypeCode", required = false) Short fromServiceTypeCode,
@RequestParam(value = "fromServiceTypeName", required = false) @NotBlank String fromServiceTypeName,
Expand All @@ -283,7 +293,8 @@ public TimeSeriesView getLinkTimeHistogramChart(
responseTimeHistogramService.selectLinkHistogramData(fromApplication, toApplication, range);

ApplicationTimeHistogram histogram = linkHistogramSummary.getLinkApplicationTimeHistogram();
return histogram.createTimeSeriesView(timeHistogramType);

return chartView(histogram, timeHistogramType);
}

private ResponseTimeHistogramServiceOption.Builder createOptionBuilder(Application application, Range range,
Expand Down
Loading

0 comments on commit 5ddd983

Please sign in to comment.