Skip to content

Commit

Permalink
[#10776] Clean up duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed Jun 25, 2024
1 parent dbe6170 commit 9d42ca4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -77,18 +74,18 @@ private void map(OtlpMetricData.Builder builder, Metric metric, Map<String, Stri
}

private void parseCommonTags(OtlpMetricData.Builder builder, Map<String, String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -67,7 +64,7 @@ public void save(OtlpMetricData otlpMetricData) {

List<String> 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());
Expand Down

0 comments on commit 9d42ca4

Please sign in to comment.