Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions templates/monitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ spec:
endpoints:
- port: kamon
path: /metrics
{{- if .Values.monitoring.serviceMonitor.interval }}
interval: {{ .Values.monitoring.serviceMonitor.interval }}
{{- end }}
{{- if .Values.monitoring.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.monitoring.serviceMonitor.scrapeTimeout }}
{{- end }}
{{- if .Values.monitoring.serviceMonitor.honorLabels }}
honorLabels: {{ .Values.monitoring.serviceMonitor.honorLabels }}
{{- end }}
{{- if .Values.monitoring.serviceMonitor.metricRelabelings }}
metricRelabelings: {{- include "common.tplvalues.render" ( dict "value" .Values.monitoring.serviceMonitor.metricRelabelings "context" $) | nindent 8 }}
{{- end }}
{{- if .Values.monitoring.serviceMonitor.relabelings }}
relabelings: {{- include "common.tplvalues.render" ( dict "value" .Values.monitoring.serviceMonitor.relabelings "context" $) | nindent 8 }}
{{- end }}
selector:
matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
namespaceSelector:
Expand Down
157 changes: 157 additions & 0 deletions tests/monitor_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,160 @@ tests:
- equal:
path: metadata.labels["app.kubernetes.io/managed-by"]
value: Helm

- it: should omit all optional endpoint fields by default
capabilities:
apiVersions:
- monitoring.coreos.com/v1
template: monitor.yml
asserts:
- isKind:
of: ServiceMonitor
- notExists:
path: spec.endpoints[0].interval
- notExists:
path: spec.endpoints[0].scrapeTimeout
- notExists:
path: spec.endpoints[0].honorLabels
- notExists:
path: spec.endpoints[0].metricRelabelings
- notExists:
path: spec.endpoints[0].relabelings

- it: should keep honorLabels omitted when explicitly set to false
set:
monitoring.serviceMonitor.honorLabels: false
capabilities:
apiVersions:
- monitoring.coreos.com/v1
template: monitor.yml
asserts:
- isKind:
of: ServiceMonitor
- notExists:
path: spec.endpoints[0].honorLabels

- it: should render honorLabels when set to true
set:
monitoring.serviceMonitor.honorLabels: true
capabilities:
apiVersions:
- monitoring.coreos.com/v1
template: monitor.yml
asserts:
- equal:
path: spec.endpoints[0].honorLabels
value: true

- it: should render interval when set
set:
monitoring.serviceMonitor.interval: 30s
capabilities:
apiVersions:
- monitoring.coreos.com/v1
template: monitor.yml
asserts:
- equal:
path: spec.endpoints[0].interval
value: 30s

- it: should render scrapeTimeout when set
set:
monitoring.serviceMonitor.scrapeTimeout: 10s
capabilities:
apiVersions:
- monitoring.coreos.com/v1
template: monitor.yml
asserts:
- equal:
path: spec.endpoints[0].scrapeTimeout
value: 10s

- it: should render metricRelabelings when set
set:
monitoring.serviceMonitor.metricRelabelings:
- sourceLabels: [__name__]
regex: expensive_metric.*
action: drop
capabilities:
apiVersions:
- monitoring.coreos.com/v1
template: monitor.yml
asserts:
- equal:
path: spec.endpoints[0].metricRelabelings
value:
- sourceLabels: [__name__]
regex: expensive_metric.*
action: drop

- it: should render relabelings when set
set:
monitoring.serviceMonitor.relabelings:
- sourceLabels: [__meta_kubernetes_pod_node_name]
targetLabel: node
capabilities:
apiVersions:
- monitoring.coreos.com/v1
template: monitor.yml
asserts:
- equal:
path: spec.endpoints[0].relabelings
value:
- sourceLabels: [__meta_kubernetes_pod_node_name]
targetLabel: node

- it: should template relabelings values via common.tplvalues.render
release:
name: my-stream
set:
monitoring.serviceMonitor.relabelings:
- targetLabel: release
replacement: "{{ .Release.Name }}"
capabilities:
apiVersions:
- monitoring.coreos.com/v1
template: monitor.yml
asserts:
- equal:
path: spec.endpoints[0].relabelings
value:
- targetLabel: release
replacement: my-stream

- it: should template metricRelabelings values via common.tplvalues.render
set:
monitoring.serviceMonitor.metricRelabelings:
- sourceLabels: [namespace]
regex: "{{ .Release.Namespace }}"
targetLabel: kube_namespace
capabilities:
apiVersions:
- monitoring.coreos.com/v1
template: monitor.yml
asserts:
- equal:
path: spec.endpoints[0].metricRelabelings
value:
- sourceLabels: [namespace]
regex: NAMESPACE
targetLabel: kube_namespace

- it: should render all endpoint fields together when set
set:
monitoring.serviceMonitor.interval: 30s
monitoring.serviceMonitor.scrapeTimeout: 10s
monitoring.serviceMonitor.honorLabels: true
capabilities:
apiVersions:
- monitoring.coreos.com/v1
template: monitor.yml
asserts:
- equal:
path: spec.endpoints
value:
- port: kamon
path: /metrics
interval: 30s
scrapeTimeout: 10s
honorLabels: true
20 changes: 20 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,26 @@ ingress:
monitoring:
## Enable the creation of a ServiceMonitor object for Stream if the cluster has the monitoring.coreos.com/v1 capability
enabled: true
## Prometheus Operator ServiceMonitor configuration
serviceMonitor:
## Chooses the metric's labels on collisions with target labels
honorLabels: false
## Interval at which metrics should be scraped.
## @ref https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api-reference/api.md#monitoring.coreos.com/v1.Endpoint
## @example
## interval: 10s
##
interval: ""
## Timeout after which the scrape is ended
## @ref https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api-reference/api.md#monitoring.coreos.com/v1.Endpoint
## @example
## scrapeTimeout: 10s
##
scrapeTimeout: ""
## Specify additional relabeling of metrics
metricRelabelings: []
## Specify general relabeling
relabelings: []
## Configure the Play secret for the Stream instance.
## As this is used for cryptographic purposes, it should be fetched
## from the environment.
Expand Down
Loading