Skip to content

Commit

Permalink
Add ServiceMonitor and Grafana dashboard for HiveMQ Platform Helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
afalhambra-hivemq committed Nov 28, 2024
1 parent bee4339 commit c4fa668
Show file tree
Hide file tree
Showing 34 changed files with 17,128 additions and 227 deletions.
8,168 changes: 8,168 additions & 0 deletions charts/hivemq-platform/files/grafana-dashboard.json

Large diffs are not rendered by default.

124 changes: 96 additions & 28 deletions charts/hivemq-platform/templates/_helpers.tpl

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions charts/hivemq-platform/templates/hivemq-custom-resource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{{- $hasAdditionalVolumes := ( include "hivemq-platform.has-additional-volumes" . ) -}}
{{- $hasAdditionalVolumeMounts := ( include "hivemq-platform.has-additional-volume-mounts" . ) -}}
{{- $metricsPort := ( include "hivemq-platform.metrics-port" . ) -}}
{{- $metricsContainerPortName := ( include "hivemq-platform.metrics-port-name" . ) -}}
{{- $hasMetricService := ( include "hivemq-platform.has-default-metrics-service" . ) -}}
{{- $hasStatefulSetMigration := ( include "hivemq-platform.has-legacy-statefulset-migration" . ) -}}
apiVersion: hivemq.com/v1
Expand Down Expand Up @@ -63,7 +64,7 @@ spec:
{{- $additionalInitContainers := .Values.additionalInitContainers }}
{{- $overrideInitContainers := .Values.config.overrideInitContainers }}
{{- if and $overrideInitContainers $additionalInitContainers }}
{{- fail ("Only `additionalInitContainers` or `config.overrideInitContainers` can be defined at a time") }}
{{- fail ("\nOnly `additionalInitContainers` or `config.overrideInitContainers` can be defined at a time") }}
{{- end }}
{{- if or $overrideInitContainers $additionalInitContainers }}
initContainers:
Expand Down Expand Up @@ -98,7 +99,7 @@ spec:
name: {{ $service.keystorePasswordSecretName }}
key: {{ $service.keystorePasswordSecretKey | default "keystore.password" }}
{{- else }}
{{- fail ("A keystore password should be set either as a string (keystorePassword) or as a secret name (keystorePasswordSecretName)") }}
{{- fail ("\nA keystore password should be set either as a string (keystorePassword) or as a secret name (keystorePasswordSecretName)") }}
{{- end }}
{{- if or $service.keystorePrivatePassword (and $service.keystorePasswordSecretName $service.keystorePrivatePasswordSecretKey) }}
{{- $envNameKeystorePrivatePassword := include "hivemq-platform.keystore-private-password" (dict "releaseName" $.Release.Name "type" $service.type "keystoreSecretName" $service.keystoreSecretName "keystorePrivatePassword" $service.keystorePrivatePassword "keystorePrivatePasswordSecretKey" $service.keystorePrivatePasswordSecretKey) }}
Expand Down Expand Up @@ -129,7 +130,7 @@ spec:
name: {{ $service.truststorePasswordSecretName }}
key: truststore.password
{{- else }}
{{- fail ("A truststore password should be set either as a string (truststorePassword) or as a secret name (truststorePasswordSecretName)") }}
{{- fail ("\nA truststore password should be set either as a string (truststorePassword) or as a secret name (truststorePasswordSecretName)") }}
{{- end }}
{{- $envNamesTrustStoreList = $envNameTrustorePassword | append $envNamesTrustStoreList }}
{{- end }}
Expand All @@ -155,7 +156,6 @@ spec:
{{- $containerPortNameList = $containerPortName | append $containerPortNameList }}
{{- end }}
{{- end }}
{{- $metricsContainerPortName := printf "metrics-%s" $metricsPort }}
{{- if and (not $hasMetricService) (not (has $metricsContainerPortName $containerPortNameList)) (.Values.metrics.enabled) (not $hasStatefulSetMigration) }}
- name: {{ $metricsContainerPortName }}
containerPort: {{ printf "%d" (int64 $metricsPort) }}
Expand Down Expand Up @@ -278,8 +278,8 @@ spec:
name: {{ (include "hivemq-platform.range-service-name" (dict "name" "" "releaseName" $.Release.Name "type" "metrics" "port" $metricsPort "containerPort" $metricsPort)) }}
spec:
ports:
- name: {{ printf "metrics-%s" $metricsPort }}
targetPort: {{ printf "metrics-%s" $metricsPort }}
- name: {{ $metricsContainerPortName }}
targetPort: {{ $metricsContainerPortName }}
port: {{ printf "%d" (int64 $metricsPort) }}
{{- end }}
{{- if hasKey .Values "extensions" }}
Expand Down
18 changes: 18 additions & 0 deletions charts/hivemq-platform/templates/hivemq-grafana-dashboard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.monitoring.enabled }}
{{- include "hivemq-platform.validate-prometheus-monitoring-stack-installed" . -}}
apiVersion: v1
kind: ConfigMap
metadata:
labels:
grafana_dashboard: "1"
{{- include "hivemq-platform.labels" . | nindent 4 }}
name: {{ include "hivemq-platform.name" (dict "name" "dashboard" "releaseName" .Release.Name) }}
{{- if and (hasKey .Values.monitoring "dashboard") (hasKey .Values.monitoring.dashboard "namespace") }}
namespace: {{ .Values.monitoring.dashboard.namespace }}
{{- else }}
namespace: {{ .Release.Namespace }}
{{- end }}
data:
hivemq-dashboard.json: |
{{- .Files.Get "files/grafana-dashboard.json" | nindent 4 }}
{{- end }}
30 changes: 30 additions & 0 deletions charts/hivemq-platform/templates/hivemq-service-monitor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{- if .Values.monitoring.enabled }}
{{- include "hivemq-platform.validate-prometheus-monitoring-stack-installed" . -}}
{{- include "hivemq-platform.validate-metrics-services" . -}}
{{- include "hivemq-platform.validate-metrics-is-enabled" . -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
{{- include "hivemq-platform.labels" . | nindent 4 }}
release: {{ .Values.monitoring.serviceMonitor.releaseName | default .Release.Name }}
name: {{ include "hivemq-platform.name" (dict "name" "service-monitor" "releaseName" .Release.Name) }}
{{- if .Values.monitoring.serviceMonitor.namespace }}
namespace: {{ .Values.monitoring.serviceMonitor.namespace }}
{{- else }}
namespace: {{ .Release.Namespace }}
{{- end }}
spec:
selector:
matchLabels:
{{- include "hivemq-platform.selector-labels" . | nindent 6 }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
endpoints:
- port: {{ include "hivemq-platform.metrics-container-port-name" . }}
path: {{ .Values.metrics.path }}
interval: {{ .Values.monitoring.serviceMonitor.interval }}
scrapeTimeout: {{ .Values.monitoring.serviceMonitor.scrapeTimeout }}
jobLabel: {{ include "hivemq-platform.name" (dict "name" "service-monitor" "releaseName" .Release.Name) }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
suite: HiveMQ Platform Configuration as ConfigMap tests
suite: HiveMQ Platform Configuration as ConfigMap - Configuration tests
templates:
- hivemq-configuration.yml
- hivemq-custom-resource.yml
Expand Down Expand Up @@ -1974,7 +1974,7 @@ tests:
config.create: false
asserts:
- failedTemplate:
errorMessage: HiveMQ configuration ConfigMap name cannot be empty when using an existing ConfigMap
errorPattern: HiveMQ configuration ConfigMap name cannot be empty when using an existing ConfigMap

- it: with existing ConfigMap, then reuse existing ConfigMap and no additional ConfigMap is created
template: hivemq-custom-resource.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ tests:
hivemqListenerName: my-custom-mqtt-listener
asserts:
- failedTemplate:
errorMessage: Found duplicated HiveMQ listener name `my-custom-mqtt-listener`
errorPattern: Found duplicated HiveMQ listener name `my-custom-mqtt-listener`

- it: with non-exposed MQTT services and duplicated listener name, validation succeeds
template: hivemq-custom-resource.yml
Expand Down Expand Up @@ -615,7 +615,7 @@ tests:
truststorePasswordSecretName: "my-truststore-secret"
asserts:
- failedTemplate:
errorMessage: A keystore password should be set either as a string (keystorePassword) or as a secret name (keystorePasswordSecretName)
errorPattern: A keystore password should be set either as a string \(keystorePassword\) or as a secret name \(keystorePasswordSecretName\)

- it: with a secure mutual TLS MQTT service exposed but missing required truststore password, validation fails
template: hivemq-custom-resource.yml
Expand All @@ -632,7 +632,7 @@ tests:
truststoreSecretKey: "truststore.jks"
asserts:
- failedTemplate:
errorMessage: A truststore password should be set either as a string (truststorePassword) or as a secret name (truststorePasswordSecretName)
errorPattern: A truststore password should be set either as a string \(truststorePassword\) or as a secret name \(truststorePasswordSecretName\)

- it: with a secure mutual TLS MQTT service not exposed
template: hivemq-configuration.yml
Expand Down Expand Up @@ -884,7 +884,7 @@ tests:
hivemqListenerName: my-custom-secure-mqtt-listener
asserts:
- failedTemplate:
errorMessage: Found duplicated HiveMQ listener name `my-custom-secure-mqtt-listener`
errorPattern: Found duplicated HiveMQ listener name `my-custom-secure-mqtt-listener`

- it: with non-exposed secure MQTT services and duplicated listener name, validation succeeds
template: hivemq-custom-resource.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ tests:
hivemqListenerName: my-custom-ws-listener
asserts:
- failedTemplate:
errorMessage: Found duplicated HiveMQ listener name `my-custom-ws-listener`
errorPattern: Found duplicated HiveMQ listener name `my-custom-ws-listener`

- it: with non-exposed WebSocket services and duplicated listener name, validation succeeds
template: hivemq-custom-resource.yml
Expand Down Expand Up @@ -815,7 +815,7 @@ tests:
hivemqListenerName: my-custom-secure-ws-listener
asserts:
- failedTemplate:
errorMessage: Found duplicated HiveMQ listener name `my-custom-secure-ws-listener`
errorPattern: Found duplicated HiveMQ listener name `my-custom-secure-ws-listener`

- it: with non-exposed secure WebSocket services and duplicated listener name, validation succeeds
template: hivemq-custom-resource.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
suite: HiveMQ Platform Configuration as Secret tests
suite: HiveMQ Platform Configuration as Secret - Configuration tests
templates:
- hivemq-configuration.yml
- hivemq-custom-resource.yml
Expand Down Expand Up @@ -2004,7 +2004,7 @@ tests:
config.create: false
asserts:
- failedTemplate:
errorMessage: HiveMQ configuration Secret name cannot be empty when using an existing Secret
errorPattern: HiveMQ configuration Secret name cannot be empty when using an existing Secret

- it: with existing Secret, then reuse existing Secret and no additional Secret is created
template: hivemq-custom-resource.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ tests:
truststorePasswordSecretName: "my-truststore-secret"
asserts:
- failedTemplate:
errorMessage: A keystore password should be set either as a string (keystorePassword) or as a secret name (keystorePasswordSecretName)
errorPattern: A keystore password should be set either as a string \(keystorePassword\) or as a secret name \(keystorePasswordSecretName\)

- it: with a secure mutual TLS MQTT service exposed, but missing required truststore password
template: hivemq-custom-resource.yml
Expand All @@ -568,7 +568,7 @@ tests:
truststoreSecretKey: "truststore.jks"
asserts:
- failedTemplate:
errorMessage: A truststore password should be set either as a string (truststorePassword) or as a secret name (truststorePasswordSecretName)
errorPattern: A truststore password should be set either as a string \(truststorePassword\) or as a secret name \(truststorePasswordSecretName\)

- it: with a secure mutual TLS MQTT service not exposed
template: hivemq-configuration.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
suite: HiveMQ Platform extension tests
suite: HiveMQ Platform - Extension tests
templates:
- hivemq-custom-resource.yml
tests:
Expand Down Expand Up @@ -86,7 +86,7 @@ tests:
secretName: "my-tracing-extension-secret-name"
asserts:
- failedTemplate:
errorMessage: Found duplicated extension name `hivemq-distributed-tracing-extension`
errorPattern: Found duplicated extension name `hivemq-distributed-tracing-extension`

- it: with extension configMapName and secretName set, validation fails
set:
Expand All @@ -98,7 +98,7 @@ tests:
secretName: "my-tracing-extension-secret-name"
asserts:
- failedTemplate:
errorMessage: Both `configMapName` and `secretName` values are set for extension `hivemq-distributed-tracing-extension`. Only one can be defined at a time
errorPattern: Both `configMapName` and `secretName` values are set for extension `hivemq-distributed-tracing-extension`. Only one can be defined at a time

- it: with extension configMapName and secretName empty, validation succeeds
set:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
suite: HiveMQ Platform NOTES tests
suite: HiveMQ Platform - NOTES tests
templates:
- NOTES.txt
release:
Expand Down
35 changes: 14 additions & 21 deletions charts/hivemq-platform/tests/hivemq_platform_test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
suite: HiveMQ Platform custom resource tests
suite: HiveMQ Platform - CustomResource tests
templates:
- hivemq-custom-resource.yml
release:
Expand Down Expand Up @@ -150,8 +150,7 @@ tests:
image: busybox
asserts:
- failedTemplate:
errorMessage: |-
Only `additionalInitContainers` or `config.overrideInitContainers` can be defined at a time
errorPattern: Only `additionalInitContainers` or `config.overrideInitContainers` can be defined at a time

- it: with default service account
asserts:
Expand Down Expand Up @@ -599,8 +598,7 @@ tests:
path: /additional-configmap-volume-2
asserts:
- failedTemplate:
errorMessage: |-
VolumeMount `foobar-mount-volume` is duplicated for container `hivemq`
errorPattern: VolumeMount `foobar-mount-volume` is duplicated for container `hivemq`

- it: with duplicated additionalVolumes `mountName` value in same `foobar` container, then fails
set:
Expand All @@ -617,8 +615,7 @@ tests:
path: /additional-configmap-volume-2
asserts:
- failedTemplate:
errorMessage: |-
VolumeMount `foobar-mount-volume` is duplicated for container `foobar`
errorPattern: VolumeMount `foobar-mount-volume` is duplicated for container `foobar`

- it: with duplicated additionalVolumes `mountName` value but different containers, then success
set:
Expand Down Expand Up @@ -667,8 +664,7 @@ tests:
path: /additional-configmap-volume-2
asserts:
- failedTemplate:
errorMessage: |-
VolumeMount `foobar-mount-volume` is duplicated for container `hivemq`
errorPattern: VolumeMount `foobar-mount-volume` is duplicated for container `hivemq`

- it: with duplicated additionalVolumes `name` value in same `foobar` container, then fails
set:
Expand All @@ -683,8 +679,7 @@ tests:
path: /additional-configmap-volume-2
asserts:
- failedTemplate:
errorMessage: |-
VolumeMount `foobar-mount-volume` is duplicated for container `foobar`
errorPattern: VolumeMount `foobar-mount-volume` is duplicated for container `foobar`

- it: with duplicated additionalVolumes `name` value but different containers, then success
set:
Expand Down Expand Up @@ -767,8 +762,7 @@ tests:
path: /additional-configmap-volume-2
asserts:
- failedTemplate:
errorMessage: |-
Volume `foobar-mount-volume` is defined more than once but with different types
errorPattern: Volume `foobar-mount-volume` is defined more than once but with different types

- it: with invalid additional volume `type`, then schema validation fails
set:
Expand All @@ -786,7 +780,7 @@ tests:
path: /fake-volume-path
asserts:
- failedTemplate:
errorMessage: |-
errorPattern: |-
`type` value is mandatory for all of the `additionalVolumes` defined
- it: with missing mandatory additional volume `type` for `foobar` container, then fails
Expand All @@ -797,7 +791,7 @@ tests:
containerName: foobar
asserts:
- failedTemplate:
errorMessage: |-
errorPattern: |-
`type` value is mandatory for all of the `additionalVolumes` defined
- it: with missing mandatory additional volume `path` for `hivemq` container, then fails
Expand All @@ -807,7 +801,7 @@ tests:
type: configMap
asserts:
- failedTemplate:
errorMessage: |-
errorPattern: |-
`path` values is mandatory for all of the `additionalVolumes` defined for the `hivemq` container
- it: with missing mandatory additional volume `path` for `foobar` container, then success
Expand All @@ -834,8 +828,7 @@ tests:
path: /fake-volume-path
asserts:
- failedTemplate:
errorMessage: |-
At least one of `name` or `mountName` values must be defined
errorPattern: At least one of `name` or `mountName` values must be defined

- it: with additional volume type `configMap` but missing `name`, then fails
set:
Expand All @@ -845,7 +838,7 @@ tests:
mountName: fake-volume-mount-name
asserts:
- failedTemplate:
errorMessage: |-
errorPattern: |-
`name` value is required for types "configMap", "secret" and "persistentVolumeClaim"
- it: with additional volume type `secret` but missing `name`, then fails
Expand All @@ -856,7 +849,7 @@ tests:
mountName: fake-volume-mount-name
asserts:
- failedTemplate:
errorMessage: |-
errorPattern: |-
`name` value is required for types "configMap", "secret" and "persistentVolumeClaim"
- it: with additional volume type `persistentVolumeClaim` but missing `name`, then fails
Expand All @@ -867,7 +860,7 @@ tests:
mountName: fake-volume-mount-name
asserts:
- failedTemplate:
errorMessage: |-
errorPattern: |-
`name` value is required for types "configMap", "secret" and "persistentVolumeClaim"
- it: with additional volume type `emptyDir` but missing `name`, then success
Expand Down
Loading

0 comments on commit c4fa668

Please sign in to comment.