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
121 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
18 changes: 18 additions & 0 deletions
18
.../src/main/java/io/quarkus/micrometer/runtime/AdditionalHttpServerMetricsTagsProvider.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; | ||
|
||
import io.micrometer.core.instrument.Tags; | ||
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. | ||
*/ | ||
public interface AdditionalHttpServerMetricsTagsProvider { | ||
|
||
Tags configure(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.AdditionalHttpServerMetricsTagsProvider; | ||
|
||
@Singleton | ||
public class DummyTag implements AdditionalHttpServerMetricsTagsProvider { | ||
|
||
@Override | ||
public Tags configure(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.AdditionalHttpServerMetricsTagsProvider; | ||
|
||
@Singleton | ||
public class HeaderTag implements AdditionalHttpServerMetricsTagsProvider { | ||
|
||
@Override | ||
public Tags configure(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