Skip to content

Commit

Permalink
Expose metrics and add Prometheus ServiceMonitor (#46)
Browse files Browse the repository at this point in the history
* expose metrics and add prometheus servicemonitor

* add new values to readme

* remove trailing space

* use metrics in favor of prometheus as variable name
  • Loading branch information
modularTaco authored Jul 26, 2021
1 parent 30b7bce commit 002cbe5
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helm/oauth2-proxy/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: oauth2-proxy
version: 4.0.6
version: 4.1.0
apiVersion: v2
appVersion: 7.1.3
home: https://oauth2-proxy.github.io/oauth2-proxy/
Expand Down
8 changes: 8 additions & 0 deletions helm/oauth2-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ Parameter | Description | Default
`sessionStorage.redis.sentinel.connectionUrls` | List of Redis sentinel connection URLs (e.g. redis://HOST[:PORT]) | `[]`
`redis.enabled` | Enable the redis subchart deployment | `false`
`checkDeprecation` | Enable deprecation checks | `true`
`metrics.enabled` | Enable Prometheus metrics endpoint | `true`
`metrics.port` | Serve Prometheus metrics on this port | `44180`
`metrics.servicemonitor.enabled` | Enable Prometheus Operator ServiceMonitor | `false`
`metrics.servicemonitor.namespace` | Define the namespace where to deploy the ServiceMonitor resource | `""`
`metrics.servicemonitor.prometheusInstance` | Prometheus Instance definition | `default`
`metrics.servicemonitor.interval` | Prometheus scrape interval | `60s`
`metrics.servicemonitor.scrapeTimeout` | Prometheus scrape timeout | `30s`
`metrics.servicemonitor.labels` | Add custom labels to the ServiceMonitor resource| `{}`

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

Expand Down
8 changes: 8 additions & 0 deletions helm/oauth2-proxy/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- --http-address=0.0.0.0:4180
{{- if .Values.metrics.enabled }}
- --metrics-address=0.0.0.0:44180
{{- end }}
{{- if .Values.config.cookieName }}
- --cookie-name={{ .Values.config.cookieName }}
{{- end }}
Expand Down Expand Up @@ -136,6 +139,11 @@ spec:
- containerPort: 4180
name: {{ .Values.httpScheme }}
protocol: TCP
{{- if .Values.metrics.enabled }}
- containerPort: 44180
protocol: TCP
name: metrics
{{- end }}
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
httpGet:
Expand Down
6 changes: 6 additions & 0 deletions helm/oauth2-proxy/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ spec:
targetPort: {{ .Values.httpScheme }}
protocol: TCP
name: {{ .Values.httpScheme }}
{{- if and .Values.metrics.enabled .Values.metrics.port }}
- port: {{ .Values.metrics.port }}
protocol: TCP
targetPort: metrics
name: metrics
{{- end }}
selector:
app: {{ template "oauth2-proxy.name" . }}
release: {{ .Release.Name }}
34 changes: 34 additions & 0 deletions helm/oauth2-proxy/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{- if and .Values.metrics.enabled .Values.metrics.servicemonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "oauth2-proxy.fullname" . }}
{{- if .Values.metrics.servicemonitor.namespace }}
namespace: {{ .Values.metrics.servicemonitor.namespace }}
{{- else }}
namespace: {{ .Release.Namespace | quote }}
{{- end }}
labels:
app: {{ template "oauth2-proxy.name" . }}
chart: {{ template "oauth2-proxy.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
prometheus: {{ .Values.metrics.servicemonitor.prometheusInstance }}
{{- if .Values.metrics.servicemonitor.labels }}
{{ toYaml .Values.metrics.servicemonitor.labels | indent 4}}
{{- end }}
spec:
jobLabel: {{ template "oauth2-proxy.fullname" . }}
selector:
matchLabels:
app: {{ template "oauth2-proxy.name" . }}
release: {{ .Release.Name }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
endpoints:
- port: metrics
path: "/metrics"
interval: {{ .Values.metrics.servicemonitor.interval }}
scrapeTimeout: {{ .Values.metrics.servicemonitor.scrapeTimeout }}
{{- end }}
19 changes: 19 additions & 0 deletions helm/oauth2-proxy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,22 @@ redis:

# Enables apiVersion deprecation checks
checkDeprecation: true

metrics:
# Enable Prometheus metrics endpoint
enabled: true
# Serve Prometheus metrics on this port
port: 44180
servicemonitor:
# Enable Prometheus Operator ServiceMonitor
enabled: false
# Define the namespace where to deploy the ServiceMonitor resource
namespace: ""
# Prometheus Instance definition
prometheusInstance: default
# Prometheus scrape interval
interval: 60s
# Prometheus scrape timeout
scrapeTimeout: 30s
# Add custom labels to the ServiceMonitor resource
labels: {}

0 comments on commit 002cbe5

Please sign in to comment.