-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement "Prometheus mode" for better micrometer->OTel->Prometheus s…
…upport (#5537) * Implement "Prometheus mode" for better micrometer->OTel->Prometheus support * code review comments * forgot about README
- Loading branch information
Mateusz Rzeszutek
authored
Mar 18, 2022
1 parent
e20f295
commit ab587a9
Showing
11 changed files
with
516 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...t/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/PrometheusModeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5; | ||
|
||
import io.opentelemetry.instrumentation.micrometer.v1_5.AbstractPrometheusModeTest; | ||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class PrometheusModeTest extends AbstractPrometheusModeTest { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
||
@Override | ||
protected InstrumentationExtension testing() { | ||
return testing; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...java/io/opentelemetry/instrumentation/micrometer/v1_5/PrometheusModeNamingConvention.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.micrometer.v1_5; | ||
|
||
import io.micrometer.core.instrument.Meter; | ||
import io.micrometer.core.instrument.config.NamingConvention; | ||
import javax.annotation.Nullable; | ||
|
||
// This naming strategy does not replace '.' with '_', and it does not append '_total' to counter | ||
// names - the reason behind it is that this is already done by the Prometheus exporter; see the | ||
// io.opentelemetry.exporter.prometheus.MetricAdapter class | ||
enum PrometheusModeNamingConvention implements NamingConvention { | ||
INSTANCE; | ||
|
||
@Override | ||
public String name(String name, Meter.Type type, @Nullable String baseUnit) { | ||
if (type == Meter.Type.COUNTER | ||
|| type == Meter.Type.DISTRIBUTION_SUMMARY | ||
|| type == Meter.Type.GAUGE) { | ||
if (baseUnit != null && !name.endsWith("." + baseUnit)) { | ||
name = name + "." + baseUnit; | ||
} | ||
} | ||
|
||
if (type == Meter.Type.LONG_TASK_TIMER || type == Meter.Type.TIMER) { | ||
if (!name.endsWith(".seconds")) { | ||
name = name + ".seconds"; | ||
} | ||
} | ||
|
||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ry/src/test/java/io/opentelemetry/instrumentation/micrometer/v1_5/PrometheusModeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.micrometer.v1_5; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Metrics; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class PrometheusModeTest extends AbstractPrometheusModeTest { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); | ||
|
||
static MeterRegistry otelMeterRegistry; | ||
|
||
@BeforeAll | ||
public static void setUpRegistry() { | ||
otelMeterRegistry = | ||
OpenTelemetryMeterRegistry.builder(testing.getOpenTelemetry()) | ||
.setPrometheusMode(true) | ||
.build(); | ||
Metrics.addRegistry(otelMeterRegistry); | ||
} | ||
|
||
@AfterAll | ||
public static void tearDownRegistry() { | ||
Metrics.removeRegistry(otelMeterRegistry); | ||
} | ||
|
||
@Override | ||
protected InstrumentationExtension testing() { | ||
return testing; | ||
} | ||
} |
Oops, something went wrong.