forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a way to provide custom micrometer metrics tags
Closes: quarkusio#33313
- Loading branch information
Showing
6 changed files
with
132 additions
and
9 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
24 changes: 24 additions & 0 deletions
24
...runtime/src/main/java/io/quarkus/micrometer/runtime/HttpServerMetricsTagsContributor.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,24 @@ | ||
package io.quarkus.micrometer.runtime; | ||
|
||
import io.micrometer.core.instrument.Tags; | ||
import io.micrometer.core.instrument.config.MeterFilter; | ||
import io.vertx.core.http.HttpServerRequest; | ||
|
||
/** | ||
* Allows code to add additional Micrometer {@link Tags} to the metrics collected for completed HTTP server requests. | ||
* <p> | ||
* The implementations of this interface are meant to be registered via CDI beans. | ||
* | ||
* @see MeterFilter for a more advanced and feature complete way of interacting with {@link Tags} | ||
*/ | ||
public interface HttpServerMetricsTagsContributor { | ||
|
||
/** | ||
* Called when Vert.x http server response has ended | ||
*/ | ||
Tags contribute(Context context); | ||
|
||
interface Context { | ||
HttpServerRequest request(); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
integration-tests/micrometer-prometheus/src/main/java/io/quarkus/DummyTag.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,15 @@ | ||
package io.quarkus; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import io.micrometer.core.instrument.Tags; | ||
import io.quarkus.micrometer.runtime.HttpServerMetricsTagsContributor; | ||
|
||
@Singleton | ||
public class DummyTag implements HttpServerMetricsTagsContributor { | ||
|
||
@Override | ||
public Tags contribute(Context context) { | ||
return Tags.of("dummy", "value"); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
integration-tests/micrometer-prometheus/src/main/java/io/quarkus/HeaderTag.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,20 @@ | ||
package io.quarkus; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import io.micrometer.core.instrument.Tags; | ||
import io.quarkus.micrometer.runtime.HttpServerMetricsTagsContributor; | ||
|
||
@Singleton | ||
public class HeaderTag implements HttpServerMetricsTagsContributor { | ||
|
||
@Override | ||
public Tags contribute(Context context) { | ||
String headerValue = context.request().getHeader("Foo"); | ||
String value = "UNSET"; | ||
if ((headerValue != null) && !headerValue.isEmpty()) { | ||
value = headerValue; | ||
} | ||
return Tags.of("foo", value); | ||
} | ||
} |
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