From 692597788b8e848371c6b1ad27dc0d6f8e932de8 Mon Sep 17 00:00:00 2001 From: "minwoo.jung" Date: Thu, 8 Aug 2024 13:09:34 +0900 Subject: [PATCH] [#10776] Add the field concept to the metric definition. --- .../common/defined/AppMetricDefinition.java | 11 +++-- .../property/{Tag.java => FieldAndUnit.java} | 2 +- .../common/definition/property/Metric.java | 9 ++-- .../definition/property/MetricGroup.java | 2 +- .../definition/property/TagCluster.java | 46 +++++++++++++++++++ .../OpenTelemetryMetricController.java | 4 ++ .../mysql/MysqlAppMetricDefinitionDao.java | 3 +- .../web/vo/OtlpMetricChartQueryParameter.java | 21 +++++++++ 8 files changed, 85 insertions(+), 13 deletions(-) rename otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/{Tag.java => FieldAndUnit.java} (92%) create mode 100644 otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/TagCluster.java diff --git a/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/defined/AppMetricDefinition.java b/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/defined/AppMetricDefinition.java index 5346f9d4e917..d5babeb58a08 100644 --- a/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/defined/AppMetricDefinition.java +++ b/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/defined/AppMetricDefinition.java @@ -18,6 +18,7 @@ import com.navercorp.pinpoint.common.server.util.StringPrecondition; +import java.util.List; import java.util.Objects; /** @@ -32,20 +33,20 @@ public class AppMetricDefinition { private final String title; private final String metricGroupName; private final String metricName; - private final String fieldName; private final String tags; + private final List fieldNameList; private final String unit; private final String chartType; private final Layout layout; - public AppMetricDefinition(String applicationName, String id, String title, String metricGroupName, String metricName, String fieldName, String tags, String unit, String chartType, Layout layout) { + public AppMetricDefinition(String applicationName, String id, String title, String metricGroupName, String metricName, List fieldNameList, String tags, String unit, String chartType, Layout layout) { this.applicationName = StringPrecondition.requireHasLength(applicationName, "applicationName"); this.id = id; this.title = StringPrecondition.requireHasLength(title, "title"); this.metricGroupName = StringPrecondition.requireHasLength(metricGroupName, "metricGroupName"); this.metricName = StringPrecondition.requireHasLength(metricName, "metricName"); - this.fieldName = ""; + this.fieldNameList = fieldNameList; this.tags = StringPrecondition.requireHasLength(tags, "tags"); this.unit = StringPrecondition.requireHasLength(unit, "unit"); this.chartType = StringPrecondition.requireHasLength(chartType, "chartType"); @@ -76,8 +77,8 @@ public String getMetricName() { return metricName; } - public String getFieldName() { - return fieldName; + public List getFieldNameList() { + return fieldNameList; } public String getTags() { diff --git a/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/Tag.java b/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/FieldAndUnit.java similarity index 92% rename from otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/Tag.java rename to otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/FieldAndUnit.java index 9c118d7f95b0..1498ed792340 100644 --- a/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/Tag.java +++ b/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/FieldAndUnit.java @@ -19,5 +19,5 @@ /** * @author minwoo-jung */ -public record Tag(String tag, String unit) { +public record FieldAndUnit(String fieldName, String unit) { } diff --git a/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/Metric.java b/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/Metric.java index 2407e87c602d..fd785caf611b 100644 --- a/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/Metric.java +++ b/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/Metric.java @@ -26,22 +26,23 @@ public class Metric { private final String metricName; - private final Map tagMap; + private final Map tagMap; public Metric(String metricName) { this.metricName = metricName; this.tagMap = new HashMap<>(); } - public void addTagAndUnit(String tag, String unit) { - tagMap.computeIfAbsent(tag, k -> new Tag(tag, unit)); + public void addTagAndUnit(String tag, String fieldName, String unit) { + TagCluster tagCluster = tagMap.computeIfAbsent(tag, k -> new TagCluster(tag)); + tagCluster.addFieldAndUnit(fieldName, unit); } public String getMetricName() { return metricName; } - public List getTagList() { + public List getTagClusterList() { return List.copyOf(tagMap.values()); } diff --git a/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/MetricGroup.java b/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/MetricGroup.java index b368d4aaf3e0..a2e86c578b50 100644 --- a/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/MetricGroup.java +++ b/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/MetricGroup.java @@ -35,7 +35,7 @@ public MetricGroup(String metricGroupName) { public void addUniqueMetric(MetricDescriptor metricDescriptor) { Metric metric = metricMap.computeIfAbsent(metricDescriptor.metricName(), k -> new Metric(metricDescriptor.metricName())); - metric.addTagAndUnit(metricDescriptor.rawTags(), metricDescriptor.unit()); + metric.addTagAndUnit(metricDescriptor.rawTags(), metricDescriptor.fieldName(), metricDescriptor.unit()); } public String getMetricGroupName() { diff --git a/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/TagCluster.java b/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/TagCluster.java new file mode 100644 index 000000000000..ebfbbd6a601c --- /dev/null +++ b/otlpmetric/otlpmetric-common/src/main/java/com/navercorp/pinpoint/otlp/common/definition/property/TagCluster.java @@ -0,0 +1,46 @@ +/* + * 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.otlp.common.definition.property; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author minwoo-jung + */ +public class TagCluster { + private final String tag; + private final List fieldAndUnitList; + + public TagCluster(String tag) { + this.tag = tag; + this.fieldAndUnitList = new ArrayList<>(); + } + + public void addFieldAndUnit(String fieldName, String unit) { + FieldAndUnit fieldAndUnit = new FieldAndUnit(fieldName, unit); + fieldAndUnitList.add(fieldAndUnit); + } + + public List getFieldAndUnitList() { + return fieldAndUnitList; + } + + public String getTags() { + return tag; + } +} diff --git a/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/controller/OpenTelemetryMetricController.java b/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/controller/OpenTelemetryMetricController.java index bf6f9dfdd9ba..ef7768f0c1b0 100644 --- a/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/controller/OpenTelemetryMetricController.java +++ b/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/controller/OpenTelemetryMetricController.java @@ -43,12 +43,15 @@ public OpenTelemetryMetricController(OtlpMetricWebService otlpMetricWebService, tenantId = tenantProvider.getTenantId(); } + + @Deprecated @GetMapping("/metricGroups") public List getMetricGroups(@RequestParam("applicationId") @NotBlank String applicationId, @RequestParam(value = "agentId", required = false) String agentId) { return otlpMetricWebService.getMetricGroupList(tenantId, DEFAULT_SERVICE_ID, applicationId, agentId); } + @Deprecated @GetMapping("/metrics") public List getMetricGroups(@RequestParam("applicationId") @NotBlank String applicationId, @RequestParam(value = "agentId", required = false) String agentId, @@ -56,6 +59,7 @@ public List getMetricGroups(@RequestParam("applicationId") @NotBlank Str return otlpMetricWebService.getMetricList(tenantId, DEFAULT_SERVICE_ID, applicationId, agentId, metricGroupName); } + @Deprecated @GetMapping("/tags") public List getTags(@RequestParam("applicationId") @NotBlank String applicationId, @RequestParam(value = "agentId", required = false) String agentId, diff --git a/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/dao/mysql/MysqlAppMetricDefinitionDao.java b/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/dao/mysql/MysqlAppMetricDefinitionDao.java index 0c6f7d738716..fb691a71584c 100644 --- a/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/dao/mysql/MysqlAppMetricDefinitionDao.java +++ b/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/dao/mysql/MysqlAppMetricDefinitionDao.java @@ -62,8 +62,7 @@ public List selectAppMetricDefinitionList(String applicatio @Override public void updateAppMetricDefinitionList(List appMetricDefinitionList) { AppMetricDefDto appMetricDefDto = mapper.toDto(appMetricDefinitionList); - int result = sqlSessionTemplate.update(NAMESPACE + "updateAppMetricDefinition", appMetricDefDto); - System.out.println("result = " + result); + sqlSessionTemplate.update(NAMESPACE + "updateAppMetricDefinition", appMetricDefDto); } static class Mapper { diff --git a/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/vo/OtlpMetricChartQueryParameter.java b/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/vo/OtlpMetricChartQueryParameter.java index bfac40dceecc..d7dcacf75b90 100644 --- a/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/vo/OtlpMetricChartQueryParameter.java +++ b/otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/vo/OtlpMetricChartQueryParameter.java @@ -135,4 +135,25 @@ public OtlpMetricChartQueryParameter build() { return new OtlpMetricChartQueryParameter(this); } } + + @Override + public String toString() { + return "OtlpMetricChartQueryParameter{" + + "serviceId='" + serviceId + '\'' + + ", applicationId='" + applicationId + '\'' + + ", agentId='" + agentId + '\'' + + ", metricGroupName='" + metricGroupName + '\'' + + ", metricName='" + metricName + '\'' + + ", fieldName='" + fieldName + '\'' + + ", tags=" + tags + + ", version='" + version + '\'' + + ", aggreFunc=" + aggreFunc + + ", dataType=" + dataType + + ", TimePrecision=" + timePrecision + + ", range=" + range.prettyToString() + + ", range(from)=" + range.getFrom() + + ", range(to)=" + range.getTo() + + ", limit=" + limit + + '}'; + } }