From 4d61b86d4829e800267088ca455cc14fe62e10cd Mon Sep 17 00:00:00 2001 From: Yevhen Ivantsov Date: Fri, 25 Aug 2023 18:37:41 +1000 Subject: [PATCH] Decouple server and jmx annotations --- src/main/charts/bamboo/README.md | 1 + src/main/charts/bamboo/templates/service-jmx.yaml | 2 +- src/main/charts/bamboo/values.yaml | 4 ++++ src/main/charts/bitbucket/README.md | 1 + src/main/charts/bitbucket/templates/service-jmx.yaml | 2 +- src/main/charts/bitbucket/values.yaml | 4 ++++ src/main/charts/confluence/README.md | 1 + src/main/charts/confluence/templates/service-jmx.yaml | 2 +- src/main/charts/confluence/values.yaml | 4 ++++ src/main/charts/crowd/README.md | 1 + src/main/charts/crowd/templates/service-jmx.yaml | 2 +- src/main/charts/crowd/values.yaml | 4 ++++ src/main/charts/jira/README.md | 1 + src/main/charts/jira/templates/service-jmx.yaml | 2 +- src/main/charts/jira/values.yaml | 4 ++++ src/test/java/test/JmxMetricsTest.java | 6 +++++- 16 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/main/charts/bamboo/README.md b/src/main/charts/bamboo/README.md index 0c6e39042..580d2efca 100644 --- a/src/main/charts/bamboo/README.md +++ b/src/main/charts/bamboo/README.md @@ -139,6 +139,7 @@ Kubernetes: `>=1.21.x-0` | monitoring.jmxExporterImageTag | string | `"0.18.0"` | Image tag to be used to pull jmxExporterImageRepo | | monitoring.jmxExporterPort | int | `9999` | Port number on which metrics will be available | | monitoring.jmxExporterPortType | string | `"ClusterIP"` | JMX exporter port type | +| monitoring.jmxServiceAnnotations | object | `{}` | Annotations added to the jmx service | | monitoring.serviceMonitor.create | bool | `false` | Create ServiceMonitor to start scraping metrics. ServiceMonitor CRD needs to be created in advance. | | monitoring.serviceMonitor.prometheusLabelSelector | object | `{}` | ServiceMonitorSelector of the prometheus instance. | | monitoring.serviceMonitor.scrapeIntervalSeconds | int | `30` | Scrape interval for the JMX service. | diff --git a/src/main/charts/bamboo/templates/service-jmx.yaml b/src/main/charts/bamboo/templates/service-jmx.yaml index 9e826c395..3924aa336 100644 --- a/src/main/charts/bamboo/templates/service-jmx.yaml +++ b/src/main/charts/bamboo/templates/service-jmx.yaml @@ -6,7 +6,7 @@ metadata: labels: {{- include "common.labels.commonLabels" . | nindent 4 }} annotations: - {{- with .Values.bamboo.service.annotations }} + {{- with .Values.monitoring.jmxServiceAnnotations }} {{- toYaml . | nindent 4 }} {{- end }} spec: diff --git a/src/main/charts/bamboo/values.yaml b/src/main/charts/bamboo/values.yaml index 107553261..0d1bc014a 100644 --- a/src/main/charts/bamboo/values.yaml +++ b/src/main/charts/bamboo/values.yaml @@ -833,6 +833,10 @@ monitoring: # exposeJmxMetrics: false + # -- Annotations added to the jmx service + # + jmxServiceAnnotations: {} + # -- Fetch jmx_exporter jar from the image. If set to false make sure to manually copy the jar # to shared home and provide an absolute path in jmxExporterCustomJarLocation # diff --git a/src/main/charts/bitbucket/README.md b/src/main/charts/bitbucket/README.md index f19796e6e..d6937ca9b 100644 --- a/src/main/charts/bitbucket/README.md +++ b/src/main/charts/bitbucket/README.md @@ -171,6 +171,7 @@ Kubernetes: `>=1.21.x-0` | monitoring.jmxExporterImageTag | string | `"0.18.0"` | Image tag to be used to pull jmxExporterImageRepo | | monitoring.jmxExporterPort | int | `9999` | Port number on which metrics will be available | | monitoring.jmxExporterPortType | string | `"ClusterIP"` | JMX exporter port type | +| monitoring.jmxServiceAnnotations | object | `{}` | Annotations added to the jmx service | | monitoring.serviceMonitor.create | bool | `false` | Create ServiceMonitor to start scraping metrics. ServiceMonitor CRD needs to be created in advance. | | monitoring.serviceMonitor.prometheusLabelSelector | object | `{}` | ServiceMonitorSelector of the prometheus instance. | | monitoring.serviceMonitor.scrapeIntervalSeconds | int | `30` | Scrape interval for the JMX service. | diff --git a/src/main/charts/bitbucket/templates/service-jmx.yaml b/src/main/charts/bitbucket/templates/service-jmx.yaml index 7bdfe1f84..eaa822732 100644 --- a/src/main/charts/bitbucket/templates/service-jmx.yaml +++ b/src/main/charts/bitbucket/templates/service-jmx.yaml @@ -6,7 +6,7 @@ metadata: labels: {{- include "common.labels.commonLabels" . | nindent 4 }} annotations: - {{- with .Values.bitbucket.service.annotations }} + {{- with .Values.monitoring.jmxServiceAnnotations }} {{- toYaml . | nindent 4 }} {{- end }} spec: diff --git a/src/main/charts/bitbucket/values.yaml b/src/main/charts/bitbucket/values.yaml index ce5832c4d..9f696ed06 100644 --- a/src/main/charts/bitbucket/values.yaml +++ b/src/main/charts/bitbucket/values.yaml @@ -1106,6 +1106,10 @@ monitoring: # exposeJmxMetrics: false + # -- Annotations added to the jmx service + # + jmxServiceAnnotations: {} + # -- Fetch jmx_exporter jar from the image. If set to false make sure to manually copy the jar # to shared home and provide an absolute path in jmxExporterCustomJarLocation # diff --git a/src/main/charts/confluence/README.md b/src/main/charts/confluence/README.md index 29297f1dd..0483d7b2a 100644 --- a/src/main/charts/confluence/README.md +++ b/src/main/charts/confluence/README.md @@ -134,6 +134,7 @@ Kubernetes: `>=1.21.x-0` | monitoring.jmxExporterImageTag | string | `"0.18.0"` | Image tag to be used to pull jmxExporterImageRepo | | monitoring.jmxExporterPort | int | `9999` | Port number on which metrics will be available | | monitoring.jmxExporterPortType | string | `"ClusterIP"` | JMX exporter port type | +| monitoring.jmxServiceAnnotations | object | `{}` | Annotations added to the jmx service | | monitoring.serviceMonitor.create | bool | `false` | Create ServiceMonitor to start scraping metrics. ServiceMonitor CRD needs to be created in advance. | | monitoring.serviceMonitor.prometheusLabelSelector | object | `{}` | ServiceMonitorSelector of the prometheus instance. | | monitoring.serviceMonitor.scrapeIntervalSeconds | int | `30` | Scrape interval for the JMX service. | diff --git a/src/main/charts/confluence/templates/service-jmx.yaml b/src/main/charts/confluence/templates/service-jmx.yaml index c79a513fa..3924aa336 100644 --- a/src/main/charts/confluence/templates/service-jmx.yaml +++ b/src/main/charts/confluence/templates/service-jmx.yaml @@ -6,7 +6,7 @@ metadata: labels: {{- include "common.labels.commonLabels" . | nindent 4 }} annotations: - {{- with .Values.confluence.service.annotations }} + {{- with .Values.monitoring.jmxServiceAnnotations }} {{- toYaml . | nindent 4 }} {{- end }} spec: diff --git a/src/main/charts/confluence/values.yaml b/src/main/charts/confluence/values.yaml index 8ad51497e..401c8ede4 100644 --- a/src/main/charts/confluence/values.yaml +++ b/src/main/charts/confluence/values.yaml @@ -937,6 +937,10 @@ monitoring: # exposeJmxMetrics: false + # -- Annotations added to the jmx service + # + jmxServiceAnnotations: {} + # -- Fetch jmx_exporter jar from the image. If set to false make sure to manually copy the jar # to shared home and provide an absolute path in jmxExporterCustomJarLocation # diff --git a/src/main/charts/crowd/README.md b/src/main/charts/crowd/README.md index 3d505a156..6a8d080f6 100644 --- a/src/main/charts/crowd/README.md +++ b/src/main/charts/crowd/README.md @@ -113,6 +113,7 @@ Kubernetes: `>=1.21.x-0` | monitoring.jmxExporterImageTag | string | `"0.18.0"` | Image tag to be used to pull jmxExporterImageRepo | | monitoring.jmxExporterPort | int | `9999` | Port number on which metrics will be available | | monitoring.jmxExporterPortType | string | `"ClusterIP"` | JMX exporter port type | +| monitoring.jmxServiceAnnotations | object | `{}` | Annotations added to the jmx service | | monitoring.serviceMonitor.create | bool | `false` | Create ServiceMonitor to start scraping metrics. ServiceMonitor CRD needs to be created in advance. | | monitoring.serviceMonitor.prometheusLabelSelector | object | `{}` | ServiceMonitorSelector of the prometheus instance. | | monitoring.serviceMonitor.scrapeIntervalSeconds | int | `30` | Scrape interval for the JMX service. | diff --git a/src/main/charts/crowd/templates/service-jmx.yaml b/src/main/charts/crowd/templates/service-jmx.yaml index cabda61f0..3924aa336 100644 --- a/src/main/charts/crowd/templates/service-jmx.yaml +++ b/src/main/charts/crowd/templates/service-jmx.yaml @@ -6,7 +6,7 @@ metadata: labels: {{- include "common.labels.commonLabels" . | nindent 4 }} annotations: - {{- with .Values.crowd.service.annotations }} + {{- with .Values.monitoring.jmxServiceAnnotations }} {{- toYaml . | nindent 4 }} {{- end }} spec: diff --git a/src/main/charts/crowd/values.yaml b/src/main/charts/crowd/values.yaml index a9b395c0e..4dcac2497 100644 --- a/src/main/charts/crowd/values.yaml +++ b/src/main/charts/crowd/values.yaml @@ -809,6 +809,10 @@ monitoring: # exposeJmxMetrics: false + # -- Annotations added to the jmx service + # + jmxServiceAnnotations: {} + # -- Fetch jmx_exporter jar from the image. If set to false make sure to manually copy the jar # to shared home and provide an absolute path in jmxExporterCustomJarLocation # diff --git a/src/main/charts/jira/README.md b/src/main/charts/jira/README.md index 350953607..24a093bf9 100644 --- a/src/main/charts/jira/README.md +++ b/src/main/charts/jira/README.md @@ -130,6 +130,7 @@ Kubernetes: `>=1.21.x-0` | monitoring.jmxExporterImageTag | string | `"0.18.0"` | Image tag to be used to pull jmxExporterImageRepo | | monitoring.jmxExporterPort | int | `9999` | Port number on which metrics will be available | | monitoring.jmxExporterPortType | string | `"ClusterIP"` | JMX exporter port type | +| monitoring.jmxServiceAnnotations | object | `{}` | Annotations added to the jmx service | | monitoring.serviceMonitor.create | bool | `false` | Create ServiceMonitor to start scraping metrics. ServiceMonitor CRD needs to be created in advance. | | monitoring.serviceMonitor.prometheusLabelSelector | object | `{}` | ServiceMonitorSelector of the prometheus instance. | | monitoring.serviceMonitor.scrapeIntervalSeconds | int | `30` | Scrape interval for the JMX service. | diff --git a/src/main/charts/jira/templates/service-jmx.yaml b/src/main/charts/jira/templates/service-jmx.yaml index fb323562c..3924aa336 100644 --- a/src/main/charts/jira/templates/service-jmx.yaml +++ b/src/main/charts/jira/templates/service-jmx.yaml @@ -6,7 +6,7 @@ metadata: labels: {{- include "common.labels.commonLabels" . | nindent 4 }} annotations: - {{- with .Values.jira.service.annotations }} + {{- with .Values.monitoring.jmxServiceAnnotations }} {{- toYaml . | nindent 4 }} {{- end }} spec: diff --git a/src/main/charts/jira/values.yaml b/src/main/charts/jira/values.yaml index d07b81a43..1d18e0178 100644 --- a/src/main/charts/jira/values.yaml +++ b/src/main/charts/jira/values.yaml @@ -798,6 +798,10 @@ monitoring: # -- Expose JMX metrics with jmx_exporter https://github.com/prometheus/jmx_exporter # exposeJmxMetrics: false + + # -- Annotations added to the jmx service + # + jmxServiceAnnotations: {} # -- Fetch jmx_exporter jar from the image. If set to false make sure to manually copy the jar # to shared home and provide an absolute path in jmxExporterCustomJarLocation diff --git a/src/test/java/test/JmxMetricsTest.java b/src/test/java/test/JmxMetricsTest.java index f262ffce9..29b5192f7 100644 --- a/src/test/java/test/JmxMetricsTest.java +++ b/src/test/java/test/JmxMetricsTest.java @@ -134,7 +134,8 @@ void jmx_service_test(Product product) throws Exception { final var resources = helm.captureKubeResourcesFromHelmChart(product, Map.of( "monitoring.exposeJmxMetrics", "true", "monitoring.jmxExporterPort", "9000", - "monitoring.jmxExporterPortType", "NodePort" + "monitoring.jmxExporterPortType", "NodePort", + "monitoring.jmxServiceAnnotations.foo", "bar" )); final var service = resources.get(Kind.Service, Service.class, product.getHelmReleaseName()+"-jmx"); @@ -143,6 +144,9 @@ void jmx_service_test(Product product) throws Exception { .hasTextEqualTo("NodePort"); VavrAssertions.assertThat(service.getPort("jmx")) .hasValueSatisfying(node -> assertThat(node.path("port")).hasValueEqualTo(9000)); + assertThat(service.getAnnotations()).isObject(Map.of( + "foo", "bar" + )); } @ParameterizedTest