Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[alertmanager] Add prometheus servicemonitor support #4631

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion charts/alertmanager/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ home: https://prometheus.io/
icon: https://raw.githubusercontent.com/prometheus/prometheus.github.io/master/assets/prometheus_logo-cb55bb5c346.png
sources:
- https://github.com/prometheus/alertmanager
dependencies:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
- name: prometheus-operator-crds
version: ">=0.1.0"
condition: crds.enabled
repository: "https://prometheus-community.github.io/helm-charts"
type: application
version: 1.11.0
version: 1.12.0
appVersion: v0.27.0
kubeVersion: ">=1.19.0-0"
keywords:
Expand Down
85 changes: 85 additions & 0 deletions charts/alertmanager/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "alertmanager.fullname" . }}-alertmanager
namespace: {{ template "alertmanager.namespace" . }}
labels:
{{- include "alertmanager.labels" . | nindent 4 }}
{{- with .Values.serviceMonitor.additionalLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.serviceMonitor.attachMetadata }}
attachMetadata:
node: true
{{- end }}
endpoints:
- port: http
path: "/metrics"
enableHttp2: {{ .Values.serviceMonitor.enableHttp2 }}
{{- if .Values.serviceMonitor.interval }}
interval: {{ .Values.serviceMonitor.interval }}
{{- end }}
{{- if .Values.serviceMonitor.proxyUrl }}
proxyUrl: {{ .Values.serviceMonitor.proxyUrl}}
{{- end }}
{{- if .Values.serviceMonitor.scheme }}
scheme: {{ .Values.serviceMonitor.scheme }}
{{- end }}
{{- if .Values.serviceMonitor.tlsConfig }}
tlsConfig: {{- toYaml .Values.serviceMonitor.tlsConfig | nindent 6 }}
{{- end }}
{{- if .Values.serviceMonitor.metricRelabelings }}
metricRelabelings: {{- tpl (toYaml .Values.serviceMonitor.metricRelabelings | nindent 6) . }}
{{- end }}
{{- if .Values.serviceMonitor.relabelings }}
relabelings: {{- toYaml .Values.serviceMonitor.relabelings | nindent 6 }}
{{- end }}
{{- range .Values.serviceMonitor.additionalEndpoints }}
- port: {{ .port }}
{{- if or $.Values.serviceMonitor.interval .interval }}
interval: {{ default $.Values.serviceMonitor.interval .interval }}
{{- end }}
{{- if or $.Values.serviceMonitor.proxyUrl .proxyUrl }}
proxyUrl: {{ default $.Values.serviceMonitor.proxyUrl .proxyUrl }}
{{- end }}
{{- if or $.Values.serviceMonitor.scheme .scheme }}
scheme: {{ default $.Values.serviceMonitor.scheme .scheme }}
{{- end }}
{{- if or $.Values.serviceMonitor.tlsConfig .tlsConfig }}
tlsConfig: {{- default $.Values.serviceMonitor.tlsConfig .tlsConfig | toYaml | nindent 6 }}
{{- end }}
path: {{ .path }}
{{- if or $.Values.serviceMonitor.metricRelabelings .metricRelabelings }}
metricRelabelings: {{- tpl (default $.Values.serviceMonitor.metricRelabelings .metricRelabelings | toYaml | nindent 6) . }}
{{- end }}
{{- if or $.Values.serviceMonitor.relabelings .relabelings }}
relabelings: {{- default $.Values.serviceMonitor.relabelings .relabelings | toYaml | nindent 6 }}
{{- end }}
{{- end }}
{{- if .Values.serviceMonitor.jobLabel }}
jobLabel: {{ .Values.serviceMonitor.jobLabel | quote }}
{{- end }}
keepDroppedTargets: {{ .Values.serviceMonitor.keepDroppedTargets }}
labelLimit: {{ .Values.serviceMonitor.labelLimit }}
labelNameLengthLimit: {{ .Values.serviceMonitor.labelNameLengthLimit }}
labelValueLengthLimit: {{ .Values.serviceMonitor.labelValueLengthLimit }}
namespaceSelector:
matchNames:
- {{ printf "%s" (include "alertmanager.namespace" .) | quote }}
{{- if .Values.serviceMonitor.podTargetLabels }}
podTargetLabels: {{ .Values.serviceMonitor.podTargetLabels }}
{{- end }}
sampleLimit: {{ .Values.serviceMonitor.sampleLimit }}
selector:
matchLabels:
{{- include "alertmanager.selectorLabels" . | nindent 6 }}
{{- with .Values.service.labels }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- if .Values.serviceMonitor.targetLabels }}
targetLabels: {{ toYaml .Values.serviceMonitor.targetLabels | nindent 4 }}
{{- end }}
targetLimit: {{ .Values.serviceMonitor.targetLimit }}
{{- end }}
159 changes: 141 additions & 18 deletions charts/alertmanager/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

