-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44016 from brunobat/micrometer-exemplars-on-http
Micrometer exemplars on HTTP
- Loading branch information
Showing
14 changed files
with
213 additions
and
13 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
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
2 changes: 1 addition & 1 deletion
2
.../export/EmptyExemplarSamplerProvider.java → ...emplars/EmptyExemplarSamplerProvider.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
16 changes: 16 additions & 0 deletions
16
...uarkus/micrometer/runtime/export/exemplars/NoopOpenTelemetryExemplarContextUnwrapper.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,16 @@ | ||
package io.quarkus.micrometer.runtime.export.exemplars; | ||
|
||
import java.util.function.Function; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
import io.vertx.core.Context; | ||
|
||
@Dependent | ||
public class NoopOpenTelemetryExemplarContextUnwrapper implements OpenTelemetryContextUnwrapper { | ||
|
||
@Override | ||
public <P, R> R executeInContext(Function<P, R> methodReference, P parameter, Context requestContext) { | ||
return methodReference.apply(parameter);// pass through | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...in/java/io/quarkus/micrometer/runtime/export/exemplars/OpenTelemetryContextUnwrapper.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,18 @@ | ||
package io.quarkus.micrometer.runtime.export.exemplars; | ||
|
||
import java.util.function.Function; | ||
|
||
public interface OpenTelemetryContextUnwrapper { | ||
/** | ||
* Called when an HTTP server response has ended. | ||
* Makes sure exemplars are produced because they have an OTel context. | ||
* | ||
* @param methodReference Ex: Sample stop method reference | ||
* @param parameter The parameter to pass to the method | ||
* @param requestContext The request context | ||
* @param <P> The parameter type is a type of metric, ex: Timer | ||
* @param <R> The return type of the method pointed by the methodReference | ||
* @return The result of the method | ||
*/ | ||
<P, R> R executeInContext(Function<P, R> methodReference, P parameter, io.vertx.core.Context requestContext); | ||
} |
31 changes: 31 additions & 0 deletions
31
...io/quarkus/micrometer/runtime/export/exemplars/OpenTelemetryExemplarContextUnwrapper.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,31 @@ | ||
package io.quarkus.micrometer.runtime.export.exemplars; | ||
|
||
import java.util.function.Function; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.quarkus.opentelemetry.runtime.QuarkusContextStorage; | ||
|
||
@Dependent | ||
public class OpenTelemetryExemplarContextUnwrapper implements OpenTelemetryContextUnwrapper { | ||
|
||
@Override | ||
public <P, R> R executeInContext(Function<P, R> methodReference, P parameter, io.vertx.core.Context requestContext) { | ||
if (requestContext == null) { | ||
return methodReference.apply(parameter); | ||
} | ||
|
||
Context newContext = QuarkusContextStorage.getContext(requestContext); | ||
|
||
if (newContext == null) { | ||
return methodReference.apply(parameter); | ||
} | ||
|
||
io.opentelemetry.context.Context oldContext = QuarkusContextStorage.INSTANCE.current(); | ||
try (Scope scope = QuarkusContextStorage.INSTANCE.attach(newContext)) { | ||
return methodReference.apply(parameter); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...OpentelemetryExemplarSamplerProvider.java → ...OpentelemetryExemplarSamplerProvider.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
34 changes: 34 additions & 0 deletions
34
...rometer-prometheus/src/test/java/io/quarkus/it/micrometer/prometheus/ExemplarOffTest.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,34 @@ | ||
package io.quarkus.it.micrometer.prometheus; | ||
|
||
import static io.restassured.RestAssured.get; | ||
import static io.restassured.RestAssured.when; | ||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.awaitility.Awaitility.await; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
/** | ||
* See Micrometer Guide | ||
*/ | ||
@QuarkusTest | ||
@TestProfile(OtelOffProfile.class) | ||
public class ExemplarOffTest { | ||
|
||
@Test | ||
void testExemplar() { | ||
when().get("/example/prime/257").then().statusCode(200); | ||
when().get("/example/prime/7919").then().statusCode(200); | ||
|
||
String metricMatch = "http_server_requests_seconds_count{dummy=\"value\",env=\"test\"," + | ||
"env2=\"test\",foo=\"UNSET\",method=\"GET\",outcome=\"SUCCESS\"," + | ||
"registry=\"prometheus\",status=\"200\",uri=\"/example/prime/{number}\"} 2.0 # {span_id=\""; | ||
|
||
await().atMost(5, SECONDS).untilAsserted(() -> { | ||
assertFalse(get("/q/metrics").then().extract().asString().contains(metricMatch)); | ||
}); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...micrometer-prometheus/src/test/java/io/quarkus/it/micrometer/prometheus/ExemplarTest.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,35 @@ | ||
package io.quarkus.it.micrometer.prometheus; | ||
|
||
import static io.restassured.RestAssured.get; | ||
import static io.restassured.RestAssured.when; | ||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.awaitility.Awaitility.await; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
/** | ||
* See Micrometer Guide | ||
*/ | ||
@QuarkusTest | ||
@TestProfile(OtelOnProfile.class) | ||
public class ExemplarTest { | ||
|
||
@Test | ||
void testExemplar() { | ||
when().get("/example/prime/257").then().statusCode(200); | ||
when().get("/example/prime/7919").then().statusCode(200); | ||
|
||
String metricMatch = "http_server_requests_seconds_count{dummy=\"value\",env=\"test\"," + | ||
"env2=\"test\",foo=\"UNSET\",method=\"GET\",outcome=\"SUCCESS\"," + | ||
"registry=\"prometheus\",status=\"200\",uri=\"/example/prime/{number}\"} 2.0 # {span_id=\""; | ||
|
||
await().atMost(5, SECONDS).untilAsserted(() -> { | ||
String body = get("/q/metrics").then().extract().asString(); | ||
assertTrue(body.contains(metricMatch), body); | ||
}); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...crometer-prometheus/src/test/java/io/quarkus/it/micrometer/prometheus/OtelOffProfile.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,16 @@ | ||
package io.quarkus.it.micrometer.prometheus; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
|
||
public class OtelOffProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
Map<String, String> config = new HashMap<>(Map.of( | ||
"quarkus.otel.enabled", "false")); | ||
return config; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...icrometer-prometheus/src/test/java/io/quarkus/it/micrometer/prometheus/OtelOnProfile.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,16 @@ | ||
package io.quarkus.it.micrometer.prometheus; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
|
||
public class OtelOnProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
Map<String, String> config = new HashMap<>(Map.of( | ||
"quarkus.otel.enabled", "true")); | ||
return config; | ||
} | ||
} |