Skip to content

Commit

Permalink
feat: Refactors Helm chart
Browse files Browse the repository at this point in the history
- Updates labels to match current standards and moves to helpers
- Adds Prometheus PodMonitor and removes Prometheus annotation
- Updates README to reflect breaking changes
  • Loading branch information
jmriebold committed Aug 19, 2024
1 parent 35bd958 commit c4cebf0
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 19 deletions.
2 changes: 1 addition & 1 deletion chart/sqs-prometheus-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: sqs-prometheus-exporter
version: 1.1.7
version: 2.0.0
description: Helm chart for the SQS Prometheus Exporter
keywords:
- prometheus
Expand Down
8 changes: 8 additions & 0 deletions chart/sqs-prometheus-exporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ A simple, lightweight Prometheus metrics exporter for [AWS's Simple Queue Servic

# Use

## Installation

```bash
helm repo add jmriebold https://jmriebold.github.io/charts
helm install release-name --set sqs.region=[region-name] \
--set sqs.queueUrls[0]=https://sqs.[region].amazonaws.com/[account-id]/[queue-name-1] \
jmriebold/sqs-prometheus-exporter
```

## Upgrading

### From 1.x.x to 2.x.x

This version adds a Prometheus PodMonitor CRD and refactors the deployment selector labels, both of which are breaking changes, the latter of which requires a chart reinstall. When reinstalling, ensure that `podMonitor.labels.release` matches your Prometheus PodMonitor selector.

# Configuration

## AWS
Expand Down
19 changes: 16 additions & 3 deletions chart/sqs-prometheus-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,21 @@ Set default container port name.
{{- end -}}

{{/*
Set default service port name.
Selector labels
*/}}
{{- define "portNames.service" -}}
{{- print "http" -}}
{{- define "sqs-prometheus-exporter.selectorLabels" -}}
app.kubernetes.io/name: {{ include "sqs-prometheus-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "sqs-prometheus-exporter.labels" -}}
helm.sh/chart: {{ include "sqs-prometheus-exporter.chart" . }}
{{ include "sqs-prometheus-exporter.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
16 changes: 5 additions & 11 deletions chart/sqs-prometheus-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@ metadata:
name: {{ .Values.app.name }}
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "sqs-prometheus-exporter.name" . }}
chart: {{ template "sqs-prometheus-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "sqs-prometheus-exporter.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
app: {{ template "sqs-prometheus-exporter.name" . }}
release: {{ .Release.Name }}
{{- include "sqs-prometheus-exporter.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
app: {{ template "sqs-prometheus-exporter.name" . }}
release: {{ .Release.Name }}
{{- include "sqs-prometheus-exporter.labels" . | nindent 8 }}
annotations:
{{- with .Values.deployment.podAnnotations }}
{{ toYaml . | indent 8 }}
{{- end }}
prometheus.io/scrape: "true"
spec:
{{- if or .Values.serviceAccount.name .Values.serviceAccount.create }}
serviceAccountName: {{ .Values.serviceAccount.name | default .Values.app.name | quote }}
Expand All @@ -33,9 +27,9 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: IfNotPresent
ports:
- name: traffic
- name: {{ template "portNames.container" . }}
protocol: {{ .Values.deployment.protocol }}
containerPort: {{ .Values.deployment.port }}
protocol: TCP
resources:
{{- with .Values.deployment.resources }}
{{ toYaml . | indent 12 }}
Expand Down
36 changes: 36 additions & 0 deletions chart/sqs-prometheus-exporter/templates/podmonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{- if .Values.podMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: {{ .Values.app.name }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "sqs-prometheus-exporter.labels" . | nindent 4 }}
{{- with .Values.podMonitor.labels }}
{{ toYaml . | indent 4 }}
{{- end }}
spec:
podMetricsEndpoints:
- path: /metrics
port: {{ template "portNames.container" . }}
interval: {{ .Values.podMonitor.interval }}
{{- with .Values.podMonitor.metricRelabelings }}
metricRelabelings:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podMonitor.relabelings }}
relabelings:
{{- toYaml . | nindent 8 }}
{{- end }}
selector:
matchLabels:
{{- include "sqs-prometheus-exporter.selectorLabels" . | nindent 6 }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
{{- with .Values.podMonitor.targetLabels }}
targetLabels:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}

5 changes: 1 addition & 4 deletions chart/sqs-prometheus-exporter/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ metadata:
name: {{ .Values.app.name }}
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "sqs-prometheus-exporter.name" . }}
chart: {{ template "sqs-prometheus-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "sqs-prometheus-exporter.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{ toYaml . | indent 4 }}
Expand Down
11 changes: 11 additions & 0 deletions chart/sqs-prometheus-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ serviceAccount:
create: false
annotations: {}

podMonitor:
# Enable Prometheus metrics scraping
enabled: true
interval: 30s
labels:
# Must match Prometheus PodMonitor selector
release: kube-prometheus-stack
relabelings: []
metricRelabelings: []
targetLabels: []

sqs:
region: us-west-2
queueUrls: []
Expand Down

0 comments on commit c4cebf0

Please sign in to comment.