Skip to content

Commit 64db91f

Browse files
authored
New probes and Kubernetes Service resource (#82)
* Add: Healthy and Ready handlers Signed-off-by: Nicolas Lamirault <[email protected]> * Update: new probes Signed-off-by: Nicolas Lamirault <[email protected]> * Add: Service resource Signed-off-by: Nicolas Lamirault <[email protected]> --------- Signed-off-by: Nicolas Lamirault <[email protected]>
1 parent e1070dc commit 64db91f

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

charts/kubernetes-event-exporter/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type: application
66
# This is the chart version. This version number should be incremented each time you make changes
77
# to the chart and its templates, including the app version.
88
# Versions are expected to follow Semantic Versioning (https://semver.org/)
9-
version: 0.1.0
9+
version: 0.2.0
1010

1111
# This is the version number of the application being deployed. This version number should be
1212
# incremented each time you make changes to the application. Versions are not expected to

charts/kubernetes-event-exporter/templates/deployment.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ spec:
3232
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
3333
imagePullPolicy: {{ .Values.image.pullPolicy }}
3434
ports:
35-
- name: metrics
35+
- name: http
3636
containerPort: {{ .Values.service.port }}
3737
protocol: TCP
3838
livenessProbe:
3939
httpGet:
40-
path: /metrics
41-
port: metrics
40+
path: /-/healthy
41+
port: http
4242
readinessProbe:
4343
httpGet:
44-
path: /metrics
45-
port: metrics
44+
path: /-/ready
45+
port: http
4646
args:
4747
- -conf=/data/config.yaml
4848
volumeMounts:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
kind: Service
3+
apiVersion: v1
4+
metadata:
5+
name: {{ include "kubernetes-event-exporter.fullname" . }}
6+
namespace: {{ include "kubernetes-event-exporter.namespace" . }}
7+
spec:
8+
type: {{ .Values.service.type }}
9+
ports:
10+
- name: http
11+
port: {{ .Values.service.port }}
12+
protocol: TCP
13+
selector:
14+
{{- include "kubernetes-event-exporter.selectorLabels" . | indent 4 }}

pkg/metrics/metrics.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package metrics
22

33
import (
4+
"fmt"
45
"net/http"
56

67
"github.com/prometheus/client_golang/prometheus"
78
"github.com/prometheus/client_golang/prometheus/collectors"
9+
"github.com/prometheus/common/version"
810
"github.com/prometheus/client_golang/prometheus/promauto"
911
"github.com/prometheus/client_golang/prometheus/promhttp"
1012
)
@@ -21,7 +23,25 @@ func Init(addr string) {
2123
// Setup the prometheus metrics machinery
2224
// Add Go module build info.
2325
prometheus.MustRegister(collectors.NewBuildInfoCollector())
24-
26+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
27+
w.Write([]byte(`<html>
28+
<head><title>Kubernetes Events Exporter</title></head>
29+
<body>
30+
<h1>Kubernetes Events Exporter</h1>
31+
<p><a href='metrics'>Metrics</a></p>
32+
<h2>Build</h2>
33+
<pre>` + version.Info() + ` ` + version.BuildContext() + `</pre>
34+
</body>
35+
</html>`))
36+
})
37+
http.HandleFunc("/-/healthy", func(w http.ResponseWriter, r *http.Request) {
38+
w.WriteHeader(http.StatusOK)
39+
fmt.Fprintf(w, "OK")
40+
})
41+
http.HandleFunc("/-/ready", func(w http.ResponseWriter, r *http.Request) {
42+
w.WriteHeader(http.StatusOK)
43+
fmt.Fprintf(w, "OK")
44+
})
2545
// Expose the registered metrics via HTTP.
2646
http.Handle("/metrics", promhttp.HandlerFor(
2747
prometheus.DefaultGatherer,

0 commit comments

Comments
 (0)