diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/IgnoredArtifacts.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/IgnoredArtifacts.java index 5a1d1527ad..b2defe3d7a 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/IgnoredArtifacts.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/IgnoredArtifacts.java @@ -21,10 +21,15 @@ import org.keycloak.config.database.Database; import java.util.Collection; import java.util.HashSet; + +import org.keycloak.config.HealthOptions; +import org.keycloak.config.MetricsOptions; + import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import static java.util.Collections.emptySet; import static org.keycloak.quarkus.runtime.Environment.getCurrentOrCreateFeatureProfile; /** @@ -35,7 +40,9 @@ public class IgnoredArtifacts { public static Set getDefaultIgnoredArtifacts() { return Stream.of( fips(), - jdbcDrivers() + jdbcDrivers(), + health(), + metrics() ) .flatMap(Collection::stream) .collect(Collectors.toUnmodifiableSet()); @@ -130,4 +137,32 @@ public class IgnoredArtifacts { allJdbcDrivers.removeAll(jdbcArtifacts); return allJdbcDrivers; } + + // Health + public static final Set HEALTH = Set.of( + "io.quarkus:quarkus-smallrye-health", + "io.quarkus:quarkus-smallrye-health-deployment" + ); + + private static Set health() { + boolean isHealthEnabled = Configuration.getOptionalBooleanValue( + MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + HealthOptions.HEALTH_ENABLED.getKey()).orElse(false); + + return !isHealthEnabled ? HEALTH : emptySet(); + } + + // Metrics + public static Set METRICS = Set.of( + "io.quarkus:quarkus-micrometer", + "io.quarkus:quarkus-micrometer-deployment", + "io.quarkus:quarkus-micrometer-registry-prometheus", + "io.quarkus:quarkus-micrometer-registry-prometheus-deployment" + ); + + private static Set metrics() { + boolean isMetricsEnabled = Configuration.getOptionalBooleanValue( + MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + MetricsOptions.METRICS_ENABLED.getKey()).orElse(false); + + return !isMetricsEnabled ? METRICS : emptySet(); + } } diff --git a/quarkus/runtime/src/main/resources/application.properties b/quarkus/runtime/src/main/resources/application.properties index 53fa4d4c03..c369cf48d2 100644 --- a/quarkus/runtime/src/main/resources/application.properties +++ b/quarkus/runtime/src/main/resources/application.properties @@ -17,7 +17,7 @@ quarkus.datasource.health.enabled=false quarkus.micrometer.binder.http-server.enabled=false # Enables metrics from other extensions if metrics is enabled -quarkus.datasource.metrics.enabled=${quarkus.micrometer.enabled} +quarkus.datasource.metrics.enabled=${quarkus.micrometer.enabled:false} # Default transaction timeout quarkus.transaction-manager.default-transaction-timeout=300 diff --git a/quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/test/IgnoredArtifactsTest.java b/quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/test/IgnoredArtifactsTest.java index 35b3576946..072349fd80 100644 --- a/quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/test/IgnoredArtifactsTest.java +++ b/quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/test/IgnoredArtifactsTest.java @@ -22,6 +22,8 @@ import org.junit.Test; import org.keycloak.common.Profile; import org.keycloak.common.profile.PropertiesProfileConfigResolver; import org.keycloak.config.DatabaseOptions; +import org.keycloak.config.HealthOptions; +import org.keycloak.config.MetricsOptions; import org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts; import org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider; @@ -109,4 +111,34 @@ public class IgnoredArtifactsTest { System.setProperty(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + DatabaseOptions.DB.getKey(), ""); } } + + @Test + public void health() { + var ignoredArtifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts(); + // Health disabled by default + assertThat(ignoredArtifacts.containsAll(IgnoredArtifacts.HEALTH), is(true)); + + System.setProperty(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + HealthOptions.HEALTH_ENABLED.getKey(), "true"); + try { + final var artifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts(); + assertThat(artifacts.containsAll(IgnoredArtifacts.HEALTH), is(false)); + } finally { + System.setProperty(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + HealthOptions.HEALTH_ENABLED.getKey(), ""); + } + } + + @Test + public void metrics() { + var ignoredArtifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts(); + // Metrics disabled by default + assertThat(ignoredArtifacts.containsAll(IgnoredArtifacts.METRICS), is(true)); + + System.setProperty(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + MetricsOptions.METRICS_ENABLED.getKey(), "true"); + try { + final var artifacts = IgnoredArtifacts.getDefaultIgnoredArtifacts(); + assertThat(artifacts.containsAll(IgnoredArtifacts.METRICS), is(false)); + } finally { + System.setProperty(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + HealthOptions.HEALTH_ENABLED.getKey(), ""); + } + } }