forked from CrunchyData/postgres-operator-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prometheus): Adding PodMonitor to autoconfigure prometheusOperator
- Loading branch information
1 parent
fab0794
commit 28f39fd
Showing
4 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "postgres.name" -}} | ||
{{- default .Chart.Name .Values.name | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "postgres.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "postgres.labels" -}} | ||
helm.sh/chart: {{ include "postgres.chart" . }} | ||
{{ include "postgres.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "postgres.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "postgres.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{{- if and .Values.monitoring .Values.podMonitor.enabled -}} | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: PodMonitor | ||
metadata: | ||
name: {{ default .Release.Name .Values.name }} | ||
{{- if .Values.podMonitor.namespace }} | ||
namespace: {{ .Values.podMonitor.namespace | quote }} | ||
{{- else }} | ||
namespace: {{ .Release.Namespace }} | ||
{{- end }} | ||
labels: | ||
{{- include "postgres.labels" . | nindent 4 }} | ||
{{- if .Values.podMonitor.additionalLabels }} | ||
{{- toYaml .Values.podMonitor.additionalLabels | nindent 4 }} | ||
{{- end }} | ||
spec: | ||
namespaceSelector: | ||
matchNames: | ||
- {{ .Release.Namespace }} | ||
podMetricsEndpoints: | ||
- interval: {{ .Values.podMonitor.interval }} | ||
scrapeTimeout: {{ .Values.podMonitor.scrapeTimeout }} | ||
relabelings: | ||
- sourceLabels: [__meta_kubernetes_namespace] | ||
action: replace | ||
targetLabel: kubernetes_namespace | ||
- sourceLabels: [__meta_kubernetes_pod_name] | ||
targetLabel: pod | ||
# Because of the https://github.com/prometheus-operator/prometheus-operator/issues/5003 we cannot use the version with empty separator from monitoring chart. | ||
#- sourceLabels: [__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_cluster,__meta_kubernetes_pod_label_pg_cluster] | ||
# targetLabel: cluster | ||
# separator: '' | ||
# replacement: '$1' | ||
- sourceLabels: [__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_cluster,__meta_kubernetes_pod_label_pg_cluster] | ||
targetLabel: cluster | ||
separator: ';' | ||
regex: '(.*);(.*)' | ||
action: replace | ||
replacement: '$1$2' | ||
- sourceLabels: [__meta_kubernetes_namespace,cluster] | ||
targetLabel: pg_cluster | ||
separator: ":" | ||
replacement: '$1$2' | ||
- sourceLabels: [__meta_kubernetes_pod_ip] | ||
targetLabel: ip | ||
replacement: '$1' | ||
# Because of the https://github.com/prometheus-operator/prometheus-operator/issues/5003 we cannot use the version with empty separator from monitoring chart. | ||
#- sourceLabels: [__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_instance,__meta_kubernetes_pod_label_deployment_name] | ||
# targetLabel: deployment | ||
# replacement: '$1' | ||
# separator: '' | ||
- sourceLabels: [__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_instance,__meta_kubernetes_pod_label_deployment_name] | ||
targetLabel: deployment | ||
separator: ';' | ||
regex: '(.*);(.*)' | ||
action: replace | ||
replacement: '$1$2' | ||
# Because of the https://github.com/prometheus-operator/prometheus-operator/issues/5003 we cannot use the version with empty separator from monitoring chart. | ||
#- sourceLabels: [__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_role,__meta_kubernetes_pod_label_role] | ||
# targetLabel: role | ||
# replacement: '$1' | ||
# separator: '' | ||
- sourceLabels: [__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_role,__meta_kubernetes_pod_label_role] | ||
targetLabel: role | ||
separator: ';' | ||
regex: '(.*);(.*)' | ||
action: replace | ||
replacement: '$1$2' | ||
targetPort: 9187 | ||
selector: | ||
matchLabels: | ||
postgres-operator.crunchydata.com/cluster: {{ .Release.Name }} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters