Skip to content

Commit

Permalink
[alertmanager] add servicemonitor
Browse files Browse the repository at this point in the history
Signed-off-by: junot <[email protected]>
  • Loading branch information
junotx committed Apr 2, 2024
1 parent 7151996 commit 1d6e36a
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/alertmanager/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ icon: https://raw.githubusercontent.com/prometheus/prometheus.github.io/master/a
sources:
- https://github.com/prometheus/alertmanager
type: application
version: 1.8.2
version: 1.8.3
appVersion: v0.26.0
kubeVersion: ">=1.19.0-0"
keywords:
Expand Down
19 changes: 19 additions & 0 deletions charts/alertmanager/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,22 @@ Allow overriding alertmanager namespace
{{- .Release.Namespace -}}
{{- end -}}
{{- end -}}

{{/* Sets default scrape limits for servicemonitor */}}
{{- define "servicemonitor.scrapeLimits" -}}
{{- with .sampleLimit }}
sampleLimit: {{ . }}
{{- end }}
{{- with .targetLimit }}
targetLimit: {{ . }}
{{- end }}
{{- with .labelLimit }}
labelLimit: {{ . }}
{{- end }}
{{- with .labelNameLengthLimit }}
labelNameLengthLimit: {{ . }}
{{- end }}
{{- with .labelValueLengthLimit }}
labelValueLengthLimit: {{ . }}
{{- end }}
{{- end }}
64 changes: 64 additions & 0 deletions charts/alertmanager/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{{- if .Values.prometheus.monitor.enabled }}
{{- $apiVersion := .Values.prometheus.monitor.apiVersion | default "monitoring.coreos.com/v1" }}
{{- if .Capabilities.APIVersions.Has (printf "%s/ServiceMonitor" $apiVersion) }}
apiVersion: {{ $apiVersion }}
kind: ServiceMonitor
metadata:
name: {{ include "alertmanager.fullname" . }}
namespace: {{ include "alertmanager.namespace" . }}
labels:
{{- include "alertmanager.labels" . | nindent 4 }}
{{- with .Values.prometheus.monitor.additionalLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
jobLabel: {{ default "app.kubernetes.io/name" .Values.prometheus.monitor.jobLabel }}
{{- include "servicemonitor.scrapeLimits" .Values.prometheus.monitor | nindent 2 }}
{{- with .Values.prometheus.monitor.podTargetLabels }}
podTargetLabels:
{{- toYaml . | nindent 4 }}
{{- end }}
selector:
matchLabels:
{{- with .Values.prometheus.monitor.selectorOverride }}
{{- toYaml . | nindent 6 }}
{{- else }}
{{- include "alertmanager.selectorLabels" . | nindent 6 }}
{{- end }}
{{- with .Values.prometheus.monitor.attachMetadata }}
attachMetadata:
{{- toYaml . | nindent 4 }}
{{- end }}
endpoints:
- port: http
scheme: {{ .Values.prometheus.monitor.scheme }}
{{- with .Values.prometheus.monitor.basicAuth }}
basicAuth:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.prometheus.monitor.bearerTokenFile }}
bearerTokenFile: {{ . }}
{{- end }}
{{- with .Values.prometheus.monitor.tlsConfig }}
tlsConfig:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.prometheus.monitor.proxyUrl }}
proxyUrl: {{ . }}
{{- end }}
{{- with .Values.prometheus.monitor.interval }}
interval: {{ . }}
{{- end }}
{{- with .Values.prometheus.monitor.scrapeTimeout }}
scrapeTimeout: {{ . }}
{{- end }}
{{- with .Values.prometheus.monitor.relabelings }}
relabelings:
{{- tpl (toYaml .) $ | nindent 8 }}
{{- end }}
{{- with .Values.prometheus.monitor.metricRelabelings }}
metricRelabelings:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
105 changes: 104 additions & 1 deletion charts/alertmanager/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@
"type": "string"
},
"global": {
"properties": {},
"properties": {
"imagePullSecrets": {
"type": "array"
}
},
"type": "object"
},
"hostAliases": {
Expand Down Expand Up @@ -338,6 +342,105 @@
"priorityClassName": {
"type": "string"
},
"prometheus": {
"properties": {
"monitor": {
"properties": {
"additionalLabels": {
"properties": {
"app.kubernetes.io/vendor": {
"type": "string"
}
},
"type": "object"
},
"apiVersion": {
"type": "string"
},
"attachMetadata": {
"properties": {},
"type": "object"
},
"basicAuth": {
"properties": {},
"type": "object"
},
"bearerTokenFile": {
"type": "null"
},
"enabled": {
"type": "boolean"
},
"interval": {
"type": "string"
},
"jobLabel": {
"type": "string"
},
"labelLimit": {
"type": "integer"
},
"labelNameLengthLimit": {
"type": "integer"
},
"labelValueLengthLimit": {
"type": "integer"
},
"metricRelabelings": {
"type": "array"
},
"podTargetLabels": {
"type": "array"
},
"proxyUrl": {
"type": "string"
},
"relabelings": {
"items": {
"properties": {
"action": {
"type": "string"
},
"regex": {
"type": "string"
},
"sourceLabels": {
"items": {
"type": "string"
},
"type": "array"
}
},
"type": "object"
},
"type": "array"
},
"sampleLimit": {
"type": "integer"
},
"scheme": {
"type": "string"
},
"scrapeTimeout": {
"type": "string"
},
"selectorOverride": {
"properties": {},
"type": "object"
},
"targetLimit": {
"type": "integer"
},
"tlsConfig": {
"properties": {},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
},
"readinessProbe": {
"properties": {
"httpGet": {
Expand Down
61 changes: 61 additions & 0 deletions charts/alertmanager/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,64 @@ testFramework:
annotations:
"helm.sh/hook": test-success
# "helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"

prometheus:
monitor:
enabled: true

additionalLabels:
app.kubernetes.io/vendor: kubesphere

jobLabel: ""

# List of pod labels to add to node exporter metrics
# https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#servicemonitor
podTargetLabels: []

scheme: http
basicAuth: {}
bearerTokenFile:
tlsConfig: {}

## proxyUrl: URL of a proxy that should be used for scraping.
##
proxyUrl: ""

## Override serviceMonitor selector
##
selectorOverride: {}

## Attach node metadata to discovered targets. Requires Prometheus v2.35.0 and above.
##
attachMetadata: {}

relabelings:
- sourceLabels:
- service
regex: '^{{ include "alertmanager.fullname" . }}-headless$'
action: keep
metricRelabelings: []
interval: ""
scrapeTimeout: 10s
## prometheus.monitor.apiVersion ApiVersion for the serviceMonitor Resource(defaults to "monitoring.coreos.com/v1")
apiVersion: ""

## SampleLimit defines per-scrape limit on number of scraped samples that will be accepted.
##
sampleLimit: 0

## TargetLimit defines a limit on the number of scraped targets that will be accepted.
##
targetLimit: 0

## Per-scrape limit on number of labels that will be accepted for a sample. Only valid in Prometheus versions 2.27.0 and newer.
##
labelLimit: 0

## Per-scrape limit on length of labels name that will be accepted for a sample. Only valid in Prometheus versions 2.27.0 and newer.
##
labelNameLengthLimit: 0

## Per-scrape limit on length of labels value that will be accepted for a sample. Only valid in Prometheus versions 2.27.0 and newer.
##
labelValueLengthLimit: 0

0 comments on commit 1d6e36a

Please sign in to comment.