Skip to content

Commit

Permalink
feat(helm): add support for metrics in the chart (#924)
Browse files Browse the repository at this point in the history
* Add support for metrics in chart

Signed-off-by: François BIBRON <[email protected]>

* feat: add serviceMonitor

Signed-off-by: François BIBRON <[email protected]>

* feat: fix values

Signed-off-by: François BIBRON <[email protected]>

* feat: fix values

Signed-off-by: François BIBRON <[email protected]>

* feat: fix values

Signed-off-by: François BIBRON <[email protected]>

* fix values and typos

Signed-off-by: François Bibron <[email protected]>

* fix typo

Signed-off-by: François Bibron <[email protected]>

* fix CS

---------

Signed-off-by: François BIBRON <[email protected]>
Signed-off-by: François Bibron <[email protected]>
Co-authored-by: Kévin Dunglas <[email protected]>
  • Loading branch information
coibib and dunglas authored Sep 9, 2024
1 parent ab445d3 commit 849c7b3
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
5 changes: 5 additions & 0 deletions charts/mercure/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ spec:
- name: http
containerPort: {{ .Values.service.targetPort }}
protocol: TCP
{{- if .Values.metrics.enabled }}
- name: metrics
containerPort: {{ .Values.metrics.port }}
protocol: TCP
{{- end }}
livenessProbe:
httpGet:
path: /healthz
Expand Down
24 changes: 24 additions & 0 deletions charts/mercure/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,27 @@ spec:
name: http
selector:
{{- include "mercure.selectorLabels" . | nindent 4 }}
---
{{- if .Values.metrics.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "mercure.fullname" . }}-metrics
labels:
{{- include "mercure.labels" . | nindent 4 }}
app.kubernetes.io/component: metrics
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}

spec:
type: ClusterIP
ports:
- port: {{ .Values.metrics.port }}
targetPort: metrics
protocol: TCP
name: metrics
selector:
{{- include "mercure.selectorLabels" . | nindent 4 }}
{{- end }}
28 changes: 28 additions & 0 deletions charts/mercure/templates/serviceMonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "mercure.fullname" . }}-metrics
labels:
{{- include "mercure.labels" . | nindent 4 }}
app.kubernetes.io/component: metrics
spec:
selector:
matchLabels:
app.kubernetes.io/component: metrics
endpoints:
- port: metrics
{{- if .Values.metrics.serviceMonitor.interval }}
interval: {{ .Values.metrics.serviceMonitor.interval }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }}
{{- end }}
honorLabels: {{ .Values.metrics.serviceMonitor.honorLabels }}
{{- if .Values.metrics.serviceMonitor.relabelings }}
metricRelabelings: {{- toYaml .Values.metrics.serviceMonitor.relabelings | nindent 8 }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.relabelings }}
relabelings: {{- toYaml .Values.metrics.serviceMonitor.relabelings | nindent 6 }}
{{- end }}
{{- end }}
27 changes: 25 additions & 2 deletions charts/mercure/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ existingSecret: ""
# -- The license key for [the High Availability version](https://mercure.rocks/docs/hub/cluster) (not necessary is you use the FOSS version).
license: ""

metrics:
# -- Enable metrics. You must also add a `servers` block with a [`metrics` directive](https://caddyserver.com/docs/caddyfile/options#metrics) in the `globalOptions` value.
# servers {
# metrics
# }
enabled: false
# -- The port to use for exposing the metrics.
port: 2019

serviceMonitor:
# -- Whether to create a ServiceMonitor for Prometheus Operator.
enabled: false
# -- The interval to use for the ServiceMonitor to scrape the metrics.
interval: 15s
# -- Timeout after which the scrape is ended
scrapeTimeout: ""
# -- Additional labels that can be used so ServiceMonitor will be discovered by Prometheus
selector: {}
# -- RelabelConfigs to apply to samples before scraping
relabelings: []
# -- Specify honorLabels parameter to add the scrape endpoint
honorLabels: false

# -- The number of replicas (pods) to launch, must be 1 unless you are using [the High Availability version](https://mercure.rocks/docs/hub/cluster).
replicaCount: 1

Expand Down Expand Up @@ -114,8 +137,8 @@ ingress:
hosts:
- host: mercure-example.local
paths:
- path: /
pathType: ImplementationSpecific
- path: /
pathType: ImplementationSpecific
# -- Ingress TLS configuration.
# @default -- See [values.yaml](values.yaml).
tls: []
Expand Down

0 comments on commit 849c7b3

Please sign in to comment.