From 4c2e5b176664c13b19391227b253c8d9fcbe6234 Mon Sep 17 00:00:00 2001
From: Denis GERMAIN
Date: Thu, 18 Jan 2024 12:22:35 +0100
Subject: [PATCH 1/2] chore: add probes on all containers
---
.../templates/daemonset.yaml | 24 +++++++++++++++++++
.../templates/deployment.yaml | 24 +++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/deploy/charts/x509-certificate-exporter/templates/daemonset.yaml b/deploy/charts/x509-certificate-exporter/templates/daemonset.yaml
index 0385770..0e7ecef 100644
--- a/deploy/charts/x509-certificate-exporter/templates/daemonset.yaml
+++ b/deploy/charts/x509-certificate-exporter/templates/daemonset.yaml
@@ -136,9 +136,21 @@ spec:
- {{ tpl (. | toYaml) $ | indent 10 | trim }}
{{- end }}
{{- if not $.Values.rbacProxy.enabled }}
+ livenessProbe:
+ httpGet:
+ path: /metrics
+ port: metrics
+ initialDelaySeconds: 5
+ periodSeconds: 3
ports:
- name: metrics
containerPort: {{ $.Values.podListenPort }}
+ readinessProbe:
+ httpGet:
+ path: /metrics
+ port: metrics
+ initialDelaySeconds: 5
+ periodSeconds: 3
{{- else }}
- name: kube-rbac-proxy
{{- with $.Values.rbacProxy.securityContext }}
@@ -157,9 +169,21 @@ spec:
valueFrom:
fieldRef:
fieldPath: status.podIP
+ livenessProbe:
+ httpGet:
+ path: /metrics
+ port: metrics
+ initialDelaySeconds: 5
+ periodSeconds: 3
ports:
- name: metrics
containerPort: {{ $.Values.podListenPort }}
+ readinessProbe:
+ httpGet:
+ path: /metrics
+ port: metrics
+ initialDelaySeconds: 5
+ periodSeconds: 3
{{- with $.Values.rbacProxy.resources }}
resources:
{{- . | toYaml | trim | nindent 10 }}
diff --git a/deploy/charts/x509-certificate-exporter/templates/deployment.yaml b/deploy/charts/x509-certificate-exporter/templates/deployment.yaml
index 7c27897..9308e06 100644
--- a/deploy/charts/x509-certificate-exporter/templates/deployment.yaml
+++ b/deploy/charts/x509-certificate-exporter/templates/deployment.yaml
@@ -133,9 +133,21 @@ spec:
{{- end }}
{{- if not .Values.rbacProxy.enabled }}
- --listen-address=:{{ .Values.podListenPort }}
+ livenessProbe:
+ httpGet:
+ path: /metrics
+ port: metrics
+ initialDelaySeconds: 5
+ periodSeconds: 3
ports:
- name: metrics
containerPort: {{ .Values.podListenPort }}
+ readinessProbe:
+ httpGet:
+ path: /metrics
+ port: metrics
+ initialDelaySeconds: 5
+ periodSeconds: 3
{{- else }}
- --listen-address=:{{ .Values.rbacProxy.upstreamListenPort }}
- name: kube-rbac-proxy
@@ -155,9 +167,21 @@ spec:
valueFrom:
fieldRef:
fieldPath: status.podIP
+ livenessProbe:
+ httpGet:
+ path: /metrics
+ port: metrics
+ initialDelaySeconds: 5
+ periodSeconds: 3
ports:
- name: metrics
containerPort: {{ .Values.podListenPort }}
+ readinessProbe:
+ httpGet:
+ path: /metrics
+ port: metrics
+ initialDelaySeconds: 5
+ periodSeconds: 3
{{- with .Values.rbacProxy.resources }}
resources:
{{- . | toYaml | trim | nindent 10 }}
From 1f45928f788d5e9ae1c4452ff10f2347b4a4e7eb Mon Sep 17 00:00:00 2001
From: Denis GERMAIN
Date: Mon, 25 Mar 2024 15:52:58 +0100
Subject: [PATCH 2/2] chore: add a real /healthz endpoint
---
.../x509-certificate-exporter/templates/daemonset.yaml | 8 ++++----
.../x509-certificate-exporter/templates/deployment.yaml | 8 ++++----
go.mod | 1 +
go.sum | 6 ++++++
internal/exporter.go | 2 ++
5 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/deploy/charts/x509-certificate-exporter/templates/daemonset.yaml b/deploy/charts/x509-certificate-exporter/templates/daemonset.yaml
index 0e7ecef..4456084 100644
--- a/deploy/charts/x509-certificate-exporter/templates/daemonset.yaml
+++ b/deploy/charts/x509-certificate-exporter/templates/daemonset.yaml
@@ -138,7 +138,7 @@ spec:
{{- if not $.Values.rbacProxy.enabled }}
livenessProbe:
httpGet:
- path: /metrics
+ path: /healthz
port: metrics
initialDelaySeconds: 5
periodSeconds: 3
@@ -147,7 +147,7 @@ spec:
containerPort: {{ $.Values.podListenPort }}
readinessProbe:
httpGet:
- path: /metrics
+ path: /healthz
port: metrics
initialDelaySeconds: 5
periodSeconds: 3
@@ -171,7 +171,7 @@ spec:
fieldPath: status.podIP
livenessProbe:
httpGet:
- path: /metrics
+ path: /healthz
port: metrics
initialDelaySeconds: 5
periodSeconds: 3
@@ -180,7 +180,7 @@ spec:
containerPort: {{ $.Values.podListenPort }}
readinessProbe:
httpGet:
- path: /metrics
+ path: /healthz
port: metrics
initialDelaySeconds: 5
periodSeconds: 3
diff --git a/deploy/charts/x509-certificate-exporter/templates/deployment.yaml b/deploy/charts/x509-certificate-exporter/templates/deployment.yaml
index 9308e06..1bb14f1 100644
--- a/deploy/charts/x509-certificate-exporter/templates/deployment.yaml
+++ b/deploy/charts/x509-certificate-exporter/templates/deployment.yaml
@@ -135,7 +135,7 @@ spec:
- --listen-address=:{{ .Values.podListenPort }}
livenessProbe:
httpGet:
- path: /metrics
+ path: /healthz
port: metrics
initialDelaySeconds: 5
periodSeconds: 3
@@ -144,7 +144,7 @@ spec:
containerPort: {{ .Values.podListenPort }}
readinessProbe:
httpGet:
- path: /metrics
+ path: /healthz
port: metrics
initialDelaySeconds: 5
periodSeconds: 3
@@ -169,7 +169,7 @@ spec:
fieldPath: status.podIP
livenessProbe:
httpGet:
- path: /metrics
+ path: /healthz
port: metrics
initialDelaySeconds: 5
periodSeconds: 3
@@ -178,7 +178,7 @@ spec:
containerPort: {{ .Values.podListenPort }}
readinessProbe:
httpGet:
- path: /metrics
+ path: /healthz
port: metrics
initialDelaySeconds: 5
periodSeconds: 3
diff --git a/go.mod b/go.mod
index 1868375..1224ac8 100644
--- a/go.mod
+++ b/go.mod
@@ -4,6 +4,7 @@ go 1.21
require (
github.com/bmatcuk/doublestar/v4 v4.6.1
+ github.com/dimiro1/health v0.0.0-20231118160444-e388c68d7d7e
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pborman/getopt/v2 v2.1.0
github.com/pkg/errors v0.9.1
diff --git a/go.sum b/go.sum
index abd46c6..2f6344e 100644
--- a/go.sum
+++ b/go.sum
@@ -1,3 +1,4 @@
+github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
@@ -7,10 +8,13 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/dimiro1/health v0.0.0-20231118160444-e388c68d7d7e h1:MPc833fnULks8D8FZwut9nDjRnxZlo4kmpAph09ChXw=
+github.com/dimiro1/health v0.0.0-20231118160444-e388c68d7d7e/go.mod h1:k1oeNKpjma0O03u8mKfiKIDXPvqA3VDYq9+QNcPPvuE=
github.com/emicklei/go-restful/v3 v3.11.2 h1:1onLa9DcsMYO9P+CXaL0dStDqQ2EHHXLiz+BtnqkLAU=
github.com/emicklei/go-restful/v3 v3.11.2/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/enix/doublestar/v4 v4.0.0-20230517083426-fa6d1b0d071d h1:XgDfI7CiZqA4yTAb1gGilrci8zfoHqN311QqHOor3Pw=
github.com/enix/doublestar/v4 v4.0.0-20230517083426-fa6d1b0d071d/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
+github.com/garyburd/redigo v0.0.0-20160302234602-4ed1111375cb/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
@@ -32,6 +36,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
+github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -94,6 +99,7 @@ github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7f
github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
+github.com/rafaeljusto/redigomock v0.0.0-20190202135759-257e089e14a1/go.mod h1:JaY6n2sDr+z2WTsXkOmNRUfDy6FN0L6Nk7x06ndm4tY=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
diff --git a/internal/exporter.go b/internal/exporter.go
index 4e1040f..f8ac808 100644
--- a/internal/exporter.go
+++ b/internal/exporter.go
@@ -19,6 +19,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/bmatcuk/doublestar/v4"
+ "github.com/dimiro1/health"
"github.com/prometheus/common/promlog"
"github.com/prometheus/exporter-toolkit/web"
log "github.com/sirupsen/logrus"
@@ -87,6 +88,7 @@ func (exporter *Exporter) Listen() error {
// Serve : Actually reply to requests
func (exporter *Exporter) Serve() error {
mux := http.NewServeMux()
+ mux.Handle("/healthz", health.NewHandler())
mux.Handle("/metrics", promhttp.Handler())
exporter.server = &http.Server{