Ignore Health and Metrics artifacts (#22438)

Closes #22437

Signed-off-by: Martin Bartoš <mabartos@redhat.com>
This commit is contained in:
Martin Bartoš 2023-12-08 17:57:12 +01:00 committed by GitHub
parent f78c54fa42
commit 0a95159e07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 2 deletions

View file

@ -21,10 +21,15 @@ import org.keycloak.config.database.Database;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import org.keycloak.config.HealthOptions;
import org.keycloak.config.MetricsOptions;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static java.util.Collections.emptySet;
import static org.keycloak.quarkus.runtime.Environment.getCurrentOrCreateFeatureProfile; import static org.keycloak.quarkus.runtime.Environment.getCurrentOrCreateFeatureProfile;
/** /**
@ -35,7 +40,9 @@ public class IgnoredArtifacts {
public static Set<String> getDefaultIgnoredArtifacts() { public static Set<String> getDefaultIgnoredArtifacts() {
return Stream.of( return Stream.of(
fips(), fips(),
jdbcDrivers() jdbcDrivers(),
health(),
metrics()
) )
.flatMap(Collection::stream) .flatMap(Collection::stream)
.collect(Collectors.toUnmodifiableSet()); .collect(Collectors.toUnmodifiableSet());
@ -130,4 +137,32 @@ public class IgnoredArtifacts {
allJdbcDrivers.removeAll(jdbcArtifacts); allJdbcDrivers.removeAll(jdbcArtifacts);
return allJdbcDrivers; return allJdbcDrivers;
} }
// Health
public static final Set<String> HEALTH = Set.of(
"io.quarkus:quarkus-smallrye-health",
"io.quarkus:quarkus-smallrye-health-deployment"
);
private static Set<String> health() {
boolean isHealthEnabled = Configuration.getOptionalBooleanValue(
MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + HealthOptions.HEALTH_ENABLED.getKey()).orElse(false);
return !isHealthEnabled ? HEALTH : emptySet();
}
// Metrics
public static Set<String> 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<String> metrics() {
boolean isMetricsEnabled = Configuration.getOptionalBooleanValue(
MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + MetricsOptions.METRICS_ENABLED.getKey()).orElse(false);
return !isMetricsEnabled ? METRICS : emptySet();
}
} }

View file

@ -17,7 +17,7 @@ quarkus.datasource.health.enabled=false
quarkus.micrometer.binder.http-server.enabled=false quarkus.micrometer.binder.http-server.enabled=false
# Enables metrics from other extensions if metrics is enabled # 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 # Default transaction timeout
quarkus.transaction-manager.default-transaction-timeout=300 quarkus.transaction-manager.default-transaction-timeout=300

View file

@ -22,6 +22,8 @@ import org.junit.Test;
import org.keycloak.common.Profile; import org.keycloak.common.Profile;
import org.keycloak.common.profile.PropertiesProfileConfigResolver; import org.keycloak.common.profile.PropertiesProfileConfigResolver;
import org.keycloak.config.DatabaseOptions; 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.IgnoredArtifacts;
import org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider; import org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider;
@ -109,4 +111,34 @@ public class IgnoredArtifactsTest {
System.setProperty(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + DatabaseOptions.DB.getKey(), ""); 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(), "");
}
}
} }