Skip to content

Commit

Permalink
[pinpoint-apm#11050] Extract LinkHistogramSummaryView
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jun 3, 2024
1 parent 7081047 commit bcb44af
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.navercorp.pinpoint.web.component.ApplicationFactory;
import com.navercorp.pinpoint.web.validation.NullOrNotBlank;
import com.navercorp.pinpoint.web.view.ApplicationTimeHistogramViewModel;
import com.navercorp.pinpoint.web.view.LinkHistogramSummaryView;
import com.navercorp.pinpoint.web.vo.Application;
import com.navercorp.pinpoint.web.vo.ApplicationPair;
import com.navercorp.pinpoint.web.vo.ApplicationPairs;
Expand Down Expand Up @@ -316,7 +317,7 @@ private List<Application> mapApplicationPairsToApplications(List<ApplicationPair
}

@GetMapping(value = "/getLinkTimeHistogramData")
public LinkHistogramSummary getLinkTimeHistogramData(
public LinkHistogramSummaryView getLinkTimeHistogramData(
@RequestParam(value = "fromApplicationName", required = false) @NullOrNotBlank String fromApplicationName,
@RequestParam(value = "fromServiceTypeCode", required = false) Short fromServiceTypeCode,
@RequestParam(value = "toApplicationName", required = false) @NullOrNotBlank String toApplicationName,
Expand All @@ -333,10 +334,16 @@ public LinkHistogramSummary getLinkTimeHistogramData(
final Application toApplication = this.createApplication(toApplicationName, toServiceTypeCode);
final LinkHistogramSummary linkHistogramSummary =
responseTimeHistogramService.selectLinkHistogramData(fromApplication, toApplication, range);

TimeHistogramFormat format = getTimeHistogramFormat(useLoadHistogramFormat);
return new LinkHistogramSummaryView(linkHistogramSummary, format);
}

private TimeHistogramFormat getTimeHistogramFormat(boolean useLoadHistogramFormat) {
if (useLoadHistogramFormat) {
linkHistogramSummary.setTimeHistogramFormat(TimeHistogramFormat.V2);
return TimeHistogramFormat.V2;
}
return linkHistogramSummary;
return TimeHistogramFormat.V1;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,14 @@

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

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.TimeHistogramFormat;
import com.navercorp.pinpoint.web.view.LinkHistogramSummarySerializer;
import com.navercorp.pinpoint.web.view.TimeSeries.TimeSeriesView;
import com.navercorp.pinpoint.web.view.TimeViewModel;
import com.navercorp.pinpoint.web.view.histogram.HistogramView;
import com.navercorp.pinpoint.web.view.histogram.TimeHistogramType;

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

/**
* @author HyunGil Jeong
*/
@JsonSerialize(using = LinkHistogramSummarySerializer.class)
public class LinkHistogramSummary {

private final Link link;
Expand All @@ -40,10 +32,6 @@ public LinkHistogramSummary(Link link) {
this.link = Objects.requireNonNull(link, "link");
}

public void setTimeHistogramFormat(TimeHistogramFormat timeHistogramFormat) {
link.setTimeHistogramFormat(timeHistogramFormat);
}

public LinkName getLinkName() {
return link.getLinkName();
}
Expand All @@ -52,16 +40,8 @@ public Histogram getHistogram() {
return link.getHistogram();
}

public List<TimeViewModel> getTimeSeriesHistogram() {
return link.getLinkApplicationTimeSeriesHistogram();
}

public TimeSeriesView getTimeHistogram(TimeHistogramType timeHistogramType) {
return link.getLinkApplicationTimeHistogram().createTimeSeriesView(timeHistogramType);
}

public HistogramView getHistogramView() {
return new HistogramView(link.getLinkName(), link.getHistogram(), link.getLinkApplicationTimeHistogram());
public ApplicationTimeHistogram getLinkApplicationTimeHistogram() {
return link.getLinkApplicationTimeHistogram();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.common.server.util.time.RangeValidator;
import com.navercorp.pinpoint.web.applicationmap.histogram.ApplicationTimeHistogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram;
import com.navercorp.pinpoint.web.applicationmap.link.LinkHistogramSummary;
import com.navercorp.pinpoint.web.applicationmap.nodes.NodeHistogramSummary;
Expand Down Expand Up @@ -246,7 +247,11 @@ public HistogramView getLinkHistogramData(
LinkHistogramSummary linkHistogramSummary =
responseTimeHistogramService.selectLinkHistogramData(fromApplication, toApplication, range);

return linkHistogramSummary.getHistogramView();
return newHistogramView(linkHistogramSummary);
}

public HistogramView newHistogramView(LinkHistogramSummary summary) {
return new HistogramView(summary.getLinkName(), summary.getHistogram(), summary.getLinkApplicationTimeHistogram());
}

@GetMapping(value = "/getLink/{type}/chart")
Expand All @@ -271,7 +276,8 @@ public TimeSeriesView getLinkTimeHistogramChart(
LinkHistogramSummary linkHistogramSummary =
responseTimeHistogramService.selectLinkHistogramData(fromApplication, toApplication, range);

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

private ResponseTimeHistogramServiceOption.Builder createOptionBuilder(Application application, Range range,
Expand Down Expand Up @@ -304,6 +310,6 @@ private Application createApplication(String applicationName, Short serviceTypeC
}
}
logger.error("can not create application. applicationName: {}, serviceTypeCode: {}, serviceTypeName: {}", applicationName, serviceTypeCode, serviceTypeName);
throw new IllegalArgumentException("can not create application. applicationName: " + serviceTypeName);
throw new IllegalArgumentException("can not create application. applicationName: " + applicationName);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.navercorp.pinpoint.web.view;

import com.navercorp.pinpoint.web.applicationmap.histogram.ApplicationTimeHistogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogramFormat;
import com.navercorp.pinpoint.web.applicationmap.link.LinkHistogramSummary;

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

public class LinkHistogramSummaryView {
private final LinkHistogramSummary linkHistogramSummary;
private final TimeHistogramFormat format;

public LinkHistogramSummaryView(LinkHistogramSummary linkHistogramSummary, TimeHistogramFormat format) {
this.linkHistogramSummary = Objects.requireNonNull(linkHistogramSummary, "linkHistogramSummary");
this.format = Objects.requireNonNull(format, "format");
}

public String getKey() {
return linkHistogramSummary.getLinkName().getName();
}

public Histogram getHistogram() {
return linkHistogramSummary.getHistogram();
}

public List<TimeViewModel> getTimeSeriesHistogram() {
ApplicationTimeHistogram histogram = linkHistogramSummary.getLinkApplicationTimeHistogram();
return histogram.createViewModel(format);
}
}

0 comments on commit bcb44af

Please sign in to comment.