crds:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
enabled: false

replicaCount: 1

# Number of old history to retain to allow rollback
Expand All @@ -22,7 +25,8 @@ extraArgs: {}

## Additional Alertmanager Secret mounts
# Defines additional mounts with secrets. Secrets must be manually created in the namespace.
extraSecretMounts: []
extraSecretMounts:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
[]
# - name: secret-files
# mountPath: /etc/secrets
# subPath: ""
Expand Down Expand Up @@ -54,7 +58,8 @@ schedulerName: ""

podSecurityContext:
fsGroup: 65534
dnsConfig: {}
dnsConfig:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
{}
# nameservers:
# - 1.2.3.4
# searches:
Expand All @@ -64,7 +69,8 @@ dnsConfig: {}
# - name: ndots
# value: "2"
# - name: edns0
hostAliases: []
Arabus marked this conversation as resolved.
Show resolved Hide resolved
hostAliases:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
[]
# - ip: "127.0.0.1"
# hostnames:
# - "foo.local"
Expand Down Expand Up @@ -109,8 +115,10 @@ service:
type: ClusterIP
port: 9093
clusterPort: 9094
loadBalancerIP: "" # Assign ext IP when Service type is LoadBalancer
loadBalancerSourceRanges: [] # Only allow access to loadBalancerIP from these IPs
# Assign ext IP when Service type is LoadBalancer
loadBalancerIP: ""
# Only allow access to loadBalancerIP from these IPs
loadBalancerSourceRanges: []
# if you want to force a specific nodePort. Must be use with service.type=NodePort
# nodePort:

Expand Down Expand Up @@ -141,10 +149,114 @@ servicePerReplica:
#
type: ClusterIP

## Configuration for creating a ServiceMonitor for AlertManager
##
serviceMonitor:
## If true, a ServiceMonitor will be created for the AlertManager service.
##
enabled: false

## Additional labels
##
additionalLabels: {}

## Additional metadata which is added to the discovered targets
## Will attempt to add node metatadata if enabled. Only valid in Prometheus versions 2.37.0 and newer.
attachMetadata: false

## Selects the label from the associated Kubernetes Service object
## which will be used as the job label for all metrics.
## Defaults to service name if unspecified.
jobLabel: ""

## Per-scrape limit on the number of targets dropped by relabeling that will be
## kept in memory. 0 means no limit. Only valid in Prometheus versions 2.47.0 and newer.
keepDroppedTargets: 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

## Defines the labels which are transferred from the associated Kubernetes
## Pod object onto the ingested metrics.
##
podTargetLabels: []

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

## TargetLabels defines the labels which are transferred from the associated
## Kubernetes Service object onto the ingested metrics.
##
targetLabels: []

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

## Endpoint options
#
## enableHttp2: Whether to enable HTTP2.
## See https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#endpoint
##
enableHttp2: true

## Interval at which Prometheus scrapes the metrics from the target. If empty, Prometheus uses the global scrape interval
##
interval: ""

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

## scheme: HTTP scheme to use for scraping. Can be used with `tlsConfig` for example if using istio mTLS.
##
scheme: ""

