Skip to content

Commit

Permalink
add interval to prometheus service monitor
Browse files Browse the repository at this point in the history
We have a use-case where we need to modify the default scrape interval
on a number of apps, including coredns.

This PR simply adds support to change it. (It should be backwards
compatible with existing implmentations.)

Test/verification:
```
$ helm template charts/coredns --set prometheus.monitor.enabled=true --set prometheus.monitor.interval=60s |grep servicemonitor.yaml -A 22
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: RELEASE-NAME-coredns
  labels:
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "RELEASE-NAME"
    helm.sh/chart: "coredns-1.16.5"
    k8s-app: "coredns"
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "CoreDNS"
    app.kubernetes.io/name: coredns
spec:
  selector:
    matchLabels:
      app.kubernetes.io/instance: "RELEASE-NAME"
      k8s-app: "coredns"
      app.kubernetes.io/name: coredns
      app.kubernetes.io/component: metrics
  endpoints:
    - port: metrics
      interval: 60s
```

Signed-off-by: Craig Sebenik <csebenik@aurora.tech>
  • Loading branch information
craig5 authored and mrueg committed Feb 7, 2022
1 parent 939b013 commit 3c0c1a5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions charts/coredns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The command removes all the Kubernetes components associated with the chart and
| `prometheus.monitor.enabled` | Set this to `true` to create ServiceMonitor for Prometheus operator | `false` |
| `prometheus.monitor.additionalLabels` | Additional labels that can be used so ServiceMonitor will be discovered by Prometheus | {} |
| `prometheus.monitor.namespace` | Selector to select which namespaces the Endpoints objects are discovered from. | `""` |
| `prometheus.monitor.interval` | Scrape interval for polling the metrics endpoint. (E.g. "30s") | `""` |
| `service.clusterIP` | IP address to assign to service | `""` |
| `service.loadBalancerIP` | IP address to assign to load balancer (if supported) | `""` |
| `service.externalIPs` | External IP addresses | [] |
Expand Down
3 changes: 3 additions & 0 deletions charts/coredns/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ spec:
app.kubernetes.io/component: metrics
endpoints:
- port: metrics
{{- if .Values.prometheus.monitor.interval }}
interval: {{ .Values.prometheus.monitor.interval }}
{{- end }}
{{- end }}
1 change: 1 addition & 0 deletions charts/coredns/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ prometheus:
enabled: false
additionalLabels: {}
namespace: ""
interval: ""

service:
# clusterIP: ""
Expand Down

0 comments on commit 3c0c1a5

Please sign in to comment.