Skip to content

Commit

Permalink
[#10776] Add the field concept to the metric definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed Aug 8, 2024
1 parent 6ecf7bd commit 6925977
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

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

/**
Expand All @@ -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<String> 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<String> 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");
Expand Down Expand Up @@ -76,8 +77,8 @@ public String getMetricName() {
return metricName;
}

public String getFieldName() {
return fieldName;
public List<String> getFieldNameList() {
return fieldNameList;
}

public String getTags() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
/**
* @author minwoo-jung
*/
public record Tag(String tag, String unit) {
public record FieldAndUnit(String fieldName, String unit) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@
public class Metric {

private final String metricName;
private final Map<String, Tag> tagMap;
private final Map<String, TagCluster> 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<Tag> getTagList() {
public List<TagCluster> getTagClusterList() {
return List.copyOf(tagMap.values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FieldAndUnit> 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<FieldAndUnit> getFieldAndUnitList() {
return fieldAndUnitList;
}

public String getTags() {
return tag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,23 @@ public OpenTelemetryMetricController(OtlpMetricWebService otlpMetricWebService,
tenantId = tenantProvider.getTenantId();
}


@Deprecated
@GetMapping("/metricGroups")
public List<String> 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<String> getMetricGroups(@RequestParam("applicationId") @NotBlank String applicationId,
@RequestParam(value = "agentId", required = false) String agentId,
@RequestParam("metricGroupName") @NotBlank String metricGroupName) {
return otlpMetricWebService.getMetricList(tenantId, DEFAULT_SERVICE_ID, applicationId, agentId, metricGroupName);
}

@Deprecated
@GetMapping("/tags")
public List<String> getTags(@RequestParam("applicationId") @NotBlank String applicationId,
@RequestParam(value = "agentId", required = false) String agentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public List<AppMetricDefinition> selectAppMetricDefinitionList(String applicatio
@Override
public void updateAppMetricDefinitionList(List<AppMetricDefinition> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
'}';
}
}

0 comments on commit 6925977

Please sign in to comment.