2 # Copyright © 2021 Bell Canada
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 Resolve the name of a chart's serviceMonitor.
19 The default will be the chart name (or $dot.Values.nameOverride if set).
20 And the use of .Values.metrics.serviceMonitor.name overrides all.
22 - .Values.metrics.serviceMonitor.name: override default serviceMonitor (ie. chart) name
23 Example values file addition:
27 port: blueprints-processor-http
28 ## specify target port if name is not given to the port in the service definition
34 externalSecretName: mysecretname
35 externalSecretUserKey: login
36 externalSecretPasswordKey: password
38 ## Namespace in which Prometheus is running
40 # namespace: monitoring
42 ## Interval at which metrics should be scraped.
43 ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#endpoint
47 ## Timeout after which the scrape is ended
48 ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#endpoint
52 ## ServiceMonitor selector labels
53 ## ref: https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#prometheus-configuration
56 app: '{{ include "common.name" . }}'
57 chart: '{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}'
58 release: '{{ include "common.release" . }}'
59 heritage: '{{ .Release.Service }}'
61 ## RelabelConfigs to apply to samples before scraping
62 ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#relabelconfig
63 ## Value is evalued as a template
67 ## MetricRelabelConfigs to apply to samples before ingestion
68 ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#relabelconfig
69 ## Value is evalued as a template
74 # targetLabel: "__name__"
77 # replacement: 'example_prefix_$1'
81 Expand the serviceMonitor name for a chart.
83 {{- define "common.serviceMonitorName" -}}
84 {{- $name := default .Chart.Name .Values.nameOverride -}}
85 {{- default $name .Values.metrics.serviceMonitor.name | trunc 63 | trimSuffix "-" -}}
88 {{/* Define the metadata of serviceMonitor
89 The function takes from one to four arguments (inside a dictionary):
90 - .dot : environment (.)
91 - .suffix : a string which will be added at the end of the name (with a '-').
92 - .annotations: the annotations to add
93 - .labels : labels to add
95 {{ include "common.serviceMonitorMetadata" ( dict "suffix" "myService" "dot" .) }}
96 {{ include "common.serviceMonitorMetadata" ( dict "annotations" .Values.metrics.serviceMonitor.annotation "dot" .) }}
99 {{- define "common.serviceMonitorMetadata" -}}
100 {{- $dot := default . .dot -}}
101 {{- $annotations := default "" .annotations -}}
102 {{- $labels := default (dict) .labels -}}
103 {{- if $annotations -}}
105 {{ include "common.tplValue" (dict "value" $annotations "context" $dot) | indent 2 }}
107 name: {{ include "common.serviceMonitorName" $dot }}
108 {{- if $dot.Values.metrics.serviceMonitor.namespace }}
109 namespace: {{ $dot.Values.metrics.serviceMonitor.namespace }}
111 namespace: {{ include "common.namespace" $dot }}
113 labels: {{- include "common.labels" (dict "labels" $labels "dot" $dot) | nindent 2 }}
117 Create service monitor template
119 {{- define "common.serviceMonitor" -}}
120 {{- $dot := default . .dot -}}
121 {{- $labels := default (dict) .labels -}}
122 apiVersion: monitoring.coreos.com/v1
125 {{- include "common.serviceMonitorMetadata" $dot | nindent 2 }}
128 - path: {{ default "/metrics" $dot.Values.metrics.serviceMonitor.path }}
129 {{- if $dot.Values.metrics.serviceMonitor.port }}
130 port: {{ $dot.Values.metrics.serviceMonitor.port }}
131 {{- else if $dot.Values.metrics.serviceMonitor.targetPort }}
132 targetPort: {{ $dot.Values.metrics.serviceMonitor.targetPort }}
136 {{- if $dot.Values.metrics.serviceMonitor.basicAuth.enabled }}
139 key: {{ $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretUserKey }}
140 name: {{ $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretName }}
142 key: {{ $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretPasswordKey }}
143 name: {{ $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretName }}
145 {{- if $dot.Values.metrics.serviceMonitor.interval }}
146 interval: {{ $dot.Values.metrics.serviceMonitor.interval }}
148 {{- if $dot.Values.metrics.serviceMonitor.scrapeTimeout }}
149 scrapeTimeout: {{ $dot.Values.metrics.serviceMonitor.scrapeTimeout }}
151 {{- if $dot.Values.metrics.serviceMonitor.relabelings }}
152 relabelings: {{- include "common.tplValue" ( dict "value" $dot.Values.metrics.serviceMonitor.relabelings "context" $dot) | nindent 6 }}
154 {{- if $dot.Values.metrics.serviceMonitor.metricRelabelings }}
155 metricRelabelings: {{- include "common.tplValue" ( dict "value" $dot.Values.metrics.serviceMonitor.metricRelabelings "context" $dot) | nindent 6 }}
159 - {{ include "common.namespace" $dot }}
161 {{- if $dot.Values.metrics.serviceMonitor.selector }}
162 matchLabels: {{- include "common.tplValue" ( dict "value" $dot.Values.metrics.serviceMonitor.selector "context" $dot) | nindent 6 }}
164 matchLabels: {{- include "common.labels" (dict "labels" $labels "dot" $dot) | nindent 6 }}