Skip to content

Commit

Permalink
Improve Helm chart: labels, pod monitor, additional env vars (#384)
Browse files Browse the repository at this point in the history
* fix: enhance chart

* fix(helm): add readme values

* fix(helm): add readme values

* fix(helm): review

* fix(readme): add new line
  • Loading branch information
JulienOrain authored Nov 8, 2024
1 parent 97e329a commit 023b3c1
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 12 deletions.
35 changes: 32 additions & 3 deletions chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,32 @@

### Logstash configuration

| Name | Description | Value |
| -------------- | --------------------- | ---------------------- |
| `logstash.url` | Logstash instance URL | `http://logstash:9600` |
| Name | Description | Value |
| ----------------------- | --------------------- | ---------------------- |
| `logstash.url` | Logstash instance URL | `http://logstash:9600` |
| `logstash.httpTimeout` | http timeout | `3s` |
| `logstash.httpInsecure` | http insecure | `false` |

### Web settings

| Name | Description | Value |
| ---------- | ----------------------------------- | ----- |
| `web.path` | Path under which to expose metrics. | `/` |

### PodMonitor settings

| Name | Description | Value |
| ------------------------------ | --------------------------------- | -------------------------- |
| `podMonitor.enabled` | Enable pod monitor creation | `false` |
| `podMonitor.apiVersion` | Set pod monitor apiVersion | `monitoring.coreos.com/v1` |
| `podMonitor.namespace` | Set pod monitor namespace | `""` |
| `podMonitor.labels` | Set pod monitor labels | `{}` |
| `podMonitor.interval` | Set pod monitor interval | `60s` |
| `podMonitor.scrapeTimeout` | Set pod monitor scrapeTimeout | `10s` |
| `podMonitor.honorLabels` | Set pod monitor honorLabels | `true` |
| `podMonitor.scheme` | Set pod monitor scheme | `http` |
| `podMonitor.relabelings` | Set pod monitor relabelings | `[]` |
| `podMonitor.metricRelabelings` | Set pod monitor metricRelabelings | `[]` |

### Image settings

Expand Down Expand Up @@ -58,6 +81,12 @@
| `deployment.rollingUpdate.maxSurge` | Maximum surge for rolling update | `1` |
| `deployment.rollingUpdate.maxUnavailable` | Maximum unavailable for rolling update | `0` |

### metricsPort settings

| Name | Description | Value |
| ----------------------------- | ---------------- | ------ |
| `deployment.metricsPort.name` | Name of the port | `http` |

### Service settings

| Name | Description | Value |
Expand Down
87 changes: 87 additions & 0 deletions chart/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,83 @@
"type": "string",
"description": "Logstash instance URL",
"default": "http://logstash:9600"
},
"httpTimeout": {
"type": "string",
"description": "http timeout",
"default": "3s"
},
"httpInsecure": {
"type": "boolean",
"description": "http insecure",
"default": false
}
}
},
"web": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path under which to expose metrics.",
"default": "/"
}
}
},
"podMonitor": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean",
"description": "Enable pod monitor creation",
"default": false
},
"apiVersion": {
"type": "string",
"description": "Set pod monitor apiVersion",
"default": "monitoring.coreos.com/v1"
},
"namespace": {
"type": "string",
"description": "Set pod monitor namespace",
"default": ""
},
"labels": {
"type": "object",
"description": "Set pod monitor labels",
"default": {}
},
"interval": {
"type": "string",
"description": "Set pod monitor interval",
"default": "60s"
},
"scrapeTimeout": {
"type": "string",
"description": "Set pod monitor scrapeTimeout",
"default": "10s"
},
"honorLabels": {
"type": "boolean",
"description": "Set pod monitor honorLabels",
"default": true
},
"scheme": {
"type": "string",
"description": "Set pod monitor scheme",
"default": "http"
},
"relabelings": {
"type": "array",
"description": "Set pod monitor relabelings",
"default": [],
"items": {}
},
"metricRelabelings": {
"type": "array",
"description": "Set pod monitor metricRelabelings",
"default": [],
"items": {}
}
}
},
Expand Down Expand Up @@ -187,6 +264,16 @@
"default": 0
}
}
},
"metricsPort": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name of the port",
"default": "http"
}
}
}
}
},
Expand Down
21 changes: 21 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,24 @@ It checks if .Values.image.tag is provided, and if not, it returns a tag with "v
{{- printf "v%s" .Chart.AppVersion -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "logstash-exporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "logstash-exporter.labels" -}}
helm.sh/chart: {{ include "logstash-exporter.chart" . }}
{{- with .Chart.AppVersion }}
app.kubernetes.io/version: {{ . | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.commonLabels }}
{{ toYaml .Values.commonLabels }}
{{- end }}
{{- end }}
4 changes: 4 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ spec:
value: {{ required "logstash.url is required" .Values.logstash.url | quote }}
- name: PORT
value: {{ required "service.port is required" .Values.service.port | quote }}
- name: HTTP_TIMEOUT
value: {{ required "logstash.httpTimeout is required" .Values.logstash.httpTimeout | quote }}
- name: HTTP_INSECURE
value: {{ required "logstash.httpInsecure is required" .Values.logstash.httpInsecure | quote }}
{{- range $key, $value := .Values.deployment.env }}
- name: {{ $key | quote }}
value: {{ $value | quote }}
Expand Down
45 changes: 45 additions & 0 deletions chart/templates/podmonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{- if .Values.podMonitor.enabled }}
apiVersion: {{ .Values.podMonitor.apiVersion }}
kind: PodMonitor
metadata:
name: {{ template "logstash-exporter.fullname" . }}
{{- if .Values.podMonitor.namespace }}
namespace: {{ .Values.podMonitor.namespace }}
{{- end }}
labels:
{{- include "logstash-exporter.labels" . | nindent 4 }}
{{- if .Values.podMonitor.labels }}
{{- toYaml .Values.podMonitor.labels | nindent 4 }}
{{- end }}
spec:
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
podMetricsEndpoints:
- path: {{ .Values.web.path }}
port: {{ .Values.deployment.metricsPort.name }}
{{- if .Values.podMonitor.scheme }}
scheme: {{ .Values.podMonitor.scheme }}
{{- end }}
{{- if .Values.podMonitor.interval }}
interval: {{ .Values.podMonitor.interval }}
{{- end }}
{{- if .Values.podMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.podMonitor.scrapeTimeout }}
{{- end }}
{{- if .Values.podMonitor.honorLabels }}
honorLabels: true
{{- end }}
{{- if .Values.podMonitor.metricRelabelings }}
metricRelabelings:
{{- toYaml .Values.podMonitor.metricRelabelings | nindent 6 }}
{{- end }}
{{- if .Values.podMonitor.relabelings }}
relabelings:
{{- toYaml .Values.podMonitor.relabelings | nindent 6 }}
{{- end }}
selector:
matchLabels:
app: {{ template "logstash-exporter.name" . }}
release: {{ .Release.Name }}
{{- end }}
66 changes: 57 additions & 9 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,56 @@ logstash:
## @param logstash.url Logstash instance URL
##
url: "http://logstash:9600"
## @param logstash.httpTimeout http timeout
##
httpTimeout: "3s"
## @param logstash.httpInsecure http insecure
##
httpInsecure: false

## @section Web settings
##
web:
## @param web.path Path under which to expose metrics.
##
path: /

## @section PodMonitor settings
##
podMonitor:
## If true, a PodMonitor CRD is created for a Prometheus Operator
## https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.PodMonitor
##
## @param podMonitor.enabled Enable pod monitor creation
##
enabled: false
## @param podMonitor.apiVersion Set pod monitor apiVersion
##
apiVersion: "monitoring.coreos.com/v1"
## @param podMonitor.namespace Set pod monitor namespace
##
namespace: ""
## @param podMonitor.labels Set pod monitor labels
##
labels: {}
## @param podMonitor.interval Set pod monitor interval
##
interval: 60s
## @param podMonitor.scrapeTimeout Set pod monitor scrapeTimeout
##
scrapeTimeout: 10s
## @param podMonitor.honorLabels Set pod monitor honorLabels
##
honorLabels: true
## @param podMonitor.scheme Set pod monitor scheme
##
scheme: http
## @param podMonitor.relabelings Set pod monitor relabelings
##
relabelings: []
## @param podMonitor.metricRelabelings Set pod monitor metricRelabelings
##
metricRelabelings: []

## @section Image settings
##
Expand Down Expand Up @@ -35,17 +85,9 @@ deployment:
restartPolicy: Always
## @param deployment.annotations Additional deployment annotations
##
## Example:
## annotations:
## kubernetes.io/foo: bar
##
annotations: {}
## @param deployment.labels Additional deployment labels
##
## Example:
## labels:
## foo: bar
##
labels: {}
## @param deployment.pullSecret Kubernetes secret for pulling the image
##
Expand Down Expand Up @@ -120,6 +162,12 @@ deployment:
## @param deployment.rollingUpdate.maxUnavailable Maximum unavailable for rolling update
##
maxUnavailable: 0
## @section metricsPort settings
##
metricsPort:
## @param deployment.metricsPort.name Name of the port
##
name: http

## @section Service settings
##
Expand Down Expand Up @@ -151,4 +199,4 @@ serviceAccount:
name: ""
## @param serviceAccount.annotations Additional service account annotations
##
annotations: {}
annotations: {}

0 comments on commit 023b3c1

Please sign in to comment.