Skip to content

Commit

Permalink
[#9597] add inspector api for application stat
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo.jung authored and minwoo-jung committed Jan 22, 2024
1 parent f83fcf6 commit 281dff9
Show file tree
Hide file tree
Showing 70 changed files with 1,024 additions and 407 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import com.navercorp.pinpoint.exceptiontrace.web.util.GroupByAttributes;
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionMetaDataView;
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionTraceView;
import com.navercorp.pinpoint.metric.web.util.Range;
import com.navercorp.pinpoint.metric.common.model.Range;
import com.navercorp.pinpoint.metric.common.model.TimeWindow;
import com.navercorp.pinpoint.metric.common.util.TimeWindowSampler;
import com.navercorp.pinpoint.metric.common.util.TimeWindowSlotCentricSampler;
import com.navercorp.pinpoint.metric.web.util.TimePrecision;
import com.navercorp.pinpoint.metric.web.util.TimeWindow;
import com.navercorp.pinpoint.metric.web.util.TimeWindowSampler;
import com.navercorp.pinpoint.metric.web.util.TimeWindowSlotCentricSampler;
import com.navercorp.pinpoint.pinot.tenant.TenantProvider;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.PositiveOrZero;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceGroup;
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceValueView;
import com.navercorp.pinpoint.metric.web.util.TimeWindow;
import com.navercorp.pinpoint.metric.common.model.TimeWindow;
import com.navercorp.pinpoint.metric.common.util.TimeUtils;
import com.navercorp.pinpoint.metric.web.view.TimeSeriesView;
import com.navercorp.pinpoint.metric.web.view.TimeseriesValueGroupView;

Expand Down Expand Up @@ -51,7 +52,7 @@ public static ExceptionTraceView newViewFromValueViews(
Objects.requireNonNull(timeWindow, "timeWindow");
Objects.requireNonNull(exceptionTraceValueViews, "exceptionTraceValueViews");

List<Long> timestampList = createTimeStampList(timeWindow);
List<Long> timestampList = TimeUtils.createTimeStampList(timeWindow);
List<TimeseriesValueGroupView> timeSeriesValueGroupViews = new ArrayList<>();
timeSeriesValueGroupViews.add(
ExceptionTraceGroup.newGroupFromValueViews(groupName, exceptionTraceValueViews)
Expand All @@ -62,16 +63,6 @@ public static ExceptionTraceView newViewFromValueViews(
);
}

private static List<Long> createTimeStampList(TimeWindow timeWindow) {
List<Long> timestampList = new ArrayList<>((int) timeWindow.getWindowRangeCount());

for (Long timestamp : timeWindow) {
timestampList.add(timestamp);
}

return timestampList;
}

@Override
public String getTitle() {
return TITLE;
Expand Down
4 changes: 4 additions & 0 deletions inspector-module/inspector-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-metric-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
public class InspectorWebApp {

@Bean
public Mappings inspectorDefinition(@Value(YMLInspectorManager.DEFINITION_YML)
public Mappings agentInspectorDefinition(@Value(YMLInspectorManager.AGENT_DEFINITION_YML_PATH)
Resource inspectorMetric,
YAMLMapper mapper) throws IOException {

Expand All @@ -59,4 +59,14 @@ public Mappings inspectorDefinition(@Value(YMLInspectorManager.DEFINITION_YML)
return mapper.readValue(stream, Mappings.class);
}

@Bean
public Mappings applicationInspectorDefinition(@Value(YMLInspectorManager.APPLICATION_DEFINITION_YML_PATH)
Resource inspectorMetric,
YAMLMapper mapper) throws IOException {

InputStream stream = inspectorMetric.getInputStream();

return mapper.readValue(stream, Mappings.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import com.navercorp.pinpoint.inspector.web.model.TagInformation;
import com.navercorp.pinpoint.metric.common.config.CommonRegistryHandler;
import com.navercorp.pinpoint.metric.common.model.Tag;
import com.navercorp.pinpoint.metric.web.model.chart.SystemMetricPoint;
import com.navercorp.pinpoint.metric.common.model.chart.AvgMinMaxMetricPoint;
import com.navercorp.pinpoint.metric.common.util.SystemMetricPoint;
import com.navercorp.pinpoint.metric.web.mybatis.typehandler.DoubleTypeHandler;
import com.navercorp.pinpoint.metric.web.mybatis.typehandler.TagTypeHandler;
import com.navercorp.pinpoint.mybatis.MyBatisRegistryHandler;
Expand All @@ -44,6 +45,7 @@ public void registerTypeAlias(TypeAliasRegistry typeAliasRegistry) {
registryHandler.registerTypeAlias(typeAliasRegistry);

typeAliasRegistry.registerAlias(SystemMetricPoint.class);
typeAliasRegistry.registerAlias(AvgMinMaxMetricPoint.class);
typeAliasRegistry.registerAlias(InspectorQueryParameter.class);
typeAliasRegistry.registerAlias("DoubleHandler", DoubleTypeHandler.class);
typeAliasRegistry.registerAlias(TagInformation.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
import com.navercorp.pinpoint.inspector.web.service.AgentStatService;
import com.navercorp.pinpoint.inspector.web.view.InspectorMetricGroupDataVeiw;
import com.navercorp.pinpoint.inspector.web.view.InspectorMetricView;
import com.navercorp.pinpoint.metric.web.util.Range;
import com.navercorp.pinpoint.metric.web.util.TimeWindow;
import com.navercorp.pinpoint.metric.web.util.TimeWindowSampler;
import com.navercorp.pinpoint.metric.web.util.TimeWindowSlotCentricSampler;
import com.navercorp.pinpoint.metric.web.view.SystemMetricView;
import com.navercorp.pinpoint.metric.common.model.Range;
import com.navercorp.pinpoint.metric.common.model.TimeWindow;
import com.navercorp.pinpoint.metric.common.util.TimeWindowSampler;
import com.navercorp.pinpoint.metric.common.util.TimeWindowSlotCentricSampler;
import com.navercorp.pinpoint.pinot.tenant.TenantProvider;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -42,13 +41,13 @@
@RequestMapping("/getAgentStatV2")
public class AgentStatV2Controller {

AgentStatService agentStatChartService;
AgentStatService agentStatService;

private final TimeWindowSampler DEFAULT_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(5000L, 200);
private final TenantProvider tenantProvider;

public AgentStatV2Controller(AgentStatService agentStatChartService, TenantProvider tenantProvider) {
this.agentStatChartService = Objects.requireNonNull(agentStatChartService, "agentStatChartService");
public AgentStatV2Controller(AgentStatService agentStatService, TenantProvider tenantProvider) {
this.agentStatService = Objects.requireNonNull(agentStatService, "agentStatService");
this.tenantProvider = Objects.requireNonNull(tenantProvider, "tenantProvider");
}

Expand All @@ -61,9 +60,9 @@ public InspectorMetricView getAgentStatChart(
@RequestParam("to") long to) {
String tenantId = tenantProvider.getTenantId();
TimeWindow timeWindow = new TimeWindow(Range.newRange(from, to), DEFAULT_TIME_WINDOW_SAMPLER);
InspectorDataSearchKey inspectorDataSearchKey = new InspectorDataSearchKey(tenantId, agentId, metricDefinitionId, timeWindow);
InspectorDataSearchKey inspectorDataSearchKey = new InspectorDataSearchKey(tenantId, InspectorDataSearchKey.UNKNOWN_NAME, agentId, metricDefinitionId, timeWindow);

InspectorMetricData inspectorMetricData = agentStatChartService.selectAgentStat(inspectorDataSearchKey, timeWindow);
InspectorMetricData inspectorMetricData = agentStatService.selectAgentStat(inspectorDataSearchKey, timeWindow);
return new InspectorMetricView(inspectorMetricData);
}

Expand All @@ -75,9 +74,9 @@ public InspectorMetricGroupDataVeiw getAgentStatChartList(
@RequestParam("to") long to) {
String tenantId = tenantProvider.getTenantId();
TimeWindow timeWindow = new TimeWindow(Range.newRange(from, to), DEFAULT_TIME_WINDOW_SAMPLER);
InspectorDataSearchKey inspectorDataSearchKey = new InspectorDataSearchKey(tenantId, agentId, metricDefinitionId, timeWindow);
InspectorDataSearchKey inspectorDataSearchKey = new InspectorDataSearchKey(tenantId, InspectorDataSearchKey.UNKNOWN_NAME, agentId, metricDefinitionId, timeWindow);

InspectorMetricGroupData inspectorMetricGroupData = agentStatChartService.selectAgentStatWithGrouping(inspectorDataSearchKey, timeWindow);
InspectorMetricGroupData inspectorMetricGroupData = agentStatService.selectAgentStatWithGrouping(inspectorDataSearchKey, timeWindow);
return new InspectorMetricGroupDataVeiw(inspectorMetricGroupData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.navercorp.pinpoint.inspector.web.controller;


import com.navercorp.pinpoint.inspector.web.model.InspectorDataSearchKey;
import com.navercorp.pinpoint.inspector.web.model.InspectorMetricData;
import com.navercorp.pinpoint.inspector.web.service.ApplicationStatService;
import com.navercorp.pinpoint.inspector.web.view.InspectorMetricView;
import com.navercorp.pinpoint.metric.common.model.Range;
import com.navercorp.pinpoint.metric.common.model.TimeWindow;
import com.navercorp.pinpoint.metric.common.util.TimeWindowSampler;
import com.navercorp.pinpoint.metric.common.util.TimeWindowSlotCentricSampler;
import com.navercorp.pinpoint.pinot.tenant.TenantProvider;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequestMapping("/getApplicationStatV2")
public class ApplicationStatV2Controller {

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

private final TenantProvider tenantProvider;
private final ApplicationStatService applicationStatService;

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

@GetMapping(value = "/chart")
public InspectorMetricView getApplicationStatChart(
@RequestParam("applicationName") String applicationName,
@RequestParam("metricDefinitionId") String metricDefinitionId,
@RequestParam("from") long from,
@RequestParam("to") long to) {
String tenantId = tenantProvider.getTenantId();
TimeWindow timeWindow = new TimeWindow(Range.newRange(from, to), DEFAULT_TIME_WINDOW_SAMPLER);
InspectorDataSearchKey inspectorDataSearchKey = new InspectorDataSearchKey(tenantId, applicationName, InspectorDataSearchKey.UNKNOWN_NAME, metricDefinitionId, timeWindow);

InspectorMetricData inspectorMetricData = applicationStatService.selectApplicationStat(inspectorDataSearchKey, timeWindow);
return new InspectorMetricView(inspectorMetricData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import com.navercorp.pinpoint.inspector.web.model.InspectorDataSearchKey;
import com.navercorp.pinpoint.inspector.web.model.TagInformation;
import com.navercorp.pinpoint.metric.common.model.Tag;
import com.navercorp.pinpoint.metric.web.model.chart.SystemMetricPoint;
import com.navercorp.pinpoint.metric.common.util.SystemMetricPoint;


import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
*
* * Copyright 2024 NAVER Corp.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*
*/

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

import com.navercorp.pinpoint.inspector.web.definition.metric.field.Field;
import com.navercorp.pinpoint.inspector.web.model.InspectorDataSearchKey;
import com.navercorp.pinpoint.metric.common.model.chart.AvgMinMaxMetricPoint;

import java.util.List;
import java.util.concurrent.Future;

/**
* @author minwoo-jung
*/
public interface ApplicationStatDao {
Future<List<AvgMinMaxMetricPoint<Double>>> selectAgentStatAvgMinMax(InspectorDataSearchKey inspectorDataSearchKey, String metricName, Field field);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

package com.navercorp.pinpoint.inspector.web.dao.model;

import com.navercorp.pinpoint.common.util.ObjectUtils;
import com.navercorp.pinpoint.inspector.web.model.InspectorDataSearchKey;
import com.navercorp.pinpoint.metric.common.model.Range;
import com.navercorp.pinpoint.metric.common.model.Tag;
import com.navercorp.pinpoint.metric.web.util.Range;
import com.navercorp.pinpoint.metric.web.util.TimePrecision;

import java.util.Collections;
Expand All @@ -33,6 +32,7 @@
public class InspectorQueryParameter {

private final String tenantId;
private final String applicationName;
private final String agentId;
private final String metricName;
private final String fieldName;
Expand All @@ -50,6 +50,7 @@ public InspectorQueryParameter(InspectorDataSearchKey inspectorDataSearchKey, St
Objects.requireNonNull(inspectorDataSearchKey, "inspectorDataSearchKey");

this.tenantId = inspectorDataSearchKey.getTenantId();
this.applicationName = inspectorDataSearchKey.getApplicationName();
this.agentId = inspectorDataSearchKey.getAgentId();
this.metricName = metricName;
this.fieldName = fieldName;
Expand Down Expand Up @@ -90,4 +91,8 @@ public TimePrecision getTimePrecision() {
public long getLimit() {
return limit;
}

public String getApplicationName() {
return applicationName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import com.navercorp.pinpoint.inspector.web.model.InspectorDataSearchKey;
import com.navercorp.pinpoint.inspector.web.model.TagInformation;
import com.navercorp.pinpoint.metric.common.model.Tag;
import com.navercorp.pinpoint.metric.web.model.chart.SystemMetricPoint;
import com.navercorp.pinpoint.metric.common.util.SystemMetricPoint;
import com.navercorp.pinpoint.pinot.mybatis.PinotAsyncTemplate;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Future;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
*
* * Copyright 2024 NAVER Corp.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*
*/

package com.navercorp.pinpoint.inspector.web.dao.pinot;

import com.navercorp.pinpoint.inspector.web.dao.ApplicationStatDao;
import com.navercorp.pinpoint.inspector.web.dao.model.InspectorQueryParameter;
import com.navercorp.pinpoint.inspector.web.definition.metric.field.Field;
import com.navercorp.pinpoint.inspector.web.model.InspectorDataSearchKey;
import com.navercorp.pinpoint.metric.common.model.chart.AvgMinMaxMetricPoint;
import com.navercorp.pinpoint.pinot.mybatis.PinotAsyncTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.Future;

/**
* @author minwoo-jung
*/
@Repository
public class PinotApplicationStatDao implements ApplicationStatDao {

private static final String NAMESPACE = PinotApplicationStatDao.class.getName() + ".";
private final PinotAsyncTemplate asyncTemplate;

public PinotApplicationStatDao(@Qualifier("inspectorPinotAsyncTemplate") PinotAsyncTemplate asyncTemplate) {
this.asyncTemplate = Objects.requireNonNull(asyncTemplate, "asyncTemplate");
}

@Override
public Future<List<AvgMinMaxMetricPoint<Double>>> selectAgentStatAvgMinMax(InspectorDataSearchKey inspectorDataSearchKey, String metricName, Field field) {
InspectorQueryParameter inspectorQueryParameter = new InspectorQueryParameter(inspectorDataSearchKey, metricName, field.getFieldName());
return asyncTemplate.selectList(NAMESPACE + "selectInspectorAvgMinMaxData", inspectorQueryParameter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public enum AggregationFunction {
AVG(1, "avg"),
SUM(2, "sum"),
MAX(2, "max"),

AVG_MIN_MAX(300, "avg_min_max"),

UNKNOWN(999, "unknown");

private final int code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
/**
* @author minwoo.jung
*/
@Component
// TODO : (minwoo) It seems that it can be integrated with the metric's com.navercorp.pinpoint.metric.web.service.YMLSystemMetricBasic GroupManager.
public class YMLInspectorManager {

public static final String DEFINITION_YML = "classpath:/inspector/web/inspector-definition.yml";
public static final String AGENT_DEFINITION_YML_PATH = "classpath:/inspector/web/inspector-definition-for-agent.yml";
public static final String APPLICATION_DEFINITION_YML_PATH = "classpath:/inspector/web/inspector-definition-for-application.yml";
private final Map<String, MetricDefinition> definitionIdMap;
private final Map<String, List<String>> metricIdMap;
private final Comparator<MetricInfo> metricInfoComparator;
Expand Down
Loading

0 comments on commit 281dff9

Please sign in to comment.