Skip to content

Commit

Permalink
Optimize OTEL metrics attributes KV convert. (#12152)
Browse files Browse the repository at this point in the history
  • Loading branch information
yswdqz authored Apr 24, 2024
1 parent 86155be commit 2d6bc69
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/en/changes/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
* MQE labeled metrics Binary Operation: return empty value if the labels not match rather than report error.
* Fix inaccurate Hierarchy of RabbitMQ Server monitoring metrics.
* Fix inaccurate MySQL/MariaDB, Redis, PostgreSQL metrics.
* Support DoubleValue,IntValue,BoolValue in OTEL metrics attributes.

#### UI

Expand Down
2 changes: 2 additions & 0 deletions docs/en/setup/backend/opentelemetry-receiver.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ The receiver adds label with key `node_identifier_host_name` to the collected da
and its value is from `net.host.name` (or `host.name` for some OTLP versions) resource attributes defined in OpenTelemetry proto,
for identification of the metric data.

**Notice:** In the resource scope, dots (.) in the attributes' key names are converted to underscores (_), whereas in the metrics scope, they are not converted.

| Description | Configuration File | Data Source |
|-----------------------------------------|-----------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| Metrics of Istio Control Plane | otel-rules/istio-controlplane.yaml | Istio Control Plane -> OpenTelemetry Collector -- OTLP exporter --> SkyWalking OAP Server |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest;
import io.opentelemetry.proto.common.v1.AnyValue;
import io.opentelemetry.proto.common.v1.KeyValue;
import io.opentelemetry.proto.metrics.v1.Sum;
import io.opentelemetry.proto.metrics.v1.SummaryDataPoint;
Expand Down Expand Up @@ -87,7 +88,7 @@ public void processMetricsRequest(final ExportMetricsServiceRequest requests) {
it -> LABEL_MAPPINGS
.getOrDefault(it.getKey(), it.getKey())
.replaceAll("\\.", "_"),
it -> it.getValue().getStringValue(),
it -> anyValueToString(it.getValue()),
(v1, v2) -> v1
));

Expand Down Expand Up @@ -136,7 +137,7 @@ private static Map<String, String> buildLabels(List<KeyValue> kvs) {
.stream()
.collect(toMap(
KeyValue::getKey,
it -> it.getValue().getStringValue()
it -> anyValueToString(it.getValue())
));
}

Expand Down Expand Up @@ -334,4 +335,17 @@ private Stream<? extends Metric> adaptMetrics(
}
throw new UnsupportedOperationException("Unsupported type");
}

public static String anyValueToString(AnyValue value) {
if (value.hasBoolValue()) {
return Boolean.toString(value.getBoolValue());
} else if (value.hasIntValue()) {
return Long.toString(value.getIntValue());
} else if (value.hasDoubleValue()) {
return Double.toString(value.getDoubleValue());
} else {
return value.getStringValue();
}
}

}

0 comments on commit 2d6bc69

Please sign in to comment.