diff --git a/cockroachdb/templates/service.metrics.yaml b/cockroachdb/templates/service.metrics.yaml new file mode 100644 index 00000000..3c2955c1 --- /dev/null +++ b/cockroachdb/templates/service.metrics.yaml @@ -0,0 +1,37 @@ +# This Service is only to scrape metrics from the CockroachDB cluster. +{{- if .Values.serviceMonitor.enabled }} +kind: Service +apiVersion: v1 +metadata: + name: {{ template "cockroachdb.fullname" . }}-metrics + namespace: {{ .Release.Namespace | quote }} + labels: + helm.sh/chart: {{ template "cockroachdb.chart" . }} + app.kubernetes.io/name: {{ template "cockroachdb.name" . }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + {{- with .Values.serviceMonitor.service.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + annotations: + {{- with .Values.serviceMonitor.service.annotations }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + type: ClusterIP + ports: + {{- $ports := .Values.service.ports }} + # Only http port should be exposed + - name: {{ $ports.http.name | quote }} + port: {{ $ports.http.port | int64 }} + targetPort: http + selector: + app.kubernetes.io/name: {{ template "cockroachdb.name" . }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- with .Values.statefulset.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/cockroachdb/templates/serviceMonitor.yaml b/cockroachdb/templates/serviceMonitor.yaml index 42f2390b..95fa3dc0 100644 --- a/cockroachdb/templates/serviceMonitor.yaml +++ b/cockroachdb/templates/serviceMonitor.yaml @@ -26,7 +26,7 @@ spec: matchLabels: app.kubernetes.io/name: {{ template "cockroachdb.name" . }} app.kubernetes.io/instance: {{ .Release.Name | quote }} - {{- with .Values.service.discovery.labels }} + {{- with .Values.serviceMonitor.service.labels }} {{- toYaml . | nindent 6 }} {{- end }} {{- with .Values.labels }} @@ -42,6 +42,9 @@ spec: endpoints: - port: {{ $ports.http.name | quote }} path: /_status/vars + {{- if .Values.tls.enabled }} + scheme: https + {{- end }} {{- if $serviceMonitor.interval }} interval: {{ $serviceMonitor.interval }} {{- end }} @@ -51,4 +54,5 @@ spec: {{- if .Values.serviceMonitor.tlsConfig }} tlsConfig: {{ toYaml .Values.serviceMonitor.tlsConfig | nindent 6 }} {{- end }} + relabelings: {{ tpl (toYaml .Values.serviceMonitor.relabelingConfig) . | nindent 6 }} {{- end }} diff --git a/cockroachdb/values.yaml b/cockroachdb/values.yaml index 5d007624..6e37508d 100644 --- a/cockroachdb/values.yaml +++ b/cockroachdb/values.yaml @@ -350,10 +350,30 @@ serviceMonitor: # Limits the ServiceMonitor to the current namespace if set to `true`. namespaced: false + # Service + # This service is used to scrape the CockroachDB Pods. + service: + # Additional labels to apply to this Service. + labels: + app.kubernetes.io/component: cockroachdb-metrics + # Additional annotations to apply to this Service. + annotations: {} + + # tlsConfig: TLS configuration to use when scraping the endpoint. # Of type: https://github.com/coreos/prometheus-operator/blob/main/Documentation/api.md#tlsconfig tlsConfig: {} + # relabelingConfig: List of ServiceMonitor relabeling configurations. + # See: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config + relabelingConfig: + - replacement: cockroachdb_cluster_name + targetLabel: "{{ index .Values.conf `cluster-name` }}" +# - sourceLabels: [__meta_kubernetes_namespace] +# targetLabel: namespace +# - sourceLabels: [__meta_kubernetes_pod_name] +# targetLabel: pod + # CockroachDB's data persistence. # If neither `persistentVolume` nor `hostPath` is used, then data will be # persisted in ad-hoc `emptyDir`.