From 5808ad2de0f9b9fc4fb95f6250bcc4e1da74a20b Mon Sep 17 00:00:00 2001 From: vramik Date: Thu, 7 Mar 2019 10:05:17 +0100 Subject: [PATCH] KEYCLOAK-9708 Enable SmallRye Health and Metrics extensions --- .../configuration/domain/subsystems.xml | 6 ++ .../standalone/subsystems-ha.xml | 3 + .../configuration/standalone/subsystems.xml | 3 + .../content/bin/migrate-domain-clustered.cli | 46 ++++++++++++ .../content/bin/migrate-domain-standalone.cli | 46 ++++++++++++ .../content/bin/migrate-standalone-ha.cli | 40 ++++++++++ .../content/bin/migrate-standalone.cli | 40 ++++++++++ .../metrics/MetricsRestServiceTest.java | 73 +++++++++++++++++++ 8 files changed, 257 insertions(+) create mode 100644 testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/metrics/MetricsRestServiceTest.java diff --git a/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/domain/subsystems.xml b/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/domain/subsystems.xml index eb26b613e1..33a26ddc04 100755 --- a/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/domain/subsystems.xml +++ b/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/domain/subsystems.xml @@ -37,6 +37,9 @@ security.xml security-manager.xml transactions.xml + microprofile-config-smallrye.xml + microprofile-health-smallrye.xml + microprofile-metrics-smallrye.xml keycloak-undertow.xml keycloak-server.xml @@ -64,6 +67,9 @@ security.xml security-manager.xml transactions.xml + microprofile-config-smallrye.xml + microprofile-health-smallrye.xml + microprofile-metrics-smallrye.xml keycloak-undertow.xml keycloak-server.xml diff --git a/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/standalone/subsystems-ha.xml b/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/standalone/subsystems-ha.xml index cd52002a30..533c2fd963 100755 --- a/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/standalone/subsystems-ha.xml +++ b/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/standalone/subsystems-ha.xml @@ -42,6 +42,9 @@ elytron.xml security.xml transactions.xml + microprofile-config-smallrye.xml + microprofile-health-smallrye.xml + microprofile-metrics-smallrye.xml keycloak-undertow.xml keycloak-server.xml diff --git a/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/standalone/subsystems.xml b/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/standalone/subsystems.xml index 7c40a0e953..d237de7d72 100755 --- a/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/standalone/subsystems.xml +++ b/distribution/feature-packs/server-feature-pack/src/main/resources/configuration/standalone/subsystems.xml @@ -40,6 +40,9 @@ elytron.xml security.xml transactions.xml + microprofile-config-smallrye.xml + microprofile-health-smallrye.xml + microprofile-metrics-smallrye.xml keycloak-undertow.xml keycloak-server.xml diff --git a/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-domain-clustered.cli b/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-domain-clustered.cli index 8744fe45dd..737f5974d2 100644 --- a/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-domain-clustered.cli +++ b/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-domain-clustered.cli @@ -621,4 +621,50 @@ if (result == false) of /profile=$clusteredProfile/subsystem=webservices/:read-a echo end-if +if (outcome == failed) of /profile=$clusteredProfile/subsystem=microprofile-config-smallrye/:read-resource + try + echo Trying to add microprofile-config-smallrye extension + /extension=org.wildfly.extension.microprofile.config-smallrye/:add(module=org.wildfly.extension.microprofile.config-smallrye) + echo + catch + echo Wasn't able to add microprofile-config-smallrye extension, it should be already added by migrate-domain-standalone.cli + echo + end-try + echo Adding microprofile-config-smallrye subsystem + /profile=$clusteredProfile/subsystem=microprofile-config-smallrye/:add + echo +end-if + +if (outcome == failed) of /profile=$clusteredProfile/subsystem=microprofile-health-smallrye/:read-resource + try + echo Trying to add microprofile-health-smallrye extension + /extension=org.wildfly.extension.microprofile.health-smallrye/:add(module=org.wildfly.extension.microprofile.health-smallrye) + echo + catch + echo Wasn't able to add microprofile-health-smallrye extension, it should be already added by migrate-domain-standalone.cli + echo + end-try + echo Adding microprofile-health-smallrye subsystem + /profile=$clusteredProfile/subsystem=microprofile-health-smallrye/:add + /profile=$clusteredProfile/subsystem=microprofile-health-smallrye/:write-attribute(name=security-enabled,value=false) + echo +end-if + +if (outcome == failed) of /profile=$clusteredProfile/subsystem=microprofile-metrics-smallrye/:read-resource + try + echo Trying to add microprofile-metrics-smallrye extension + /extension=org.wildfly.extension.microprofile.metrics-smallrye/:add(module=org.wildfly.extension.microprofile.metrics-smallrye) + echo + catch + echo Wasn't able to add microprofile-metrics-smallrye extension, it should be already added by migrate-domain-standalone.cli + echo + end-try + echo Adding microprofile-metrics-smallrye subsystem + /profile=$clusteredProfile/subsystem=microprofile-metrics-smallrye/:add + /profile=$clusteredProfile/subsystem=microprofile-metrics-smallrye/:write-attribute(name=security-enabled,value=false) + /profile=$clusteredProfile/subsystem=microprofile-metrics-smallrye/:write-attribute(name=exposed-subsystems,value=[*]) + /profile=$clusteredProfile/subsystem=microprofile-metrics-smallrye/:write-attribute(name=prefix,value=${wildfly.metrics.prefix:wildfly}) + echo +end-if + echo *** End Migration of /profile=$clusteredProfile *** diff --git a/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-domain-standalone.cli b/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-domain-standalone.cli index 89e165d4c4..554ac35f8a 100644 --- a/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-domain-standalone.cli +++ b/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-domain-standalone.cli @@ -546,4 +546,50 @@ if (result == false) of /profile=$standaloneProfile/subsystem=webservices/:read- echo end-if +if (outcome == failed) of /profile=$standaloneProfile/subsystem=microprofile-config-smallrye/:read-resource + try + echo Trying to add microprofile-config-smallrye extension + /extension=org.wildfly.extension.microprofile.config-smallrye/:add(module=org.wildfly.extension.microprofile.config-smallrye) + echo + catch + echo Wasn't able to add microprofile-config-smallrye extension, it should be already added by migrate-domain-clustered.cli + echo + end-try + echo Adding microprofile-config-smallrye subsystem + /profile=$standaloneProfile/subsystem=microprofile-config-smallrye/:add + echo +end-if + +if (outcome == failed) of /profile=$standaloneProfile/subsystem=microprofile-health-smallrye/:read-resource + try + echo Trying to add microprofile-health-smallrye extension + /extension=org.wildfly.extension.microprofile.health-smallrye/:add(module=org.wildfly.extension.microprofile.health-smallrye) + echo + catch + echo Wasn't able to add microprofile-health-smallrye extension, it should be already added by migrate-domain-clustered.cli + echo + end-try + echo Adding microprofile-health-smallrye subsystem + /profile=$standaloneProfile/subsystem=microprofile-health-smallrye/:add + /profile=$standaloneProfile/subsystem=microprofile-health-smallrye/:write-attribute(name=security-enabled,value=false) + echo +end-if + +if (outcome == failed) of /profile=$standaloneProfile/subsystem=microprofile-metrics-smallrye/:read-resource + try + echo Trying to add microprofile-metrics-smallrye extension + /extension=org.wildfly.extension.microprofile.metrics-smallrye/:add(module=org.wildfly.extension.microprofile.metrics-smallrye) + echo + catch + echo Wasn't able to add microprofile-metrics-smallrye extension, it should be already added by migrate-domain-clustered.cli + echo + end-try + echo Adding microprofile-metrics-smallrye subsystem + /profile=$standaloneProfile/subsystem=microprofile-metrics-smallrye/:add + /profile=$standaloneProfile/subsystem=microprofile-metrics-smallrye/:write-attribute(name=security-enabled,value=false) + /profile=$standaloneProfile/subsystem=microprofile-metrics-smallrye/:write-attribute(name=exposed-subsystems,value=[*]) + /profile=$standaloneProfile/subsystem=microprofile-metrics-smallrye/:write-attribute(name=prefix,value=${wildfly.metrics.prefix:wildfly}) + echo +end-if + echo *** End Migration of /profile=$standaloneProfile *** diff --git a/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-standalone-ha.cli b/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-standalone-ha.cli index 56a2643d40..9ac2d9c16f 100644 --- a/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-standalone-ha.cli +++ b/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-standalone-ha.cli @@ -617,4 +617,44 @@ if (result == false) of /subsystem=webservices/:read-attribute(name=statistics-e echo end-if +if (outcome == failed) of /extension=org.wildfly.extension.microprofile.config-smallrye/:read-resource + echo Adding microprofile.config-smallrye extension... + /extension=org.wildfly.extension.microprofile.config-smallrye/:add(module=org.wildfly.extension.microprofile.config-smallrye) + echo +end-if + +if (outcome == failed) of /subsystem=microprofile-config-smallrye/:read-resource + echo Adding microprofile-config-smallrye subsystem + /subsystem=microprofile-config-smallrye/:add + echo +end-if + +if (outcome == failed) of /extension=org.wildfly.extension.microprofile.health-smallrye/:read-resource + echo Adding microprofile.health-smallrye extension... + /extension=org.wildfly.extension.microprofile.health-smallrye/:add(module=org.wildfly.extension.microprofile.health-smallrye) + echo +end-if + +if (outcome == failed) of /subsystem=microprofile-health-smallrye/:read-resource + echo Adding microprofile-health-smallrye subsystem + /subsystem=microprofile-health-smallrye/:add + /subsystem=microprofile-health-smallrye/:write-attribute(name=security-enabled,value=false) + echo +end-if + +if (outcome == failed) of /extension=org.wildfly.extension.microprofile.metrics-smallrye/:read-resource + echo Adding microprofile.metrics-smallrye extension... + /extension=org.wildfly.extension.microprofile.metrics-smallrye/:add(module=org.wildfly.extension.microprofile.metrics-smallrye) + echo +end-if + +if (outcome == failed) of /subsystem=microprofile-metrics-smallrye/:read-resource + echo Adding microprofile-metrics-smallrye subsystem + /subsystem=microprofile-metrics-smallrye/:add + /subsystem=microprofile-metrics-smallrye/:write-attribute(name=security-enabled,value=false) + /subsystem=microprofile-metrics-smallrye/:write-attribute(name=exposed-subsystems,value=[*]) + /subsystem=microprofile-metrics-smallrye/:write-attribute(name=prefix,value=${wildfly.metrics.prefix:wildfly}) + echo +end-if + echo *** End Migration *** diff --git a/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-standalone.cli b/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-standalone.cli index cb5a46f933..05ed40d757 100644 --- a/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-standalone.cli +++ b/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/migrate-standalone.cli @@ -506,4 +506,44 @@ if (result == false) of /subsystem=webservices/:read-attribute(name=statistics-e echo end-if +if (outcome == failed) of /extension=org.wildfly.extension.microprofile.health-smallrye/:read-resource + echo Adding microprofile.health-smallrye extension... + /extension=org.wildfly.extension.microprofile.health-smallrye/:add(module=org.wildfly.extension.microprofile.health-smallrye) + echo +end-if + +if (outcome == failed) of /subsystem=microprofile-health-smallrye/:read-resource + echo Adding microprofile-health-smallrye subsystem + /subsystem=microprofile-health-smallrye/:add + /subsystem=microprofile-health-smallrye/:write-attribute(name=security-enabled,value=false) + echo +end-if + +if (outcome == failed) of /extension=org.wildfly.extension.microprofile.config-smallrye/:read-resource + echo Adding microprofile.config-smallrye extension... + /extension=org.wildfly.extension.microprofile.config-smallrye/:add(module=org.wildfly.extension.microprofile.config-smallrye) + echo +end-if + +if (outcome == failed) of /subsystem=microprofile-config-smallrye/:read-resource + echo Adding microprofile-config-smallrye subsystem + /subsystem=microprofile-config-smallrye/:add + echo +end-if + +if (outcome == failed) of /extension=org.wildfly.extension.microprofile.metrics-smallrye/:read-resource + echo Adding microprofile.metrics-smallrye extension... + /extension=org.wildfly.extension.microprofile.metrics-smallrye/:add(module=org.wildfly.extension.microprofile.metrics-smallrye) + echo +end-if + +if (outcome == failed) of /subsystem=microprofile-metrics-smallrye/:read-resource + echo Adding microprofile-metrics-smallrye subsystem + /subsystem=microprofile-metrics-smallrye/:add + /subsystem=microprofile-metrics-smallrye/:write-attribute(name=security-enabled,value=false) + /subsystem=microprofile-metrics-smallrye/:write-attribute(name=exposed-subsystems,value=[*]) + /subsystem=microprofile-metrics-smallrye/:write-attribute(name=prefix,value=${wildfly.metrics.prefix:wildfly}) + echo +end-if + echo *** End Migration *** diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/metrics/MetricsRestServiceTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/metrics/MetricsRestServiceTest.java new file mode 100644 index 0000000000..72eb381553 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/metrics/MetricsRestServiceTest.java @@ -0,0 +1,73 @@ +/* + * Copyright 2019 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.keycloak.testsuite.metrics; + +import java.util.List; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.keycloak.representations.idm.RealmRepresentation; +import org.keycloak.testsuite.AbstractKeycloakTest; +import org.keycloak.testsuite.util.ContainerAssume; + +import static org.hamcrest.Matchers.containsString; +import static org.keycloak.testsuite.util.Matchers.body; +import static org.keycloak.testsuite.util.Matchers.statusCodeIs; + +public class MetricsRestServiceTest extends AbstractKeycloakTest { + + private static final String MGMT_PORT = System.getProperty("auth.server.management.port", "10090"); + + @Override + public void addTestRealms(List testRealms) { + // no test realms + } + + @BeforeClass + public static void enabled() { + ContainerAssume.assumeNotAuthServerUndertow(); + } + + @Test + public void testHealthEndpoint() { + Client client = ClientBuilder.newClient(); + + try (Response response = client.target("http://localhost:" + MGMT_PORT + "/health").request().get()) { + Assert.assertThat(response, statusCodeIs(Status.OK)); + Assert.assertThat(response, body(containsString("{\"outcome\":\"UP\",\"checks\":[]}"))); + } finally { + client.close(); + } + } + + @Test + public void testMetricsEndpoint() { + Client client = ClientBuilder.newClient(); + + try (Response response = client.target("http://localhost:" + MGMT_PORT + "/metrics").request().get()) { + Assert.assertThat(response, statusCodeIs(Status.OK)); + Assert.assertThat(response, body(containsString("base:classloader_total_loaded_class_count"))); + } finally { + client.close(); + } + } +}