diff --git a/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/mapper/OtlpMetricMapper.java b/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/mapper/OtlpMetricMapper.java index 0194637a9143..142f1c140bb7 100644 --- a/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/mapper/OtlpMetricMapper.java +++ b/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/mapper/OtlpMetricMapper.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.otlp.collector.mapper; import com.navercorp.pinpoint.otlp.collector.model.OtlpMetricData; +import com.navercorp.pinpoint.otlp.collector.model.OtlpResourceAttributes; import com.navercorp.pinpoint.pinot.tenant.TenantProvider; import io.opentelemetry.proto.metrics.v1.Metric; import jakarta.validation.constraints.NotNull; @@ -29,10 +30,6 @@ @Component public class OtlpMetricMapper { - private static final String KEY_SERVICE_NAME = "service.name"; - private static final String KEY_SERVICE_NAMESPACE = "service.namespace"; - private static final String KEY_PINPOINT_AGENTID = "pinpoint.agentId"; - private static final String KEY_PINPOINT_METRIC_VERSION = "pinpoint.metric.version"; private final Logger logger = LogManager.getLogger(this.getClass()); private String tenantId = ""; @NotNull private final OtlpMetricDataMapper[] mappers; @@ -77,18 +74,18 @@ private void map(OtlpMetricData.Builder builder, Metric metric, Map commonTags) { - String serviceName = commonTags.get(KEY_SERVICE_NAME); + String serviceName = commonTags.get(OtlpResourceAttributes.KEY_SERVICE_NAME); if (serviceName == null) { throw new OtlpMappingException("Resource attribute `service.name` is required to save OTLP metrics to Pinpoint."); } builder.setServiceName(serviceName); - String agentId= commonTags.get(KEY_PINPOINT_AGENTID); + String agentId= commonTags.get(OtlpResourceAttributes.KEY_PINPOINT_AGENTID); if (agentId == null) { throw new OtlpMappingException("Resource attribute `pinpoint.agentId` is required to save OTLP metrics to Pinpoint"); } - String version = commonTags.get(KEY_PINPOINT_METRIC_VERSION); + String version = commonTags.get(OtlpResourceAttributes.KEY_PINPOINT_METRIC_VERSION); if (version != null) { builder.setVersion(version); } diff --git a/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/model/OtlpResourceAttributes.java b/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/model/OtlpResourceAttributes.java new file mode 100644 index 000000000000..d52b602b05cd --- /dev/null +++ b/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/model/OtlpResourceAttributes.java @@ -0,0 +1,11 @@ +package com.navercorp.pinpoint.otlp.collector.model; + +/** + * @author minwoo-jung + */ +public class OtlpResourceAttributes { + public static final String KEY_SERVICE_NAME = "service.name"; + public static final String KEY_SERVICE_NAMESPACE = "service.namespace"; + public static final String KEY_PINPOINT_AGENTID = "pinpoint.agentId"; + public static final String KEY_PINPOINT_METRIC_VERSION = "pinpoint.metric.version"; +} diff --git a/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/service/PinotOtlpMetricCollectorService.java b/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/service/PinotOtlpMetricCollectorService.java index 20339694a7c3..999a86a7893c 100644 --- a/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/service/PinotOtlpMetricCollectorService.java +++ b/otlpmetric/otlpmetric-collector/src/main/java/com/navercorp/pinpoint/otlp/collector/service/PinotOtlpMetricCollectorService.java @@ -32,9 +32,6 @@ @Service public class PinotOtlpMetricCollectorService implements OtlpMetricCollectorService { - private static final String KEY_SERVICE_NAME = "service.name"; - private static final String KEY_SERVICE_NAMESPACE = "service.namespace"; - private static final String KEY_PINPOINT_AGENTID = "pinpoint.agentid"; private final Logger logger = LogManager.getLogger(this.getClass()); @NotNull private final OtlpMetricDao otlpMetricDao; @@ -67,7 +64,7 @@ public void save(OtlpMetricData otlpMetricData) { List tagList = tags.entrySet().stream().filter((e) -> { String key = e.getKey().toLowerCase(); - return (!key.equals(KEY_SERVICE_NAME) && !key.equals(KEY_SERVICE_NAMESPACE) && !key.equals(KEY_PINPOINT_AGENTID)); + return (!key.equals(OtlpResourceAttributes.KEY_SERVICE_NAME) && !key.equals(OtlpResourceAttributes.KEY_SERVICE_NAMESPACE) && !key.equals(OtlpResourceAttributes.KEY_PINPOINT_AGENTID)); }).map((e) -> { return e.getKey() + ":" + e.getValue(); }).collect(Collectors.toList());