## tlsConfig: TLS configuration to use when scraping the endpoint. For example if using istio mTLS.
## Of type: https://github.com/coreos/prometheus-operator/blob/main/Documentation/api.md#tlsconfig
##
tlsConfig: {}

## MetricRelabelConfigs to apply to samples after scraping, but before ingestion.
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#relabelconfig
##
metricRelabelings: []
# - action: keep
# regex: 'kube_(daemonset|deployment|pod|namespace|node|statefulset).+'
# sourceLabels: [__name__]

## RelabelConfigs to apply to samples before scraping
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#relabelconfig
##
relabelings: []
# - sourceLabels: [__meta_kubernetes_pod_node_name]
# separator: ;
# regex: ^(.*)$
# targetLabel: nodename
# replacement: $1
# action: replace

## Additional Endpoints
##
additionalEndpoints: []
# - port: oauth-metrics
# path: /metrics

ingress:
enabled: false
className: ""
annotations: {}
Arabus marked this conversation as resolved.
Show resolved Hide resolved
annotations:
{}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
Expand Down Expand Up @@ -201,7 +313,8 @@ ingressPerReplica:
#
prefix: "alertmanager"

resources: {}
Arabus marked this conversation as resolved.
Show resolved Hide resolved
resources:
{}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
Expand Down Expand Up @@ -233,7 +346,8 @@ podAntiAffinityTopologyKey: kubernetes.io/hostname

## Topology spread constraints rely on node labels to identify the topology domain(s) that each Node is in.
## Ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
topologySpreadConstraints: []
Arabus marked this conversation as resolved.
Show resolved Hide resolved
topologySpreadConstraints:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
[]
# - maxSkew: 1
# topologyKey: failure-domain.beta.kubernetes.io/zone
# whenUnsatisfiable: DoNotSchedule
Expand All @@ -255,7 +369,8 @@ podAnnotations: {}
podLabels: {}

# Ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/
podDisruptionBudget: {}
Arabus marked this conversation as resolved.
Show resolved Hide resolved
podDisruptionBudget:
{}
# maxUnavailable: 1
# minAvailable: 1

Expand All @@ -274,7 +389,8 @@ persistence:
- ReadWriteOnce
size: 50Mi

configAnnotations: {}
configAnnotations:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
{}
## For example if you want to provide private data from a secret vault
## https://github.com/banzaicloud/bank-vaults/tree/main/charts/vault-secrets-webhook
## P.s.: Add option `configMapMutation: true` for vault-secrets-webhook
Expand All @@ -287,11 +403,12 @@ configAnnotations: {}

config:
enabled: true
global: {}
Arabus marked this conversation as resolved.
Show resolved Hide resolved
global:
{}
# slack_api_url: ''

templates:
- '/etc/alertmanager/*.tmpl'
- "/etc/alertmanager/*.tmpl"

receivers:
- name: default-receiver
Expand Down Expand Up @@ -334,17 +451,20 @@ configmapReload:
extraArgs: {}

## Optionally specify extra list of additional volumeMounts
extraVolumeMounts: []
Arabus marked this conversation as resolved.
Show resolved Hide resolved
extraVolumeMounts:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
[]
# - name: extras
# mountPath: /usr/share/extras
# readOnly: true

## Optionally specify extra environment variables to add to alertmanager container
extraEnv: []
extraEnv:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
[]
# - name: FOO
# value: BAR

securityContext: {}
securityContext:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
{}
# capabilities:
# drop:
# - ALL
Expand All @@ -357,18 +477,21 @@ templates: {}
# alertmanager.tmpl: |-

## Optionally specify extra list of additional volumeMounts
extraVolumeMounts: []
extraVolumeMounts:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
[]
# - name: extras
# mountPath: /usr/share/extras
# readOnly: true

## Optionally specify extra list of additional volumes
extraVolumes: []
extraVolumes:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
[]
# - name: extras
# emptyDir: {}

## Optionally specify extra environment variables to add to alertmanager container
extraEnv: []
extraEnv:
Arabus marked this conversation as resolved.
Show resolved Hide resolved
[]
# - name: FOO
# value: BAR

Expand Down