Skip to content

Commit

Permalink
feat: Add ServiceMonitor for Prometheus operator (#58)
Browse files Browse the repository at this point in the history
* feat: Add ServiceMonitor for Prometheus operator

Backstage instances with the Prometheus /metrics endpoint configured [1]
can set `serviceMonitor.enabled` to allow prometheus to scrape it's metrics

Disabled by default.

[1] https://github.com/backstage/backstage/blob/master/contrib/docs/tutorials/prometheus-metrics.md

Signed-off-by: Nikolai R Kristiansen <nikolai.kristiansen@remarkable.no>

* chore: Adress review feedback

- Move to `metrics.serviceMonitor
- Document prometheus-operator and /metrics endpoint requirements
- Remove namespaceSelector config option
- Add commonLabels and commonAnnotations

Signed-off-by: Nikolai R Kristiansen <nikolai.kristiansen@remarkable.no>

* chore: Roll chart version

Signed-off-by: Nikolai R Kristiansen <nikolai.kristiansen@remarkable.no>

* chore: Link to latest master version of /metrics tutorial

Co-authored-by: Vincenzo Scamporlino <me@vinzscam.dev>
Signed-off-by: Nikolai R Kristiansen <nikolai.kristiansen@remarkable.no>

* fix: allow templating for labels and annotations

Signed-off-by: Nikolai R Kristiansen <nikolai.kristiansen@remarkable.no>

---------

Signed-off-by: Nikolai R Kristiansen <nikolai.kristiansen@remarkable.no>
Co-authored-by: Vincenzo Scamporlino <me@vinzscam.dev>
  • Loading branch information
nikolaik and vinzscam authored Feb 22, 2023
1 parent 965b79a commit 37b9b30
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
8 changes: 4 additions & 4 deletions charts/backstage/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
version: 1.16.0
version: 1.17.1
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 11.6.6
digest: sha256:5f0f118ac2ae2be90edd9c6952da4bcb41feb815b39a575e23ec2a0a9244d9cd
generated: "2022-06-14T21:14:00.148159+01:00"
version: 11.9.13
digest: sha256:e24333442ed7bee23fd4d0ae522d3e8c56fd212e4ff33f020ad12f1528ae78e9
generated: "2023-02-09T14:22:13.567819+01:00"
2 changes: 1 addition & 1 deletion charts/backstage/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.16.0
version: 0.17.0

dependencies:
- name: common
Expand Down
9 changes: 8 additions & 1 deletion charts/backstage/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Backstage Helm Chart

![Version: 0.16.0](https://img.shields.io/badge/Version-0.16.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
![Version: 0.17.0](https://img.shields.io/badge/Version-0.17.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

A Helm chart for deploying a Backstage application

Expand Down Expand Up @@ -130,6 +130,13 @@ The command removes all the Kubernetes components associated with the chart and
| ingress.tls.enabled | Enable TLS configuration for the host defined at `ingress.host` parameter | bool | `false` |
| ingress.tls.secretName | The name to which the TLS Secret will be called | string | `""` |
| kubeVersion | Override Kubernetes version | string | `""` |
| metrics | Metrics configuration | object | `{"serviceMonitor":{"annotations":{},"enabled":false,"interval":null,"labels":{},"path":"/metrics"}}` |
| metrics.serviceMonitor | ServiceMonitor configuration <br /> Allows configuring your backstage instance as a scrape target for [Prometheus](https://github.com/prometheus/prometheus) using a ServiceMonitor custom resource that [Prometheus Operator](https://github.com/prometheus-operator/prometheus-operator) can understand. | object | `{"annotations":{},"enabled":false,"interval":null,"labels":{},"path":"/metrics"}` |
| metrics.serviceMonitor.annotations | ServiceMonitor annotations | object | `{}` |
| metrics.serviceMonitor.enabled | If enabled, a ServiceMonitor resource for Prometheus Operator is created <br /> Prometheus Operator must be installed in your cluster prior to enabling. | bool | `false` |
| metrics.serviceMonitor.interval | ServiceMonitor scrape interval | string | `nil` |
| metrics.serviceMonitor.labels | Additional ServiceMonitor labels | object | `{}` |
| metrics.serviceMonitor.path | ServiceMonitor endpoint path <br /> Note that the /metrics endpoint is NOT present in a freshly scaffolded Backstage app. To setup, follow the [Prometheus metrics tutorial](https://github.com/backstage/backstage/blob/master/contrib/docs/tutorials/prometheus-metrics.md). | string | `"/metrics"` |
| nameOverride | String to partially override common.names.fullname | string | `""` |
| networkPolicy | Network policies <br /> Ref: https://kubernetes.io/docs/concepts/services-networking/network-policies/ | object | `{"egressRules":{"customRules":[]},"enabled":false,"externalAccess":{"from":[]}}` |
| networkPolicy.egressRules | Custom network policy rule | object | `{"customRules":[]}` |
Expand Down
37 changes: 37 additions & 0 deletions charts/backstage/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{- if .Values.metrics.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "common.names.fullname" $ }}
namespace: {{ .Release.Namespace | quote }}
{{- if or .Values.commonAnnotations .Values.metrics.serviceMonitor.annotations }}
annotations:
{{- if $.Values.commonAnnotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.annotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.metrics.serviceMonitor.annotations "context" $ ) | nindent 4 }}
{{- end }}
{{- end }}
labels: {{ include "common.labels.standard" . | nindent 4 }}
app.kubernetes.io/component: backstage
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.labels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.metrics.serviceMonitor.labels "context" $) | nindent 4 }}
{{- end }}
spec:
namespaceSelector:
matchNames:
- {{ .Release.Namespace | quote }}
selector:
matchLabels: {{ include "common.labels.standard" . | nindent 6 }}
app.kubernetes.io/component: backstage
endpoints:
- port: http-backend
path: {{ .Values.metrics.serviceMonitor.path }}
{{- with .Values.metrics.serviceMonitor.interval }}
interval: {{ . }}
{{- end }}
{{- end -}}
24 changes: 24 additions & 0 deletions charts/backstage/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,27 @@ serviceAccount:

# -- Auto-mount the service account token in the pod
automountServiceAccountToken: true

# -- Metrics configuration
metrics:

# -- ServiceMonitor configuration
# <br /> Allows configuring your backstage instance as a scrape target for [Prometheus](https://github.com/prometheus/prometheus) using a ServiceMonitor custom resource that [Prometheus Operator](https://github.com/prometheus-operator/prometheus-operator) can understand.
serviceMonitor:

# -- If enabled, a ServiceMonitor resource for Prometheus Operator is created
# <br /> Prometheus Operator must be installed in your cluster prior to enabling.
enabled: false

# -- ServiceMonitor annotations
annotations: {}

# -- Additional ServiceMonitor labels
labels: {}

# -- ServiceMonitor scrape interval
interval: null

# -- ServiceMonitor endpoint path
# <br /> Note that the /metrics endpoint is NOT present in a freshly scaffolded Backstage app. To setup, follow the [Prometheus metrics tutorial](https://github.com/backstage/backstage/blob/master/contrib/docs/tutorials/prometheus-metrics.md).
path: /metrics

0 comments on commit 37b9b30

Please sign in to comment.