Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start the conversion to @ConfigMapping (micrometer) #45820

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions extensions/micrometer/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
3 changes: 0 additions & 3 deletions extensions/micrometer/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MicrometerMetricsFactory(MicrometerConfig config, MeterRegistry globalReg
@Override
public boolean metricsSystemSupported(String name) {
return MetricsFactory.MICROMETER.equals(name) ||
(MetricsFactory.MP_METRICS.equals(name) && config.binder.mpMetrics.enabled.orElse(false));
(MetricsFactory.MP_METRICS.equals(name) && config.binder().mpMetrics().enabled.orElse(false));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void configureRegistries(MicrometerConfig config,
List<AutoCloseable> autoCloseables = new ArrayList<>();

// Base JVM Metrics
if (config.checkBinderEnabledWithDefault(() -> config.binder.jvm)) {
if (config.checkBinderEnabledWithDefault(() -> config.binder().jvm())) {
new ClassLoaderMetrics().bindTo(Metrics.globalRegistry);
JvmHeapPressureMetrics jvmHeapPressureMetrics = new JvmHeapPressureMetrics();
jvmHeapPressureMetrics.bindTo(Metrics.globalRegistry);
Expand All @@ -131,7 +131,7 @@ public void configureRegistries(MicrometerConfig config,
}

// System metrics
if (config.checkBinderEnabledWithDefault(() -> config.binder.system)) {
if (config.checkBinderEnabledWithDefault(() -> config.binder().system())) {
new UptimeMetrics().bindTo(Metrics.globalRegistry);
new ProcessorMetrics().bindTo(Metrics.globalRegistry);
new FileDescriptorMetrics().bindTo(Metrics.globalRegistry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ public HttpBinderConfiguration(boolean httpServerMetrics, boolean httpClientMetr

serverEnabled = httpServerMetrics;
clientEnabled = httpClientMetrics;
serverSuppress4xxErrors = serverConfig.suppress4xxErrors;
clientSuppress4xxErrors = clientConfig.suppress4xxErrors;
serverSuppress4xxErrors = serverConfig.suppress4xxErrors();
clientSuppress4xxErrors = clientConfig.suppress4xxErrors();

if (serverEnabled) {
Pattern defaultIgnore = null;
String defaultMatch = null;

if (MicrometerRecorder.httpRootUri.equals(MicrometerRecorder.nonApplicationUri)) {
// we can't set the default ignore in this case, as the paths overlap
} else if (serverConfig.suppressNonApplicationUris) {
} else if (serverConfig.suppressNonApplicationUris()) {
defaultIgnore = Pattern.compile(MicrometerRecorder.nonApplicationUri + ".*");
}

Expand All @@ -72,16 +72,16 @@ public HttpBinderConfiguration(boolean httpServerMetrics, boolean httpClientMetr

// Handle deprecated/previous vertx properties as well
serverIgnorePatterns = getIgnorePatterns(
serverConfig.ignorePatterns.isPresent() ? serverConfig.ignorePatterns : vertxConfig.ignorePatterns,
serverConfig.ignorePatterns().isPresent() ? serverConfig.ignorePatterns() : vertxConfig.ignorePatterns(),
defaultIgnore);
serverMatchPatterns = getMatchPatterns(
serverConfig.matchPatterns.isPresent() ? serverConfig.matchPatterns : vertxConfig.matchPatterns,
serverConfig.matchPatterns().isPresent() ? serverConfig.matchPatterns() : vertxConfig.matchPatterns(),
defaultMatch);
}

if (clientEnabled) {
clientIgnorePatterns = getIgnorePatterns(clientConfig.ignorePatterns, null);
clientMatchPatterns = getMatchPatterns(clientConfig.matchPatterns, null);
clientIgnorePatterns = getIgnorePatterns(clientConfig.ignorePatterns(), null);
clientMatchPatterns = getMatchPatterns(clientConfig.matchPatterns(), null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class HttpMeterFilterProvider {
public MeterFilter metricsHttpClientUriTagFilter(HttpClientConfig httpClientConfig) {
if (binderConfiguration.isClientEnabled()) {
return maximumAllowableUriTagsFilter(binderConfiguration.getHttpClientRequestsName(),
httpClientConfig.maxUriTags);
httpClientConfig.maxUriTags());
}
return null;
}
Expand All @@ -32,7 +32,7 @@ public MeterFilter metricsHttpClientUriTagFilter(HttpClientConfig httpClientConf
public MeterFilter metricsHttpServerUriTagFilter(HttpServerConfig httpServerConfig) {
if (binderConfiguration.isServerEnabled()) {
return maximumAllowableUriTagsFilter(binderConfiguration.getHttpServerRequestsName(),
httpServerConfig.maxUriTags);
httpServerConfig.maxUriTags().getAsInt());
}
return null;
}
Expand All @@ -42,7 +42,7 @@ public MeterFilter metricsHttpServerUriTagFilter(HttpServerConfig httpServerConf
public MeterFilter metricsHttpPushUriTagFilter(HttpServerConfig httpServerConfig) {
if (binderConfiguration.isServerEnabled()) {
return maximumAllowableUriTagsFilter(binderConfiguration.getHttpServerPushName(),
httpServerConfig.maxUriTags);
httpServerConfig.maxUriTags().getAsInt());
}
return null;
}
Expand All @@ -52,7 +52,7 @@ public MeterFilter metricsHttpPushUriTagFilter(HttpServerConfig httpServerConfig
public MeterFilter metricsHttpWebSocketsUriTagFilter(HttpServerConfig httpServerConfig) {
if (binderConfiguration.isServerEnabled()) {
return maximumAllowableUriTagsFilter(binderConfiguration.getHttpServerWebSocketConnectionsName(),
httpServerConfig.maxUriTags);
httpServerConfig.maxUriTags().getAsInt());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class VirtualThreadCollector {

@Inject
public VirtualThreadCollector(MicrometerConfig mc) {
var config = mc.binder.virtualThreads;
var config = mc.binder().virtualThreads();
this.enabled = JavaVersionUtil.isJava21OrHigher() && config.enabled.orElse(true);
MeterBinder instantiated = null;
if (enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,59 @@
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

/**
* Global configuration for the Micrometer extension
*/
@ConfigRoot(name = "micrometer", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public final class MicrometerConfig {
@ConfigMapping(prefix = "quarkus.micrometer")
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public interface MicrometerConfig {

/**
* Micrometer metrics support.
* <p>
* Micrometer metrics support is enabled by default.
*/
@ConfigItem(defaultValue = "true")
public boolean enabled;
@WithDefault("true")
boolean enabled();

/**
* Micrometer MeterRegistry discovery.
* <p>
* Micrometer MeterRegistry implementations discovered on the classpath
* will be enabled automatically by default.
*/
@ConfigItem(defaultValue = "true")
public boolean registryEnabledDefault;
@WithDefault("true")
boolean registryEnabledDefault();

/**
* Micrometer MeterBinder discovery.
* <p>
* Micrometer MeterBinder implementations discovered on the classpath
* will be enabled automatically by default.
*/
@ConfigItem(defaultValue = "true")
public boolean binderEnabledDefault;
@WithDefault("true")
boolean binderEnabledDefault();

/** Build / static runtime config for binders */
public BinderConfig binder;
BinderConfig binder();

/** Build / static runtime config for exporters */
public ExportConfig export;
ExportConfig export();

/**
* For MeterRegistry configurations with optional 'enabled' attributes,
* determine whether the registry is enabled using {@link #registryEnabledDefault}
* as the default value.
*/
public boolean checkRegistryEnabledWithDefault(CapabilityEnabled config) {
if (enabled) {
default boolean checkRegistryEnabledWithDefault(CapabilityEnabled config) {
if (enabled()) {
Optional<Boolean> configValue = config.getEnabled();
return configValue.orElseGet(() -> registryEnabledDefault);
return configValue.orElseGet(this::registryEnabledDefault);
}
return false;
}
Expand All @@ -63,28 +65,20 @@ public boolean checkRegistryEnabledWithDefault(CapabilityEnabled config) {
* determine whether the binder is enabled using {@link #binderEnabledDefault}
* as the default value.
*/
public boolean checkBinderEnabledWithDefault(CapabilityEnabled config) {
if (enabled) {
default boolean checkBinderEnabledWithDefault(CapabilityEnabled config) {
if (enabled()) {
Optional<Boolean> configValue = config.getEnabled();
return configValue.orElseGet(() -> binderEnabledDefault);
return configValue.orElseGet(this::binderEnabledDefault);
}
return false;
}

@Override
public String toString() {
return this.getClass().getSimpleName()
+ "{enabled=" + enabled
+ ",binderEnabledDefault=" + binderEnabledDefault
+ ",registryEnabledDefault=" + registryEnabledDefault
+ '}';
}

/** Build / static runtime config for binders */
@ConfigGroup
public static class BinderConfig {
public HttpClientConfigGroup httpClient;
public HttpServerConfigGroup httpServer;
interface BinderConfig {
HttpClientConfigGroup httpClient();

HttpServerConfigGroup httpServer();

/**
* Micrometer JVM metrics support.
Expand All @@ -93,23 +87,23 @@ public static class BinderConfig {
* support is enabled, and either this value is true, or this
* value is unset and {@code quarkus.micrometer.binder-enabled-default} is true.
*/
@ConfigItem
public Optional<Boolean> jvm;
Optional<Boolean> jvm();

public KafkaConfigGroup kafka;
KafkaConfigGroup kafka();

public RedisConfigGroup redis;
public StorkConfigGroup stork;
RedisConfigGroup redis();

public GrpcServerConfigGroup grpcServer;
StorkConfigGroup stork();

public GrpcClientConfigGroup grpcClient;
GrpcServerConfigGroup grpcServer();

public ReactiveMessagingConfigGroup messaging;
GrpcClientConfigGroup grpcClient();

public MPMetricsConfigGroup mpMetrics;
ReactiveMessagingConfigGroup messaging();

public VirtualThreadsConfigGroup virtualThreads;
MPMetricsConfigGroup mpMetrics();

VirtualThreadsConfigGroup virtualThreads();

/**
* Micrometer System metrics support.
Expand All @@ -118,22 +112,22 @@ public static class BinderConfig {
* support is enabled, and either this value is true, or this
* value is unset and {@code quarkus.micrometer.binder-enabled-default} is true.
*/
@ConfigItem
public Optional<Boolean> system;
Optional<Boolean> system();

public VertxConfigGroup vertx;
VertxConfigGroup vertx();

public NettyConfigGroup netty;
NettyConfigGroup netty();
}

/** Build / static runtime config for exporters */
@ConfigGroup
public static class ExportConfig {
public JsonConfigGroup json;
public PrometheusConfigGroup prometheus;
interface ExportConfig {
JsonConfigGroup json();

PrometheusConfigGroup prometheus();
}

public interface CapabilityEnabled {
interface CapabilityEnabled {
Optional<Boolean> getEnabled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import java.util.List;
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigRoot(name = "micrometer.binder.http-client", phase = ConfigPhase.RUN_TIME)
public class HttpClientConfig {
@ConfigMapping(prefix = "quarkus.micrometer.binder.http-client")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface HttpClientConfig {
/**
* Comma-separated list of regular expressions used to specify uri
* labels in http metrics.
Expand All @@ -28,15 +30,13 @@ public class HttpClientConfig {
*
* @asciidoclet
*/
@ConfigItem
public Optional<List<String>> matchPatterns = Optional.empty();
Optional<List<String>> matchPatterns();

/**
* Comma-separated list of regular expressions defining uri paths
* that should be ignored (not measured).
*/
@ConfigItem
public Optional<List<String>> ignorePatterns = Optional.empty();
Optional<List<String>> ignorePatterns();

/**
* Suppress 4xx errors from metrics collection for unmatched templates.
Expand All @@ -46,14 +46,14 @@ public class HttpClientConfig {
*
* @asciidoclet
*/
@ConfigItem(defaultValue = "false")
public boolean suppress4xxErrors;
@WithDefault("false")
boolean suppress4xxErrors();

/**
* Maximum number of unique URI tag values allowed. After the max number of
* tag values is reached, metrics with additional tag values are denied by
* filter.
*/
@ConfigItem(defaultValue = "100")
public int maxUriTags;
@WithDefault("100")
int maxUriTags();
}
Loading
Loading