-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 completely customize MeterRegistry
This is done via the new `MeterRegistryCustomizer` interface the implementations of which are meant to be registered as CDI beans. Closes: #32996
- Loading branch information
Showing
8 changed files
with
264 additions
and
80 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
31 changes: 31 additions & 0 deletions
31
...crometer/runtime/src/main/java/io/quarkus/micrometer/runtime/MeterRegistryCustomizer.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; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
|
||
/** | ||
* Meant to be implemented by a CDI bean that provides arbitrary customization for various {@link MeterRegistry} classes | ||
* registered by Quarkus. | ||
* <p> | ||
* Unless an implementation is annotated with {@link MeterRegistryCustomizerConstraint}, it will apply to all | ||
* {@link MeterRegistry} classes. | ||
*/ | ||
public interface MeterRegistryCustomizer extends Comparable<MeterRegistryCustomizer> { | ||
|
||
int MINIMUM_PRIORITY = Integer.MIN_VALUE; | ||
// we use this priority to give a chance to other customizers to override serializers / deserializers | ||
// that might have been added by the modules that Quarkus registers automatically | ||
// (Jackson will keep the last registered serializer / deserializer for a given type | ||
// if multiple are registered) | ||
int QUARKUS_CUSTOMIZER_PRIORITY = MINIMUM_PRIORITY + 100; | ||
int DEFAULT_PRIORITY = 0; | ||
|
||
void customize(MeterRegistry registry); | ||
|
||
default int priority() { | ||
return DEFAULT_PRIORITY; | ||
} | ||
|
||
default int compareTo(MeterRegistryCustomizer o) { | ||
return Integer.compare(o.priority(), priority()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...untime/src/main/java/io/quarkus/micrometer/runtime/MeterRegistryCustomizerConstraint.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,33 @@ | ||
package io.quarkus.micrometer.runtime; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Repeatable; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.enterprise.util.AnnotationLiteral; | ||
import jakarta.inject.Qualifier; | ||
|
||
@Qualifier | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER, ElementType.FIELD }) | ||
@Repeatable(MeterRegistryCustomizerConstraints.class) | ||
public @interface MeterRegistryCustomizerConstraint { | ||
Class<?> applyTo(); | ||
|
||
final class Literal extends AnnotationLiteral<MeterRegistryCustomizerConstraint> implements | ||
MeterRegistryCustomizerConstraint { | ||
private static final long serialVersionUID = 1L; | ||
private final Class<?> clazz; | ||
|
||
public Literal(Class<?> clazz) { | ||
this.clazz = clazz; | ||
} | ||
|
||
@Override | ||
public Class<?> applyTo() { | ||
return clazz; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ntime/src/main/java/io/quarkus/micrometer/runtime/MeterRegistryCustomizerConstraints.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,12 @@ | ||
package io.quarkus.micrometer.runtime; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER, ElementType.FIELD }) | ||
public @interface MeterRegistryCustomizerConstraints { | ||
MeterRegistryCustomizerConstraint[] 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
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
Oops, something went wrong.