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 {{- if $dot.Values.metrics.serviceMonitor.labels }}
114 labels: {{- include "common.tplValue" ( dict "value" $dot.Values.metrics.serviceMonitor.labels "context" $dot) | nindent 2 }}
116 labels: {{- include "common.labels" (dict "labels" $labels "dot" $dot) | nindent 2 }}
121 Create service monitor template
123 {{- define "common.serviceMonitor" -}}
124 {{- $dot := default . .dot -}}
125 {{- $labels := default (dict) .labels -}}
126 apiVersion: monitoring.coreos.com/v1
129 {{- include "common.serviceMonitorMetadata" $dot | nindent 2 }}
132 - path: {{ default "/metrics" $dot.Values.metrics.serviceMonitor.path }}
133 {{- if $dot.Values.metrics.serviceMonitor.port }}
134 port: {{ $dot.Values.metrics.serviceMonitor.port }}
135 {{- else if $dot.Values.metrics.serviceMonitor.targetPort }}
136 targetPort: {{ $dot.Values.metrics.serviceMonitor.targetPort }}
140 {{- if $dot.Values.metrics.serviceMonitor.isHttps }}
142 {{- if $dot.Values.metrics.serviceMonitor.tlsConfig }}
143 tlsConfig: {{- include "common.tplValue" ( dict "value" $dot.Values.metrics.serviceMonitor.tlsConfig "context" $dot) | nindent 6 }}
146 insecureSkipVerify: true
149 {{- if $dot.Values.metrics.serviceMonitor.basicAuth.enabled }}
152 key: {{ $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretUserKey }}
153 {{- if $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretNameSuffix }}
154 name: {{ include "common.release" . }}-{{ $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretNameSuffix }}
156 name: {{ $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretName }}
159 key: {{ $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretPasswordKey }}
160 {{- if $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretNameSuffix }}
161 name: {{ include "common.release" . }}-{{ $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretNameSuffix }}
163 name: {{ $dot.Values.metrics.serviceMonitor.basicAuth.externalSecretName }}
166 {{- if $dot.Values.metrics.serviceMonitor.interval }}
167 interval: {{ $dot.Values.metrics.serviceMonitor.interval }}
169 {{- if $dot.Values.metrics.serviceMonitor.scrapeTimeout }}
170 scrapeTimeout: {{ $dot.Values.metrics.serviceMonitor.scrapeTimeout }}
172 {{- if $dot.Values.metrics.serviceMonitor.relabelings }}
173 relabelings: {{- include "common.tplValue" ( dict "value" $dot.Values.metrics.serviceMonitor.relabelings "context" $dot) | nindent 6 }}
175 {{- if $dot.Values.metrics.serviceMonitor.metricRelabelings }}
176 metricRelabelings: {{- include "common.tplValue" ( dict "value" $dot.Values.metrics.serviceMonitor.metricRelabelings "context" $dot) | nindent 6 }}
180 - {{ include "common.namespace" $dot }}
182 {{- if $dot.Values.metrics.serviceMonitor.selector }}
183 matchLabels: {{- include "common.tplValue" ( dict "value" $dot.Values.metrics.serviceMonitor.selector "context" $dot) | nindent 6 }}
185 matchLabels: {{- include "common.labels" (dict "labels" $labels "dot" $dot) | nindent 6 }}