Skip to content

Commit

Permalink
[pinpoint-apm#10944] Use RangeValidator to check the search time.
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed Apr 23, 2024
1 parent 0e40afe commit 759ead1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.navercorp.pinpoint.inspector.web.controller;

import com.navercorp.pinpoint.common.server.util.time.RangeValidator;
import com.navercorp.pinpoint.inspector.web.model.InspectorDataSearchKey;
import com.navercorp.pinpoint.inspector.web.model.InspectorMetricData;
import com.navercorp.pinpoint.inspector.web.model.InspectorMetricGroupData;
Expand All @@ -29,6 +30,7 @@
import com.navercorp.pinpoint.metric.common.util.TimeWindowSlotCentricSampler;
import com.navercorp.pinpoint.pinot.tenant.TenantProvider;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -43,17 +45,17 @@
@RequestMapping("/getAgentStatV2")
public class AgentStatV2Controller {

AgentStatService agentStatService;

ApdexStatService apdexStatService;

private final TimeWindowSampler DEFAULT_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(5000L, 200);
private final AgentStatService agentStatService;
private final ApdexStatService apdexStatService;
private final TenantProvider tenantProvider;
private final RangeValidator rangeValidator;

public AgentStatV2Controller(AgentStatService agentStatService, ApdexStatService apdexStatService, TenantProvider tenantProvider) {
public AgentStatV2Controller(AgentStatService agentStatService, ApdexStatService apdexStatService, TenantProvider tenantProvider, @Qualifier("rangeValidator14d") RangeValidator rangeValidator) {
this.agentStatService = Objects.requireNonNull(agentStatService, "agentStatService");
this.apdexStatService = Objects.requireNonNull(apdexStatService, "apdexStatService");
this.tenantProvider = Objects.requireNonNull(tenantProvider, "tenantProvider");
this.rangeValidator = Objects.requireNonNull(rangeValidator, "rangeValidator");
}

// TODO : (minwoo) tenantId should be considered. The collector side should also be considered.
Expand All @@ -65,8 +67,11 @@ public InspectorMetricView getAgentStatChart(
@RequestParam("from") long from,
@RequestParam("to") long to,
@RequestParam(value="version", defaultValue="1") int version) {
Range range = Range.newRange(from, to);
rangeValidator.validate(range.getFromInstant(), range.getToInstant());

String tenantId = tenantProvider.getTenantId();
TimeWindow timeWindow = new TimeWindow(Range.newRange(from, to), DEFAULT_TIME_WINDOW_SAMPLER);
TimeWindow timeWindow = getTimeWindow(range);
InspectorDataSearchKey inspectorDataSearchKey = new InspectorDataSearchKey(tenantId, applicationName, agentId, metricDefinitionId, timeWindow, version);

InspectorMetricData inspectorMetricData = agentStatService.selectAgentStat(inspectorDataSearchKey, timeWindow);
Expand All @@ -82,6 +87,9 @@ public InspectorMetricView getApdexStatChart(
@RequestParam("from") long from,
@RequestParam("to") long to,
@RequestParam(value="version", defaultValue="1") int version) {
Range range = Range.newRange(from, to);
rangeValidator.validate(range.getFromInstant(), range.getToInstant());

InspectorMetricData inspectorMetricData = apdexStatService.selectAgentStat(applicationName, serviceTypeName, metricDefinitionId, agentId, from, to);
return new InspectorMetricView(inspectorMetricData);
}
Expand All @@ -94,11 +102,18 @@ public InspectorMetricGroupDataView getAgentStatChartList(
@RequestParam("from") long from,
@RequestParam("to") long to,
@RequestParam(value="version", defaultValue="1") int version) {
Range range = Range.newRange(from, to);
rangeValidator.validate(range.getFromInstant(), range.getToInstant());

String tenantId = tenantProvider.getTenantId();
TimeWindow timeWindow = new TimeWindow(Range.newRange(from, to), DEFAULT_TIME_WINDOW_SAMPLER);
TimeWindow timeWindow = getTimeWindow(range);
InspectorDataSearchKey inspectorDataSearchKey = new InspectorDataSearchKey(tenantId, applicationName, agentId, metricDefinitionId, timeWindow, version);

InspectorMetricGroupData inspectorMetricGroupData = agentStatService.selectAgentStatWithGrouping(inspectorDataSearchKey, timeWindow);
return new InspectorMetricGroupDataView(inspectorMetricGroupData);
}

private TimeWindow getTimeWindow(Range range) {
return new TimeWindow(range, DEFAULT_TIME_WINDOW_SAMPLER);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.navercorp.pinpoint.inspector.web.controller;


import com.navercorp.pinpoint.common.server.util.time.RangeValidator;
import com.navercorp.pinpoint.inspector.web.model.InspectorDataSearchKey;
import com.navercorp.pinpoint.inspector.web.model.InspectorMetricData;
import com.navercorp.pinpoint.inspector.web.model.InspectorMetricGroupData;
Expand All @@ -14,6 +15,7 @@
import com.navercorp.pinpoint.metric.common.util.TimeWindowSlotCentricSampler;
import com.navercorp.pinpoint.pinot.tenant.TenantProvider;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -24,19 +26,17 @@
@RestController
@RequestMapping("/getApplicationStatV2")
public class ApplicationStatV2Controller {

private final TimeWindowSampler DEFAULT_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(5000L, 200);
private final TimeWindowSampler DEFAULT_TIME_WINDOW_SAMPLER_30M = new TimeWindowSlotCentricSampler(30000L, 200);

private final TenantProvider tenantProvider;
private final ApplicationStatService applicationStatService;

private final ApdexStatService apdexStatService;
private final RangeValidator rangeValidator;

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

@GetMapping(value = "/chart")
Expand All @@ -45,25 +45,27 @@ public InspectorMetricView getApplicationStatChart(
@RequestParam("metricDefinitionId") String metricDefinitionId,
@RequestParam("from") long from,
@RequestParam("to") long to) {
Range range = Range.newRange(from, to);
rangeValidator.validate(range.getFromInstant(), range.getToInstant());

String tenantId = tenantProvider.getTenantId();
TimeWindow timeWindow = getTimeWindow(from, to);
TimeWindow timeWindow = getTimeWindow(range);
InspectorDataSearchKey inspectorDataSearchKey = new InspectorDataSearchKey(tenantId, applicationName, InspectorDataSearchKey.UNKNOWN_NAME, metricDefinitionId, timeWindow);

InspectorMetricData inspectorMetricData = applicationStatService.selectApplicationStat(inspectorDataSearchKey, timeWindow);
return new InspectorMetricView(inspectorMetricData);
}

private TimeWindow getTimeWindow(long from, long to) {
return new TimeWindow(Range.newRange(from, to), DEFAULT_TIME_WINDOW_SAMPLER_30M);
}

@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) {
Range range = Range.newRange(from, to);
rangeValidator.validate(range.getFromInstant(), range.getToInstant());

InspectorMetricData inspectorMetricData = apdexStatService.selectApplicationStat(applicationName, serviceTypeName, metricDefinitionId, from, to);
return new InspectorMetricView(inspectorMetricData);
}
Expand All @@ -74,11 +76,18 @@ public InspectorMetricGroupDataView getApplicationStatChartList(
@RequestParam("metricDefinitionId") String metricDefinitionId,
@RequestParam("from") long from,
@RequestParam("to") long to) {
Range range = Range.newRange(from, to);
rangeValidator.validate(range.getFromInstant(), range.getToInstant());

String tenantId = tenantProvider.getTenantId();
TimeWindow timeWindow = getTimeWindow(from, to);
TimeWindow timeWindow = getTimeWindow(range);
InspectorDataSearchKey inspectorDataSearchKey = new InspectorDataSearchKey(tenantId, applicationName, InspectorDataSearchKey.UNKNOWN_NAME, metricDefinitionId, timeWindow);

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

private TimeWindow getTimeWindow(Range range) {
return new TimeWindow(range, DEFAULT_TIME_WINDOW_SAMPLER_30M);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.navercorp.pinpoint.common.server.util.DateTimeFormatUtils;

import java.time.Instant;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -47,6 +48,14 @@ public long getFrom() {
return from;
}

public Instant getFromInstant() {
return toInstant(from);
}

public Instant getToInstant() {
return toInstant(to);
}

public String getFromDateTime() {
return DateTimeFormatUtils.formatSimple(from);
}
Expand All @@ -69,6 +78,10 @@ public static void validate(Range range) {
}
}

private Instant toInstant(long timestamp) {
return Instant.ofEpochMilli(timestamp);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.navercorp.pinpoint.metric.web.controller;

import com.navercorp.pinpoint.common.server.util.time.RangeValidator;
import com.navercorp.pinpoint.metric.common.model.Range;
import com.navercorp.pinpoint.metric.common.model.Tag;
import com.navercorp.pinpoint.metric.common.model.TimeWindow;
Expand All @@ -30,6 +31,7 @@
import com.navercorp.pinpoint.metric.common.util.TagUtils;
import com.navercorp.pinpoint.metric.web.view.SystemMetricView;
import com.navercorp.pinpoint.pinot.tenant.TenantProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -48,17 +50,20 @@ public class SystemMetricController {
private final SystemMetricHostInfoService systemMetricHostInfoService;
private final YMLSystemMetricBasicGroupManager systemMetricBasicGroupManager;
private final TenantProvider tenantProvider;

private final TimeWindowSampler DEFAULT_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(10000L, 200);
private final RangeValidator rangeValidator;

public SystemMetricController(SystemMetricDataService systemMetricDataService,
SystemMetricHostInfoService systemMetricHostInfoService,
YMLSystemMetricBasicGroupManager systemMetricBasicGroupManager,
TenantProvider tenantProvider) {
TenantProvider tenantProvider,
@Qualifier("rangeValidator30d") RangeValidator rangeValidator
) {
this.systemMetricDataService = Objects.requireNonNull(systemMetricDataService, "systemMetricService");
this.systemMetricHostInfoService = Objects.requireNonNull(systemMetricHostInfoService, "systemMetricHostInfoService");
this.systemMetricBasicGroupManager = Objects.requireNonNull(systemMetricBasicGroupManager, "systemMetricBasicGroupManager");
this.tenantProvider = Objects.requireNonNull(tenantProvider, "tenantProvider");
this.rangeValidator = Objects.requireNonNull(rangeValidator, "rangeValidator");
}

@GetMapping(value = "/hostGroup")
Expand Down Expand Up @@ -94,6 +99,9 @@ public SystemMetricView getCollectedMetricData(@RequestParam("hostGroupName") St
@RequestParam("from") long from,
@RequestParam("to") long to,
@RequestParam(value = "tags", required = false) String tags) {
Range range = Range.newRange(from, to);
rangeValidator.validate(range.getFromInstant(), range.getToInstant());

String tenantId = tenantProvider.getTenantId();
TimeWindow timeWindow = new TimeWindow(Range.newRange(from, to), DEFAULT_TIME_WINDOW_SAMPLER);
MetricDataSearchKey metricDataSearchKey = new MetricDataSearchKey(tenantId, hostGroupName, hostName, systemMetricBasicGroupManager.findMetricName(metricDefinitionId), metricDefinitionId, timeWindow);
Expand Down

0 comments on commit 759ead1

Please sign in to comment.