From cc381835d9a0fae411fd5b5e4733ecd6baff368a Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Wed, 15 Nov 2023 23:08:26 +0200 Subject: [PATCH] feat: generate prometheus ServiceMonitor CR --- bom/application/pom.xml | 8 +- .../kubernetes/vanilla/deployment/pom.xml | 20 +++++ .../AddServiceMonitorResourceDecorator.java | 46 ++++++++++ .../deployment/KubernetesCommonHelper.java | 25 ++++-- .../deployment/PrometheusConfig.java | 10 +++ .../kubernetes/quarkus-standard-way/pom.xml | 11 +++ ...bernetesWithMetricsCustomAbsoluteTest.java | 23 ++++- ...bernetesWithMetricsCustomRelativeTest.java | 26 +++++- ...ubernetesWithMetricsNoAnnotationsTest.java | 23 ++++- ...KubernetesWithMetricsNoServiceMonitor.java | 87 +++++++++++++++++++ .../kubernetes/KubernetesWithMetricsTest.java | 20 ++++- .../KubernetesWithMicrometerTest.java | 46 +++++++--- ...es-with-metrics-custom-absolute.properties | 4 - ...es-with-metrics-custom-relative.properties | 4 - ...tes-with-metrics-no-annotations.properties | 4 - .../kubernetes-with-metrics.properties | 1 - 16 files changed, 318 insertions(+), 40 deletions(-) create mode 100644 extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddServiceMonitorResourceDecorator.java create mode 100644 integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsNoServiceMonitor.java delete mode 100644 integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-custom-absolute.properties delete mode 100644 integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-custom-relative.properties delete mode 100644 integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-no-annotations.properties delete mode 100644 integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics.properties diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 7e04f0438a780..a982858e8bf15 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -161,7 +161,7 @@ 1.7.3 0.27.0 1.6.0 - 4.0.3 + 4.1.0 3.2.0 4.2.0 3.0.2.Final @@ -3178,6 +3178,12 @@ ${dekorate.version} noapt + + io.dekorate + prometheus-annotations + ${dekorate.version} + noapt + io.dekorate s2i-annotations diff --git a/extensions/kubernetes/vanilla/deployment/pom.xml b/extensions/kubernetes/vanilla/deployment/pom.xml index cb2668a662062..40b8b5b205e41 100644 --- a/extensions/kubernetes/vanilla/deployment/pom.xml +++ b/extensions/kubernetes/vanilla/deployment/pom.xml @@ -90,6 +90,26 @@ + + io.dekorate + prometheus-annotations + noapt + + + io.sundr + * + + + com.sun + tools + + + io.fabric8 + kubernetes-client + + + + io.quarkus quarkus-junit5-internal diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddServiceMonitorResourceDecorator.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddServiceMonitorResourceDecorator.java new file mode 100644 index 0000000000000..bc75666b48f15 --- /dev/null +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddServiceMonitorResourceDecorator.java @@ -0,0 +1,46 @@ +package io.quarkus.kubernetes.deployment; + +import io.dekorate.kubernetes.decorator.ResourceProvidingDecorator; +import io.dekorate.prometheus.model.ServiceMonitorBuilder; +import io.fabric8.kubernetes.api.model.KubernetesListBuilder; +import io.fabric8.kubernetes.api.model.ObjectMeta; + +public class AddServiceMonitorResourceDecorator extends ResourceProvidingDecorator { + + private final String scheme; + private final String targetPort; + private final String path; + private final int interval; + private final boolean honorLabels; + + public AddServiceMonitorResourceDecorator(String scheme, String targetPort, String path, int interval, + boolean honorLabels) { + this.scheme = scheme; + this.targetPort = targetPort; + this.path = path; + this.interval = interval; + this.honorLabels = honorLabels; + } + + @Override + public void visit(KubernetesListBuilder list) { + ObjectMeta meta = getMandatoryDeploymentMetadata(list, ANY); + list.addToItems(new ServiceMonitorBuilder() + .withNewMetadata() + .withName(meta.getName()) + .withLabels(meta.getLabels()) + .endMetadata() + .withNewSpec() + .withNewSelector() + .addToMatchLabels(meta.getLabels()) + .endSelector() + .addNewEndpoint() + .withScheme(scheme) + .withNewTargetPort(targetPort) + .withPath(path) + .withInterval(interval + "s") + .withHonorLabels(honorLabels) + .endEndpoint() + .endSpec()); + } +} diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java index afb73d57cdea4..f3ec0a8eb039a 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java @@ -996,12 +996,21 @@ private static List createAnnotationDecorators(Optional { - String path = m.metricsEndpoint(); - String prefix = config.getPrometheusConfig().prefix; - if (port.isPresent() && path != null) { + // Add metrics annotations + metricsConfiguration.ifPresent(m -> { + String path = m.metricsEndpoint(); + String prefix = config.getPrometheusConfig().prefix; + if (port.isPresent() && path != null) { + if (config.getPrometheusConfig().generateServiceMonitor) { + result.add(new DecoratorBuildItem(target, new AddServiceMonitorResourceDecorator( + config.getPrometheusConfig().scheme.orElse("http"), + config.getPrometheusConfig().port.orElse(String.valueOf(port.get().getContainerPort())), + config.getPrometheusConfig().path.orElse(path), + 10, + true))); + } + + if (config.getPrometheusConfig().annotations) { result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name, config.getPrometheusConfig().scrape.orElse(prefix + "/scrape"), "true", PROMETHEUS_ANNOTATION_TARGETS))); @@ -1014,8 +1023,8 @@ private static List createAnnotationDecorators(Optional + + io.dekorate + prometheus-annotations + noapt + + + io.fabric8 + kubernetes-client + + + io.fabric8 kubernetes-client diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsCustomAbsoluteTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsCustomAbsoluteTest.java index d39d852925cd2..65287b49e0d01 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsCustomAbsoluteTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsCustomAbsoluteTest.java @@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import io.dekorate.prometheus.model.Endpoint; +import io.dekorate.prometheus.model.ServiceMonitor; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.builder.Version; @@ -30,7 +32,10 @@ public class KubernetesWithMetricsCustomAbsoluteTest { .setApplicationVersion("0.1-SNAPSHOT") .setRun(true) .setLogFileName("k8s.log") - .withConfigurationResource("kubernetes-with-metrics-custom-absolute.properties") + .overrideConfigKey("quarkus.http.port", "9090") + .overrideConfigKey("quarkus.micrometer.export.prometheus.path", "/absolute-metrics") + .overrideConfigKey("quarkus.kubernetes.prometheus.prefix", "example.io") + .overrideConfigKey("quarkus.kubernetes.prometheus.scrape", "example.io/should_be_scraped") .setForcedDependencies(List.of( Dependency.of("io.quarkus", "quarkus-micrometer-registry-prometheus", Version.getVersion()))); @@ -76,6 +81,22 @@ public void assertGeneratedResources() throws IOException { }); }); }); + + assertThat(kubernetesList).filteredOn(i -> i.getKind().equals("ServiceMonitor")).singleElement() + .isInstanceOfSatisfying(ServiceMonitor.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("metrics"); + }); + + assertThat(s.getSpec()).satisfies(spec -> { + assertThat(spec.getEndpoints()).hasSize(1); + assertThat(spec.getEndpoints().get(0)).isInstanceOfSatisfying(Endpoint.class, e -> { + assertThat(e.getScheme()).isEqualTo("http"); + assertThat(e.getTargetPort().getStrVal()).isEqualTo("9090"); + assertThat(e.getPath()).isEqualTo("/absolute-metrics"); + }); + }); + }); }); } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsCustomRelativeTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsCustomRelativeTest.java index f7540a26616cd..b9b9a113331ac 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsCustomRelativeTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsCustomRelativeTest.java @@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import io.dekorate.prometheus.model.Endpoint; +import io.dekorate.prometheus.model.ServiceMonitor; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.builder.Version; @@ -30,8 +32,12 @@ public class KubernetesWithMetricsCustomRelativeTest { .setApplicationVersion("0.1-SNAPSHOT") .setRun(true) .setLogFileName("k8s.log") - .withConfigurationResource("kubernetes-with-metrics-custom-relative.properties") - .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-smallrye-metrics", Version.getVersion()))); + .overrideConfigKey("quarkus.http.port", "9090") + .overrideConfigKey("quarkus.micrometer.export.prometheus.path", "met") + .overrideConfigKey("quarkus.kubernetes.prometheus.prefix", "example.io") + .overrideConfigKey("quarkus.kubernetes.prometheus.scrape", "example.io/should_be_scraped") + .setForcedDependencies(List.of( + Dependency.of("io.quarkus", "quarkus-micrometer-registry-prometheus", Version.getVersion()))); @ProdBuildResults private ProdModeTestResults prodModeTestResults; @@ -76,6 +82,22 @@ public void assertGeneratedResources() throws IOException { }); }); }); + + assertThat(kubernetesList).filteredOn(i -> i.getKind().equals("ServiceMonitor")).singleElement() + .isInstanceOfSatisfying(ServiceMonitor.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("metrics"); + }); + + assertThat(s.getSpec()).satisfies(spec -> { + assertThat(spec.getEndpoints()).hasSize(1); + assertThat(spec.getEndpoints().get(0)).isInstanceOfSatisfying(Endpoint.class, e -> { + assertThat(e.getScheme()).isEqualTo("http"); + assertThat(e.getTargetPort().getStrVal()).isEqualTo("9090"); + assertThat(e.getPath()).isEqualTo("/q/met"); + }); + }); + }); } } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsNoAnnotationsTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsNoAnnotationsTest.java index 23ff2055c42dc..aa2d0878db11e 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsNoAnnotationsTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsNoAnnotationsTest.java @@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import io.dekorate.prometheus.model.Endpoint; +import io.dekorate.prometheus.model.ServiceMonitor; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.builder.Version; @@ -30,7 +32,10 @@ public class KubernetesWithMetricsNoAnnotationsTest { .setApplicationVersion("0.1-SNAPSHOT") .setRun(true) .setLogFileName("k8s.log") - .withConfigurationResource("kubernetes-with-metrics-no-annotations.properties") + .overrideConfigKey("quarkus.http.port", "9090") + .overrideConfigKey("quarkus.smallrye-metrics.path", "/met") + .overrideConfigKey("quarkus.kubernetes.prometheus.annotations", "false") + .overrideConfigKey("quarkus.kubernetes.prometheus.prefix", "example.io") .setForcedDependencies(List.of( Dependency.of("io.quarkus", "quarkus-micrometer-registry-prometheus", Version.getVersion()))); @@ -76,6 +81,22 @@ public void assertGeneratedResources() throws IOException { }); }); }); + + assertThat(kubernetesList).filteredOn(i -> i.getKind().equals("ServiceMonitor")).singleElement() + .isInstanceOfSatisfying(ServiceMonitor.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("metrics"); + }); + + assertThat(s.getSpec()).satisfies(spec -> { + assertThat(spec.getEndpoints()).hasSize(1); + assertThat(spec.getEndpoints().get(0)).isInstanceOfSatisfying(Endpoint.class, e -> { + assertThat(e.getScheme()).isEqualTo("http"); + assertThat(e.getTargetPort().getStrVal()).isEqualTo("9090"); + assertThat(e.getPath()).isEqualTo("/q/metrics"); + }); + }); + }); } } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsNoServiceMonitor.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsNoServiceMonitor.java new file mode 100644 index 0000000000000..c996e15047d2f --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsNoServiceMonitor.java @@ -0,0 +1,87 @@ +package io.quarkus.it.kubernetes; + +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; +import static org.hamcrest.Matchers.is; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.apps.Deployment; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.LogFile; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class KubernetesWithMetricsNoServiceMonitor { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName("metrics") + .setApplicationVersion("0.1-SNAPSHOT") + .setRun(true) + .setLogFileName("k8s.log") + .overrideConfigKey("quarkus.http.port", "9090") + .overrideConfigKey("quarkus.smallrye-metrics.path", "/met") + .overrideConfigKey("quarkus.kubernetes.prometheus.generate-service-monitor", "false") + .overrideConfigKey("quarkus.kubernetes.prometheus.prefix", "example.io") + .setForcedDependencies(List.of( + Dependency.of("io.quarkus", "quarkus-micrometer-registry-prometheus", Version.getVersion()))); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @LogFile + private Path logfile; + + @Test + public void assertApplicationRuns() { + assertThat(logfile).isRegularFile().hasFileName("k8s.log"); + TestUtil.assertLogFileContents(logfile, "kubernetes", "metrics"); + + given() + .when().get("/greeting") + .then() + .statusCode(200) + .body(is("hello")); + } + + @Test + public void assertGeneratedResources() throws IOException { + final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml")); + List kubernetesList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("kubernetes.yml")); + assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> { + assertThat(d.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("metrics"); + }); + + assertThat(d.getSpec()).satisfies(deploymentSpec -> { + assertThat(deploymentSpec.getTemplate()).satisfies(t -> { + assertThat(t.getMetadata()).satisfies(meta -> { + // Annotations should not have been created in this configuration. + assertThat(meta.getAnnotations()).contains( + entry("prometheus.io/scrape", "true"), + entry("prometheus.io/path", "/met"), + entry("prometheus.io/port", "9090"), + entry("prometheus.io/scheme", "http")); + }); + }); + }); + }); + + assertThat(kubernetesList).filteredOn(i -> i.getKind().equals("ServiceMonitor")).isEmpty(); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsTest.java index 934de87fa74ed..37c51a12afcdc 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMetricsTest.java @@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import io.dekorate.prometheus.model.Endpoint; +import io.dekorate.prometheus.model.ServiceMonitor; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.builder.Version; @@ -30,7 +32,7 @@ public class KubernetesWithMetricsTest { .setApplicationVersion("0.1-SNAPSHOT") .setRun(true) .setLogFileName("k8s.log") - .withConfigurationResource("kubernetes-with-metrics.properties") + .overrideConfigKey("quarkus.http.port", "9090") .setForcedDependencies(List.of( Dependency.of("io.quarkus", "quarkus-smallrye-metrics", Version.getVersion()), Dependency.of("io.quarkus", "quarkus-kubernetes-client", Version.getVersion()))); @@ -83,6 +85,22 @@ public void assertGeneratedResources() throws IOException { entry("prometheus.io/scheme", "http")); }); + assertThat(kubernetesList).filteredOn(i -> i.getKind().equals("ServiceMonitor")).singleElement() + .isInstanceOfSatisfying(ServiceMonitor.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("metrics"); + }); + + assertThat(s.getSpec()).satisfies(spec -> { + assertThat(spec.getEndpoints()).hasSize(1); + assertThat(spec.getEndpoints().get(0)).isInstanceOfSatisfying(Endpoint.class, e -> { + assertThat(e.getScheme()).isEqualTo("http"); + assertThat(e.getTargetPort().getStrVal()).isEqualTo("9090"); + assertThat(e.getPath()).isEqualTo("/q/metrics"); + }); + }); + }); + assertThat(kubernetesList).filteredOn(h -> "ServiceAccount".equals(h.getKind())).singleElement().satisfies(h -> { if (h.getMetadata().getAnnotations() != null) { assertThat(h.getMetadata().getAnnotations()).doesNotContainKeys("prometheus.io/scrape", "prometheus.io/path", diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMicrometerTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMicrometerTest.java index 799842d43212f..b41e32d046c14 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMicrometerTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMicrometerTest.java @@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import io.dekorate.prometheus.model.Endpoint; +import io.dekorate.prometheus.model.ServiceMonitor; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.builder.Version; @@ -59,21 +61,39 @@ public void assertGeneratedResources() throws IOException { .isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml")); List kubernetesList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("kubernetes.yml")); - assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> { - assertThat(d.getMetadata()).satisfies(m -> { - assertThat(m.getName()).isEqualTo("metrics"); - }); - - assertThat(d.getSpec()).satisfies(deploymentSpec -> { - assertThat(deploymentSpec.getTemplate()).satisfies(t -> { - assertThat(t.getMetadata()).satisfies(meta -> { - assertThat(meta.getAnnotations()).contains(entry("prometheus.io/scrape", "true"), - entry("prometheus.io/path", "/q/metrics"), entry("prometheus.io/port", "8080"), - entry("prometheus.io/scheme", "http")); + + assertThat(kubernetesList).filteredOn(i -> i.getKind().equals("ServiceMonitor")).singleElement() + .isInstanceOfSatisfying(ServiceMonitor.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("metrics"); + }); + + assertThat(s.getSpec()).satisfies(spec -> { + assertThat(spec.getEndpoints()).hasSize(1); + assertThat(spec.getEndpoints().get(0)).isInstanceOfSatisfying(Endpoint.class, e -> { + assertThat(e.getScheme()).isEqualTo("http"); + assertThat(e.getTargetPort().getStrVal()).isEqualTo("8080"); + assertThat(e.getPath()).isEqualTo("/q/metrics"); + }); + }); + }); + + assertThat(kubernetesList).filteredOn(i -> i instanceof Deployment).singleElement() + .isInstanceOfSatisfying(Deployment.class, d -> { + assertThat(d.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("metrics"); + }); + + assertThat(d.getSpec()).satisfies(deploymentSpec -> { + assertThat(deploymentSpec.getTemplate()).satisfies(t -> { + assertThat(t.getMetadata()).satisfies(meta -> { + assertThat(meta.getAnnotations()).contains(entry("prometheus.io/scrape", "true"), + entry("prometheus.io/path", "/q/metrics"), entry("prometheus.io/port", "8080"), + entry("prometheus.io/scheme", "http")); + }); + }); }); }); - }); - }); } } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-custom-absolute.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-custom-absolute.properties deleted file mode 100644 index befe3e634b923..0000000000000 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-custom-absolute.properties +++ /dev/null @@ -1,4 +0,0 @@ -quarkus.http.port=9090 -quarkus.micrometer.export.prometheus.path=/absolute-metrics -quarkus.kubernetes.prometheus.prefix=example.io -quarkus.kubernetes.prometheus.scrape=example.io/should_be_scraped \ No newline at end of file diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-custom-relative.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-custom-relative.properties deleted file mode 100644 index ce7853e673614..0000000000000 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-custom-relative.properties +++ /dev/null @@ -1,4 +0,0 @@ -quarkus.http.port=9090 -quarkus.smallrye-metrics.path=met -quarkus.kubernetes.prometheus.prefix=example.io -quarkus.kubernetes.prometheus.scrape=example.io/should_be_scraped \ No newline at end of file diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-no-annotations.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-no-annotations.properties deleted file mode 100644 index 232bf76c33de6..0000000000000 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics-no-annotations.properties +++ /dev/null @@ -1,4 +0,0 @@ -quarkus.http.port=9090 -quarkus.smallrye-metrics.path=/met -quarkus.kubernetes.prometheus.annotations=false -quarkus.kubernetes.prometheus.prefix=example.io diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics.properties deleted file mode 100644 index 2e40601cd49fa..0000000000000 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-metrics.properties +++ /dev/null @@ -1 +0,0 @@ -quarkus.http.port=9090