Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…y-java into prometheus-endoint
  • Loading branch information
jack-berg committed May 29, 2024
2 parents c7e1219 + 0f99d70 commit a2f71a6
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
9 changes: 8 additions & 1 deletion buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ base {
}
}

// normalize timestamps and file ordering in jars, making the outputs reproducible
// see open-telemetry/opentelemetry-java#4488
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
Expand All @@ -35,7 +42,7 @@ java {

checkstyle {
configDirectory.set(file("$rootDir/buildscripts/"))
toolVersion = "10.16.0"
toolVersion = "10.17.0"
isIgnoreFailures = false
configProperties["rootDir"] = rootDir
}
Expand Down
4 changes: 2 additions & 2 deletions dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ val DEPENDENCY_BOMS = listOf(
"io.netty:netty-bom:4.1.110.Final",
"io.zipkin.brave:brave-bom:6.0.3",
"io.zipkin.reporter2:zipkin-reporter-bom:3.4.0",
"org.assertj:assertj-bom:3.25.3",
"org.assertj:assertj-bom:3.26.0",
"org.junit:junit-bom:5.10.2",
"org.testcontainers:testcontainers-bom:1.19.8",
"org.snakeyaml:snakeyaml-engine:2.7"
Expand Down Expand Up @@ -70,7 +70,7 @@ val DEPENDENCIES = listOf(
"io.opentelemetry.proto:opentelemetry-proto:1.2.0-alpha",
"io.opentracing:opentracing-api:0.33.0",
"io.opentracing:opentracing-noop:0.33.0",
"io.prometheus:prometheus-metrics-exporter-httpserver:1.2.1",
"io.prometheus:prometheus-metrics-exporter-httpserver:1.3.1",
"junit:junit:4.13.2",
"nl.jqno.equalsverifier:equalsverifier:3.16.1",
"org.awaitility:awaitility:4.2.1",
Expand Down
2 changes: 0 additions & 2 deletions exporters/prometheus/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
plugins {
id("otel.java-conventions")
id("otel.publish-conventions")

id("otel.animalsniffer-conventions")
}

description = "OpenTelemetry Prometheus Exporter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ private static MetricMetadata convertMetadata(MetricData metricData) {
String help = metricData.getDescription();
Unit unit = PrometheusUnitsHelper.convertUnit(metricData.getUnit());
if (unit != null && !name.endsWith(unit.toString())) {
// Need to re-sanitize metric name since unit may contain illegal characters
name = sanitizeMetricName(name + "_" + unit);
name = name + "_" + unit;
}
// Repeated __ are not allowed according to spec, although this is allowed in prometheus
while (name.contains("__")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.sun.net.httpserver.HttpHandler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.export.MemoryMode;
import io.opentelemetry.sdk.internal.DaemonThreadFactory;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.export.CollectionRegistration;
Expand Down Expand Up @@ -76,7 +77,8 @@ public static PrometheusHttpServerBuilder builder() {
// we configure prometheus with a single thread executor such that requests are handled
// sequentially.
if (memoryMode == MemoryMode.REUSABLE_DATA) {
executor = Executors.newSingleThreadExecutor();
executor =
Executors.newSingleThreadExecutor(new DaemonThreadFactory("prometheus-http-server"));
}
try {
this.httpServer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.exporter.prometheus;

import io.prometheus.metrics.model.snapshots.PrometheusNaming;
import io.prometheus.metrics.model.snapshots.Unit;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -86,11 +87,22 @@ static Unit convertUnit(String otelUnit) {
String part1 = pluralNames.getOrDefault(parts[0], parts[0]).trim();
String part2 = singularNames.getOrDefault(parts[1], parts[1]).trim();
if (part1.isEmpty()) {
return new Unit("per_" + part2);
return unitOrNull("per_" + part2);
} else {
return new Unit(part1 + "_per_" + part2);
return unitOrNull(part1 + "_per_" + part2);
}
}
return new Unit(otelUnit);
return unitOrNull(otelUnit);
}

@Nullable
private static Unit unitOrNull(String name) {
try {
return new Unit(PrometheusNaming.sanitizeUnitName(name));
} catch (IllegalArgumentException e) {
// This happens if the name cannot be converted to a valid Prometheus unit name,
// for example if name is "total".
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ private static Stream<Arguments> metricMetadataArgs() {
// if metric name ends with unit the unit is omitted - order matters
Arguments.of(
createSampleMetricData("metric_total_hertz", "hertz_total", MetricDataType.LONG_SUM),
"metric_total_hertz_hertz_total counter",
"metric_total_hertz_hertz_total description",
"metric_total_hertz_hertz_total"),
"metric_total_hertz_total counter",
"metric_total_hertz_total description",
"metric_total_hertz_total"),
// metric name cannot start with a number
Arguments.of(
createSampleMetricData("2_metric_name", "By", MetricDataType.SUMMARY),
Expand Down

0 comments on commit a2f71a6

Please sign in to comment.