From 0a8d617e3b047b2453b1fc87f31ca899bd37a2f4 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sun, 19 Apr 2026 22:24:15 -0400 Subject: [PATCH] chart(selenium-grid): add ServiceMonitor and PodMonitor support Add Prometheus Operator ServiceMonitor and PodMonitor resources for the metrics exporter, allowing users to integrate with kube-prometheus-stack without manually configuring additionalScrapeConfigs. - Name the exporter container port `metrics` for explicit port referencing - Keep service port name `http-port` (no breaking change); targetPort now references the named port `metrics` - Add `monitoring-service-monitor.yaml`: ServiceMonitor scraping via the exporter Service on port `http-port` - Add `monitoring-pod-monitor.yaml`: PodMonitor scraping pods directly on port `metrics` (alternative to ServiceMonitor) - Add `monitoring.serviceMonitor.*` and `monitoring.podMonitor.*` values (enabled, namespace, labels, annotations, path, interval, scrapeTimeout, relabelings, metricRelabelings); both disabled by default Co-Authored-By: Claude Sonnet 4.6 (1M context) --- .../monitoring-exporter-deployment.yaml | 3 +- .../monitoring-exporter-service.yaml | 2 +- .../templates/monitoring-pod-monitor.yaml | 33 +++++++++++++++ .../templates/monitoring-service-monitor.yaml | 33 +++++++++++++++ charts/selenium-grid/values.yaml | 40 +++++++++++++++++++ 5 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 charts/selenium-grid/templates/monitoring-pod-monitor.yaml create mode 100644 charts/selenium-grid/templates/monitoring-service-monitor.yaml diff --git a/charts/selenium-grid/templates/monitoring-exporter-deployment.yaml b/charts/selenium-grid/templates/monitoring-exporter-deployment.yaml index 94a7e61b38..af4472d3ae 100644 --- a/charts/selenium-grid/templates/monitoring-exporter-deployment.yaml +++ b/charts/selenium-grid/templates/monitoring-exporter-deployment.yaml @@ -31,7 +31,8 @@ spec: {{- $imageRegistry := default .Values.global.seleniumGrid.imageRegistry .Values.monitoring.exporter.imageRegistry }} image: {{ printf "%s/%s:%s" $imageRegistry .Values.monitoring.exporter.imageName .Values.monitoring.exporter.imageTag | quote }} ports: - - containerPort: {{ .Values.monitoring.exporter.port }} + - name: metrics + containerPort: {{ .Values.monitoring.exporter.port }} {{- with .Values.monitoring.exporter.tolerations }} tolerations: {{ toYaml . | nindent 6 }} {{- end }} diff --git a/charts/selenium-grid/templates/monitoring-exporter-service.yaml b/charts/selenium-grid/templates/monitoring-exporter-service.yaml index c2f98b4c88..2859589276 100644 --- a/charts/selenium-grid/templates/monitoring-exporter-service.yaml +++ b/charts/selenium-grid/templates/monitoring-exporter-service.yaml @@ -26,7 +26,7 @@ spec: - name: http-port protocol: TCP port: {{ .Values.monitoring.exporter.port }} - targetPort: {{ .Values.monitoring.exporter.port }} + targetPort: metrics {{- if and (eq .Values.monitoring.exporter.service.type "NodePort") .Values.monitoring.exporter.service.nodePort }} nodePort: {{ .Values.monitoring.exporter.service.nodePort }} {{- end }} diff --git a/charts/selenium-grid/templates/monitoring-pod-monitor.yaml b/charts/selenium-grid/templates/monitoring-pod-monitor.yaml new file mode 100644 index 0000000000..2cb71e3217 --- /dev/null +++ b/charts/selenium-grid/templates/monitoring-pod-monitor.yaml @@ -0,0 +1,33 @@ +{{- if and (eq (include "seleniumGrid.monitoring.enabled" $) "true") .Values.monitoring.podMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: {{ template "seleniumGrid.monitoring.exporter.fullname" $ }} + namespace: {{ .Values.monitoring.podMonitor.namespace | default .Release.Namespace }} + {{- with .Values.monitoring.podMonitor.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + labels: + {{- include "seleniumGrid.commonLabels" $ | nindent 4 }} + {{- with .Values.monitoring.podMonitor.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + selector: + matchLabels: + app.kubernetes.io/name: {{ template "seleniumGrid.monitoring.exporter.fullname" $ }} + podMetricsEndpoints: + - port: metrics + path: {{ .Values.monitoring.podMonitor.path }} + interval: {{ .Values.monitoring.podMonitor.interval }} + scrapeTimeout: {{ .Values.monitoring.podMonitor.scrapeTimeout }} + {{- with .Values.monitoring.podMonitor.relabelings }} + relabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.monitoring.podMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/charts/selenium-grid/templates/monitoring-service-monitor.yaml b/charts/selenium-grid/templates/monitoring-service-monitor.yaml new file mode 100644 index 0000000000..47b19c609f --- /dev/null +++ b/charts/selenium-grid/templates/monitoring-service-monitor.yaml @@ -0,0 +1,33 @@ +{{- if and (eq (include "seleniumGrid.monitoring.enabled" $) "true") .Values.monitoring.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "seleniumGrid.monitoring.exporter.fullname" $ }} + namespace: {{ .Values.monitoring.serviceMonitor.namespace | default .Release.Namespace }} + {{- with .Values.monitoring.serviceMonitor.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + labels: + {{- include "seleniumGrid.commonLabels" $ | nindent 4 }} + {{- with .Values.monitoring.serviceMonitor.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + selector: + matchLabels: + app.kubernetes.io/name: {{ template "seleniumGrid.monitoring.exporter.fullname" $ }} + endpoints: + - port: http-port + path: {{ .Values.monitoring.serviceMonitor.path }} + interval: {{ .Values.monitoring.serviceMonitor.interval }} + scrapeTimeout: {{ .Values.monitoring.serviceMonitor.scrapeTimeout }} + {{- with .Values.monitoring.serviceMonitor.relabelings }} + relabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.monitoring.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/charts/selenium-grid/values.yaml b/charts/selenium-grid/values.yaml index 2094ca3c4c..2aa13b895a 100644 --- a/charts/selenium-grid/values.yaml +++ b/charts/selenium-grid/values.yaml @@ -1041,6 +1041,46 @@ monitoring: key: "" value: "" annotations: {} + # -- ServiceMonitor configuration for Prometheus Operator + serviceMonitor: + # -- Enable ServiceMonitor resource + enabled: false + # -- Namespace to deploy the ServiceMonitor into (defaults to release namespace) + namespace: "" + # -- Additional labels for the ServiceMonitor + labels: {} + # -- Additional annotations for the ServiceMonitor + annotations: {} + # -- Metrics scrape path + path: /metrics + # -- Scrape interval + interval: 30s + # -- Scrape timeout + scrapeTimeout: 10s + # -- RelabelConfigs to apply to samples before scraping + relabelings: [] + # -- MetricRelabelConfigs to apply to samples before ingestion + metricRelabelings: [] + # -- PodMonitor configuration for Prometheus Operator (alternative to ServiceMonitor) + podMonitor: + # -- Enable PodMonitor resource + enabled: false + # -- Namespace to deploy the PodMonitor into (defaults to release namespace) + namespace: "" + # -- Additional labels for the PodMonitor + labels: {} + # -- Additional annotations for the PodMonitor + annotations: {} + # -- Metrics scrape path + path: /metrics + # -- Scrape interval + interval: 30s + # -- Scrape timeout + scrapeTimeout: 10s + # -- RelabelConfigs to apply to samples before scraping + relabelings: [] + # -- MetricRelabelConfigs to apply to samples before ingestion + metricRelabelings: [] # Keda scaled object configuration autoscaling: