Skip to content

Commit 002cbe5

Browse files
authored
Expose metrics and add Prometheus ServiceMonitor (#46)
* expose metrics and add prometheus servicemonitor * add new values to readme * remove trailing space * use metrics in favor of prometheus as variable name
1 parent 30b7bce commit 002cbe5

File tree

6 files changed

+76
-1
lines changed

6 files changed

+76
-1
lines changed

helm/oauth2-proxy/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: oauth2-proxy
2-
version: 4.0.6
2+
version: 4.1.0
33
apiVersion: v2
44
appVersion: 7.1.3
55
home: https://oauth2-proxy.github.io/oauth2-proxy/

helm/oauth2-proxy/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ Parameter | Description | Default
142142
`sessionStorage.redis.sentinel.connectionUrls` | List of Redis sentinel connection URLs (e.g. redis://HOST[:PORT]) | `[]`
143143
`redis.enabled` | Enable the redis subchart deployment | `false`
144144
`checkDeprecation` | Enable deprecation checks | `true`
145+
`metrics.enabled` | Enable Prometheus metrics endpoint | `true`
146+
`metrics.port` | Serve Prometheus metrics on this port | `44180`
147+
`metrics.servicemonitor.enabled` | Enable Prometheus Operator ServiceMonitor | `false`
148+
`metrics.servicemonitor.namespace` | Define the namespace where to deploy the ServiceMonitor resource | `""`
149+
`metrics.servicemonitor.prometheusInstance` | Prometheus Instance definition | `default`
150+
`metrics.servicemonitor.interval` | Prometheus scrape interval | `60s`
151+
`metrics.servicemonitor.scrapeTimeout` | Prometheus scrape timeout | `30s`
152+
`metrics.servicemonitor.labels` | Add custom labels to the ServiceMonitor resource| `{}`
145153

146154
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
147155

helm/oauth2-proxy/templates/deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ spec:
4848
imagePullPolicy: {{ .Values.image.pullPolicy }}
4949
args:
5050
- --http-address=0.0.0.0:4180
51+
{{- if .Values.metrics.enabled }}
52+
- --metrics-address=0.0.0.0:44180
53+
{{- end }}
5154
{{- if .Values.config.cookieName }}
5255
- --cookie-name={{ .Values.config.cookieName }}
5356
{{- end }}
@@ -136,6 +139,11 @@ spec:
136139
- containerPort: 4180
137140
name: {{ .Values.httpScheme }}
138141
protocol: TCP
142+
{{- if .Values.metrics.enabled }}
143+
- containerPort: 44180
144+
protocol: TCP
145+
name: metrics
146+
{{- end }}
139147
{{- if .Values.livenessProbe.enabled }}
140148
livenessProbe:
141149
httpGet:

helm/oauth2-proxy/templates/service.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ spec:
3434
targetPort: {{ .Values.httpScheme }}
3535
protocol: TCP
3636
name: {{ .Values.httpScheme }}
37+
{{- if and .Values.metrics.enabled .Values.metrics.port }}
38+
- port: {{ .Values.metrics.port }}
39+
protocol: TCP
40+
targetPort: metrics
41+
name: metrics
42+
{{- end }}
3743
selector:
3844
app: {{ template "oauth2-proxy.name" . }}
3945
release: {{ .Release.Name }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- if and .Values.metrics.enabled .Values.metrics.servicemonitor.enabled }}
2+
apiVersion: monitoring.coreos.com/v1
3+
kind: ServiceMonitor
4+
metadata:
5+
name: {{ template "oauth2-proxy.fullname" . }}
6+
{{- if .Values.metrics.servicemonitor.namespace }}
7+
namespace: {{ .Values.metrics.servicemonitor.namespace }}
8+
{{- else }}
9+
namespace: {{ .Release.Namespace | quote }}
10+
{{- end }}
11+
labels:
12+
app: {{ template "oauth2-proxy.name" . }}
13+
chart: {{ template "oauth2-proxy.chart" . }}
14+
release: {{ .Release.Name }}
15+
heritage: {{ .Release.Service }}
16+
prometheus: {{ .Values.metrics.servicemonitor.prometheusInstance }}
17+
{{- if .Values.metrics.servicemonitor.labels }}
18+
{{ toYaml .Values.metrics.servicemonitor.labels | indent 4}}
19+
{{- end }}
20+
spec:
21+
jobLabel: {{ template "oauth2-proxy.fullname" . }}
22+
selector:
23+
matchLabels:
24+
app: {{ template "oauth2-proxy.name" . }}
25+
release: {{ .Release.Name }}
26+
namespaceSelector:
27+
matchNames:
28+
- {{ .Release.Namespace }}
29+
endpoints:
30+
- port: metrics
31+
path: "/metrics"
32+
interval: {{ .Values.metrics.servicemonitor.interval }}
33+
scrapeTimeout: {{ .Values.metrics.servicemonitor.scrapeTimeout }}
34+
{{- end }}

helm/oauth2-proxy/values.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,22 @@ redis:
235235

236236
# Enables apiVersion deprecation checks
237237
checkDeprecation: true
238+
239+
metrics:
240+
# Enable Prometheus metrics endpoint
241+
enabled: true
242+
# Serve Prometheus metrics on this port
243+
port: 44180
244+
servicemonitor:
245+
# Enable Prometheus Operator ServiceMonitor
246+
enabled: false
247+
# Define the namespace where to deploy the ServiceMonitor resource
248+
namespace: ""
249+
# Prometheus Instance definition
250+
prometheusInstance: default
251+
# Prometheus scrape interval
252+
interval: 60s
253+
# Prometheus scrape timeout
254+
scrapeTimeout: 30s
255+
# Add custom labels to the ServiceMonitor resource
256+
labels: {}

0 commit comments

Comments
 (0)