Skip to content

Commit

Permalink
[#4456] add apdex api for application inspector page
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed Feb 19, 2024
1 parent 15ff317 commit c0a1014
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.navercorp.pinpoint.inspector.web.model.InspectorDataSearchKey;
import com.navercorp.pinpoint.inspector.web.model.InspectorMetricData;
import com.navercorp.pinpoint.inspector.web.model.InspectorMetricGroupData;
import com.navercorp.pinpoint.inspector.web.service.ApdexStatService;
import com.navercorp.pinpoint.inspector.web.service.ApplicationStatService;
import com.navercorp.pinpoint.inspector.web.view.InspectorMetricGroupDataVeiw;
import com.navercorp.pinpoint.inspector.web.view.InspectorMetricView;
Expand All @@ -12,6 +13,7 @@
import com.navercorp.pinpoint.metric.common.util.TimeWindowSampler;
import com.navercorp.pinpoint.metric.common.util.TimeWindowSlotCentricSampler;
import com.navercorp.pinpoint.pinot.tenant.TenantProvider;
import jakarta.validation.constraints.NotBlank;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -28,8 +30,11 @@ public class ApplicationStatV2Controller {
private final TenantProvider tenantProvider;
private final ApplicationStatService applicationStatService;

public ApplicationStatV2Controller(ApplicationStatService applicationStatService, TenantProvider tenantProvider) {
private final ApdexStatService apdexStatService;

public ApplicationStatV2Controller(ApplicationStatService applicationStatService, TenantProvider tenantProvider, ApdexStatService apdexStatService) {
this.applicationStatService = Objects.requireNonNull(applicationStatService, "applicationStatService");
this.apdexStatService = Objects.requireNonNull(apdexStatService, "apdexStatService");
this.tenantProvider = Objects.requireNonNull(tenantProvider, "tenantProvider");
}

Expand All @@ -47,6 +52,17 @@ public InspectorMetricView getApplicationStatChart(
return new InspectorMetricView(inspectorMetricData);
}

@GetMapping(value = "/chart", params = "metricDefinitionId=apdex")
public InspectorMetricView getApdexStatChart(
@RequestParam("applicationName") String applicationName,
@RequestParam("serviceTypeName") @NotBlank String serviceTypeName,
@RequestParam("metricDefinitionId") String metricDefinitionId,
@RequestParam("from") long from,
@RequestParam("to") long to) {
InspectorMetricData inspectorMetricData = apdexStatService.selectApplicationStat(applicationName, serviceTypeName, metricDefinitionId, from, to);
return new InspectorMetricView(inspectorMetricData);
}

@GetMapping(value = "/chartList")
public InspectorMetricGroupDataVeiw getApplicationStatChartList(
@RequestParam("applicationName") String applicationName,
Expand All @@ -59,7 +75,5 @@ public InspectorMetricGroupDataVeiw getApplicationStatChartList(

InspectorMetricGroupData inspectorMetricGroupData = applicationStatService.selectApplicationStatWithGrouping(inspectorDataSearchKey, timeWindow);
return new InspectorMetricGroupDataVeiw(inspectorMetricGroupData);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@
*/
public interface ApdexStatService {
InspectorMetricData selectAgentStat(String applicationName, String serviceTypeName, String metricDefinitionId, String agentId, long from, long to);

InspectorMetricData selectApplicationStat(String applicationName, String serviceTypeName, String metricDefinitionId, long from, long to);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentApdexScoreChart;
import com.navercorp.pinpoint.web.vo.stat.chart.agent.AgentStatPoint;
import com.navercorp.pinpoint.web.vo.stat.chart.application.ApplicationApdexScoreChart;
import com.navercorp.pinpoint.web.vo.stat.chart.application.ApplicationStatPoint;
import com.navercorp.pinpoint.web.vo.stat.chart.application.DefaultStatChartGroup;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
Expand All @@ -59,18 +61,21 @@ public class DefaultApdexStatService implements ApdexStatService {

private ApdexScoreService apdexScoreService;

private final YMLInspectorManager ymlInspectorManager;
private final YMLInspectorManager agentYmlInspectorManager;
private final YMLInspectorManager appYmlInspectorManager;

public DefaultApdexStatService(ApplicationFactory applicationFactory, ApdexScoreService apdexScoreService, @Qualifier("agentInspectorDefinition") Mappings agentInspectorDefinition) {
public DefaultApdexStatService(ApplicationFactory applicationFactory, ApdexScoreService apdexScoreService, @Qualifier("agentInspectorDefinition") Mappings agentInspectorDefinition, @Qualifier("applicationInspectorDefinition") Mappings applicationInspectorDefinition) {
Objects.requireNonNull(agentInspectorDefinition, "agentInspectorDefinition");
this.ymlInspectorManager = new YMLInspectorManager(agentInspectorDefinition);
this.agentYmlInspectorManager = new YMLInspectorManager(agentInspectorDefinition);
Objects.requireNonNull(applicationInspectorDefinition, "applicationInspectorDefinition");
this.appYmlInspectorManager = new YMLInspectorManager(agentInspectorDefinition);
this.applicationFactory = Objects.requireNonNull(applicationFactory, "applicationFactory");
this.apdexScoreService = Objects.requireNonNull(apdexScoreService, "apdexScoreService");
}

@Override
public InspectorMetricData selectAgentStat(String applicationName, String serviceTypeName, String metricDefinitionId, String agentId, long from, long to) {
MetricDefinition metricDefinition = ymlInspectorManager.findElementOfBasicGroup(metricDefinitionId);
MetricDefinition metricDefinition = agentYmlInspectorManager.findElementOfBasicGroup(metricDefinitionId);

final Range range = Range.between(from, to);
TimeWindow timeWindow = new TimeWindow(range, APDEX_SCORE_TIME_WINDOW_SAMPLER);
Expand All @@ -81,24 +86,63 @@ public InspectorMetricData selectAgentStat(String applicationName, String servic
return convertToInspectorMetricData(metricDefinition, agentApdexScoreChart);
}

@Override
public InspectorMetricData selectApplicationStat(String applicationName, String serviceTypeName, String metricDefinitionId, long from, long to) {
MetricDefinition metricDefinition = appYmlInspectorManager.findElementOfBasicGroup(metricDefinitionId);
final Range range = Range.between(from, to);
TimeWindow timeWindow = new TimeWindow(range, APDEX_SCORE_TIME_WINDOW_SAMPLER);
Application application = applicationFactory.createApplicationByTypeName(applicationName, serviceTypeName);
ApplicationApdexScoreChart applicationApdexScoreChart = (ApplicationApdexScoreChart) apdexScoreService.selectApplicationChart(application, range, timeWindow);

return convertToInspectorMetricData(metricDefinition, applicationApdexScoreChart);
}

private InspectorMetricData convertToInspectorMetricData(MetricDefinition metricDefinition, ApplicationApdexScoreChart applicationApdexScoreChart) {
DefaultStatChartGroup<ApplicationStatPoint<Double>> statChartGroup = (DefaultStatChartGroup)applicationApdexScoreChart.getCharts();
Map<StatChartGroup.ChartType, Chart<ApplicationStatPoint<Double>>> chartDatas = statChartGroup.getCharts();
Collection<Chart<ApplicationStatPoint<Double>>> values = chartDatas.values();
List<Double> avgValueList = new ArrayList<>(values.size());
List<Double> minValueList = new ArrayList<>(values.size());
List<Double> maxValueList = new ArrayList<>(values.size());
List<Long> timestampList = new ArrayList<>(values.size());

for (Chart<ApplicationStatPoint<Double>> chartData : values) {
List<ApplicationStatPoint<Double>> points = chartData.getPoints();
for (ApplicationStatPoint<Double> point : points) {
timestampList.add(point.getXVal());
avgValueList.add(point.getYValForAvg());
minValueList.add(point.getYValForMin());
maxValueList.add(point.getYValForMax());
}
}

Field field = metricDefinition.getFields().get(0);
List<InspectorMetricValue> metricValueList = new ArrayList<>(3);
metricValueList.add(new InspectorMetricValue("AVG", field.getTags(), field.getChartType(), field.getUnit(), avgValueList));
metricValueList.add(new InspectorMetricValue("MIN", field.getTags(), field.getChartType(), field.getUnit(), minValueList));
metricValueList.add(new InspectorMetricValue("MAX", field.getTags(), field.getChartType(), field.getUnit(), maxValueList));

return new InspectorMetricData(metricDefinition.getTitle(), timestampList, metricValueList);
}

private InspectorMetricData convertToInspectorMetricData(MetricDefinition metricDefinition, AgentApdexScoreChart agentApdexScoreChart) {
DefaultStatChartGroup<AgentStatPoint<Double>> statChartGroup = (DefaultStatChartGroup)agentApdexScoreChart.getCharts();
Map<StatChartGroup.ChartType, Chart<AgentStatPoint<Double>>> chartDatas = statChartGroup.getCharts();
Collection<Chart<AgentStatPoint<Double>>> values = chartDatas.values();
List<Double> avgList = new ArrayList<>(values.size());
List<Double> avgValueList = new ArrayList<>(values.size());
List<Long> timestampList = new ArrayList<>(values.size());

for (Chart<AgentStatPoint<Double>> chartData : values) {
List<AgentStatPoint<Double>> points = chartData.getPoints();
for (AgentStatPoint<Double> point : points) {
timestampList.add(point.getXVal());
avgList.add(point.getAvgYVal());
avgValueList.add(point.getAvgYVal());
}
}

List<InspectorMetricValue> metricValueList = new ArrayList<>(1);
Field field = metricDefinition.getFields().get(0);
InspectorMetricValue apdexMetricValue = new InspectorMetricValue(field.getFieldAlias(), TagUtils.defaultTags(null), field.getChartType(), field.getUnit(), avgList);
InspectorMetricValue apdexMetricValue = new InspectorMetricValue(field.getFieldAlias(), TagUtils.defaultTags(null), field.getChartType(), field.getUnit(), avgValueList);
metricValueList.add(apdexMetricValue);

return new InspectorMetricData(metricDefinition.getTitle(), timestampList, metricValueList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,13 @@ mappings:
fieldAlias: "MAX"
matchingRule: ALL
aggregationFunction: MAX
unit: "count"
unit: "count"
- definitionId: "apdex"
metricName: "apdex"
title: "Apdex Score"
fields:
- fieldName: "apdex"
matchingRule: EXACT_ONE
aggregationFunction : AVG_MIN_MAX
chartType : "spline"
unit : "count"

0 comments on commit c0a1014

Please sign in to comment.