From 9cde86493ba8d835a1d663103add50889f1f032d Mon Sep 17 00:00:00 2001 From: Ryan Lonergan Date: Fri, 19 Jul 2024 11:55:46 -0400 Subject: [PATCH] [operator] feat: add 'relabelings' and 'metricRelabelings' configs to serviceMonitor (#1246) * feat: add 'relabelings' and 'metricRelabelings' configs to serviceMonitor Signed-off-by: Ryan Lonergan * update schema Signed-off-by: Ryan Lonergan * update version in Chart.yaml Signed-off-by: Ryan Lonergan * bump Chart version * chore: make generate-examples CHARTS=opentelemetry-operator --------- Signed-off-by: Ryan Lonergan --- charts/opentelemetry-operator/Chart.yaml | 2 +- .../operator-webhook-with-cert-manager.yaml | 4 +- .../default/rendered/certmanager.yaml | 4 +- .../default/rendered/clusterrole.yaml | 6 +- .../default/rendered/clusterrolebinding.yaml | 4 +- .../examples/default/rendered/deployment.yaml | 2 +- .../examples/default/rendered/role.yaml | 2 +- .../default/rendered/rolebinding.yaml | 2 +- .../examples/default/rendered/service.yaml | 4 +- .../default/rendered/serviceaccount.yaml | 2 +- .../tests/test-certmanager-connection.yaml | 2 +- .../tests/test-service-connection.yaml | 4 +- .../templates/servicemonitor.yaml | 8 + .../opentelemetry-operator/values.schema.json | 174 ++++++++++-------- charts/opentelemetry-operator/values.yaml | 4 + 15 files changed, 128 insertions(+), 96 deletions(-) diff --git a/charts/opentelemetry-operator/Chart.yaml b/charts/opentelemetry-operator/Chart.yaml index b434e2c16..a9fe5f7c1 100644 --- a/charts/opentelemetry-operator/Chart.yaml +++ b/charts/opentelemetry-operator/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: opentelemetry-operator -version: 0.64.3 +version: 0.64.4 description: OpenTelemetry Operator Helm chart for Kubernetes type: application home: https://opentelemetry.io/ diff --git a/charts/opentelemetry-operator/examples/default/rendered/admission-webhooks/operator-webhook-with-cert-manager.yaml b/charts/opentelemetry-operator/examples/default/rendered/admission-webhooks/operator-webhook-with-cert-manager.yaml index fcb8cb30c..81800d377 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/admission-webhooks/operator-webhook-with-cert-manager.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/admission-webhooks/operator-webhook-with-cert-manager.yaml @@ -6,7 +6,7 @@ metadata: annotations: cert-manager.io/inject-ca-from: default/example-opentelemetry-operator-serving-cert labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm @@ -91,7 +91,7 @@ metadata: annotations: cert-manager.io/inject-ca-from: default/example-opentelemetry-operator-serving-cert labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/examples/default/rendered/certmanager.yaml b/charts/opentelemetry-operator/examples/default/rendered/certmanager.yaml index 65bf1e98c..183a0c76f 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/certmanager.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/certmanager.yaml @@ -4,7 +4,7 @@ apiVersion: cert-manager.io/v1 kind: Certificate metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm @@ -30,7 +30,7 @@ apiVersion: cert-manager.io/v1 kind: Issuer metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/examples/default/rendered/clusterrole.yaml b/charts/opentelemetry-operator/examples/default/rendered/clusterrole.yaml index 3475fc8ff..9f42b45c9 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/clusterrole.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/clusterrole.yaml @@ -4,7 +4,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm @@ -223,7 +223,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm @@ -242,7 +242,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/examples/default/rendered/clusterrolebinding.yaml b/charts/opentelemetry-operator/examples/default/rendered/clusterrolebinding.yaml index f73b93523..ad637dd3e 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/clusterrolebinding.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/clusterrolebinding.yaml @@ -4,7 +4,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm @@ -26,7 +26,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/examples/default/rendered/deployment.yaml b/charts/opentelemetry-operator/examples/default/rendered/deployment.yaml index f0abb265c..66c836a22 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/deployment.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/deployment.yaml @@ -4,7 +4,7 @@ apiVersion: apps/v1 kind: Deployment metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/examples/default/rendered/role.yaml b/charts/opentelemetry-operator/examples/default/rendered/role.yaml index 16a154551..c9b4d385f 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/role.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/role.yaml @@ -4,7 +4,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/examples/default/rendered/rolebinding.yaml b/charts/opentelemetry-operator/examples/default/rendered/rolebinding.yaml index 6ecfe80dd..4c3850c16 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/rolebinding.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/rolebinding.yaml @@ -4,7 +4,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/examples/default/rendered/service.yaml b/charts/opentelemetry-operator/examples/default/rendered/service.yaml index ef82dbe8c..0d7ece785 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/service.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/service.yaml @@ -4,7 +4,7 @@ apiVersion: v1 kind: Service metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm @@ -32,7 +32,7 @@ apiVersion: v1 kind: Service metadata: labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/examples/default/rendered/serviceaccount.yaml b/charts/opentelemetry-operator/examples/default/rendered/serviceaccount.yaml index 106c1a6db..f6f268125 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/serviceaccount.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/serviceaccount.yaml @@ -6,7 +6,7 @@ metadata: name: opentelemetry-operator namespace: default labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/examples/default/rendered/tests/test-certmanager-connection.yaml b/charts/opentelemetry-operator/examples/default/rendered/tests/test-certmanager-connection.yaml index 301f2304e..51786d278 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/tests/test-certmanager-connection.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/tests/test-certmanager-connection.yaml @@ -6,7 +6,7 @@ metadata: name: "example-opentelemetry-operator-cert-manager" namespace: default labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/examples/default/rendered/tests/test-service-connection.yaml b/charts/opentelemetry-operator/examples/default/rendered/tests/test-service-connection.yaml index 8a6f7c44b..27f7b5886 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/tests/test-service-connection.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/tests/test-service-connection.yaml @@ -6,7 +6,7 @@ metadata: name: "example-opentelemetry-operator-metrics" namespace: default labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm @@ -44,7 +44,7 @@ metadata: name: "example-opentelemetry-operator-webhook" namespace: default labels: - helm.sh/chart: opentelemetry-operator-0.64.3 + helm.sh/chart: opentelemetry-operator-0.64.4 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.103.0" app.kubernetes.io/managed-by: Helm diff --git a/charts/opentelemetry-operator/templates/servicemonitor.yaml b/charts/opentelemetry-operator/templates/servicemonitor.yaml index 0633cf089..3c9d8c5a4 100644 --- a/charts/opentelemetry-operator/templates/servicemonitor.yaml +++ b/charts/opentelemetry-operator/templates/servicemonitor.yaml @@ -23,6 +23,14 @@ spec: app.kubernetes.io/component: controller-manager endpoints: {{- toYaml .Values.manager.serviceMonitor.metricsEndpoints | nindent 2 }} + {{- with .Values.manager.serviceMonitor.relabelings }} + relabelings: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.manager.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 4 }} + {{- end }} namespaceSelector: matchNames: - {{ .Release.Namespace }} diff --git a/charts/opentelemetry-operator/values.schema.json b/charts/opentelemetry-operator/values.schema.json index f70b1ac26..146a6b587 100644 --- a/charts/opentelemetry-operator/values.schema.json +++ b/charts/opentelemetry-operator/values.schema.json @@ -711,83 +711,103 @@ }] }, "serviceMonitor": { - "type": "object", - "default": {}, - "title": "The serviceMonitor Schema", - "required": [ - "enabled", - "extraLabels", - "annotations", - "metricsEndpoints" - ], - "additionalProperties": false, - "properties": { - "enabled": { - "type": "boolean", - "default": false, - "title": "The enabled Schema", - "examples": [ - false - ] - }, - "extraLabels": { - "type": "object", - "default": {}, - "title": "The extraLabels Schema", - "required": [], - "properties": {}, - "examples": [{}] - }, - "annotations": { - "type": "object", - "default": {}, - "title": "The annotations Schema", - "required": [], - "properties": {}, - "examples": [{}] - }, - "metricsEndpoints": { - "type": "array", - "default": [], - "title": "The metricsEndpoints Schema", - "items": { - "type": "object", - "default": {}, - "title": "A Schema", - "required": [ - "port" - ], - "additionalProperties": false, - "properties": { - "port": { - "type": "string", - "default": "", - "title": "The port Schema", - "examples": [ - "metrics" - ] - } - }, - "examples": [{ - "port": "metrics" - }] - }, - "examples": [ - [{ - "port": "metrics" - }] - ] - } - }, - "examples": [{ - "enabled": false, - "extraLabels": {}, - "annotations": {}, - "metricsEndpoints": [{ - "port": "metrics" - }] - }] - }, + "type": "object", + "default": {}, + "title": "The serviceMonitor Schema", + "required": [ + "enabled", + "extraLabels", + "annotations", + "metricsEndpoints", + "relabelings", + "metricRelabelings" + ], + "properties": { + "enabled": { + "type": "boolean", + "default": false, + "title": "The enabled Schema", + "examples": [ + true + ] + }, + "extraLabels": { + "type": "object", + "default": {}, + "title": "The extraLabels Schema", + "required": [], + "properties": {}, + "examples": [{}] + }, + "annotations": { + "type": "object", + "default": {}, + "title": "The annotations Schema", + "required": [], + "properties": {}, + "examples": [{}] + }, + "metricsEndpoints": { + "type": "array", + "default": [], + "title": "The metricsEndpoints Schema", + "items": { + "type": "object", + "default": {}, + "title": "A Schema", + "required": [ + "port" + ], + "properties": { + "port": { + "type": "string", + "default": "", + "title": "The port Schema", + "examples": [ + "metrics" + ] + } + }, + "examples": [{ + "port": "metrics" + }] + }, + "examples": [ + [{ + "port": "metrics" + }] + ] + }, + "relabelings": { + "type": "array", + "description": "Specify general relabeling", + "default": [], + "items": {} + }, + "metricRelabelings": { + "type": "array", + "description": "Specify additional relabeling of metrics", + "default": [], + "items": {} + } + }, + "examples": [{ + "enabled": true, + "extraLabels": {}, + "annotations": {}, + "metricsEndpoints": [{ + "port": "metrics" + }], + "relabelings": [{ + "sourceLabels": [ + "__meta_kubernetes_pod_node_name" + ], + "targetLabel": "node", + "replacement": "${1}" + }], + "metricRelabelings": [] + }] + }, "deploymentAnnotations": { "type": "object", "default": {}, diff --git a/charts/opentelemetry-operator/values.yaml b/charts/opentelemetry-operator/values.yaml index 811836fdf..7f82d8731 100644 --- a/charts/opentelemetry-operator/values.yaml +++ b/charts/opentelemetry-operator/values.yaml @@ -109,6 +109,10 @@ manager: annotations: {} metricsEndpoints: - port: metrics + # Used to set relabeling and metricRelabeling configs on the ServiceMonitor + # https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config + relabelings: [] + metricRelabelings: [] # Adds additional annotations to the manager Deployment deploymentAnnotations: {}