Skip to content

Commit

Permalink
Make Grafana dashboards configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
afalhambra-hivemq committed Nov 29, 2024
1 parent 2e719de commit e23358a
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.monitoring.enabled }}
{{- if and .Values.monitoring.enabled .Values.monitoring.dashboard.create }}
{{- include "hivemq-platform-operator.validate-prometheus-monitoring-stack-installed" . -}}
apiVersion: v1
kind: ConfigMap
Expand All @@ -13,6 +13,13 @@ metadata:
namespace: {{ .Release.Namespace }}
{{- end }}
data:
{{- if .Values.monitoring.dashboard.overrideDashboard }}
operator-dashboard.json: |
{{- range .Values.monitoring.dashboard.overrideDashboard | toStrings }}
{{ . | nindent 4 }}
{{- end }}
{{- else }}
operator-dashboard.json: |
{{- .Files.Get "files/grafana-dashboard.json" | nindent 4 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ tests:
- hasDocuments:
count: 1

- it: with monitoring enabled and create disabled, ConfigMap not created
set:
monitoring:
enabled: true
dashboard:
create: false
asserts:
- notFailedTemplate: {}
- hasDocuments:
count: 0

- it: with monitoring enabled, create disabled and invalid ConfigMap name, schema validation fails
set:
monitoring:
enabled: true
dashboard:
create: false
name: this-is-a-very-long-hivemq-platform-operator-grafana-dashboard-configmap-name
asserts:
- failedTemplate: {}

- it: with long Helm release name, ConfigMap name truncated
release:
name: a-very-long-hivemq-platform-operator-release-name
Expand All @@ -45,7 +66,7 @@ tests:
- failedTemplate:
errorPattern: There is no Prometheus ServiceMonitor CustomResourceDefinition \(CRD\) available in your Kubernetes cluster. Prometheus Monitoring CRDs are required before installing the ServiceMonitor resource.

- it: with invalid Dashboard namespace, then schema validation fails
- it: with invalid Dashboard namespace, schema validation fails
set:
monitoring:
enabled: true
Expand Down Expand Up @@ -106,6 +127,25 @@ tests:
name: hivemq-platform-operator-dashboard-custom-release-name
namespace: my-custom-dashboard-namespace

- it: with monitoring enabled and overrideDashboard set, custom ConfigMap spec created with custom values
set:
monitoring:
enabled: true
dashboard:
overrideDashboard: |-
{
"my-custom-grafana-title": "foobar"
}
asserts:
- exists:
path: data["operator-dashboard.json"]
- equal:
path: data["operator-dashboard.json"]
value: |
{
"my-custom-grafana-title": "foobar"
}
- it: with monitoring enabled and default values, ConfigMap spec created with defaults values
set:
monitoring.enabled: true
Expand Down
15 changes: 14 additions & 1 deletion charts/hivemq-platform-operator/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,23 @@
"dashboard" : {
"description" : "Dashboard configuration options.",
"properties" : {
"create" : {
"description" : "Creates a default HiveMQ Platform Operator Grafana dashboard ConfigMap.",
"type": "boolean"
},
"name" : {
"description" : "Overrides the default HiveMQ Platform Operator Grafana dashboard by providing the name of a Kubernetes ConfigMap that contains the Grafana dashboard.",
"maxLength": 63,
"type": "string"
},
"namespace" : {
"description" : "Namespace where the Grafana dashboard ConfigMap will be deployed to. Defaults to use the same namespace where the HiveMQ Platform Operator chart is deployed to.",
"description" : "Namespace where the Grafana dashboard ConfigMap will be deployed to. Defaults to use the same namespace where the HiveMQ Platform chart is deployed to.",
"maxLength": 63,
"type": "string"
},
"overrideDashboard" : {
"description" : "Overrides the default HiveMQ Platform Operator Grafana dashboard content via file using --set-file grafana-dashboard.json.",
"type": "string"
}
},
"type": "object"
Expand Down
23 changes: 15 additions & 8 deletions charts/hivemq-platform-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,26 @@ monitoring:
# When enabled, deploys a ServiceMonitor resource for the Operator along with a Configmap for a Grafana dashboard.
enabled: false
# Dashboard configuration options.
# dashboard:
# Namespace where the Grafana dashboard ConfigMap will be deployed to. Defaults to use the same namespace where the HiveMQ Platform Operator Helm chart is deployed to.
# namespace: monitoring
# ServiceMonitor configuration options.
dashboard:
# Creates a default HiveMQ Platform Operator Grafana dashboard ConfigMap.
create: true
# Namespace where to deploy the Grafana dashboard ConfigMap. Defaults to the namespace of the HiveMQ Platform Operator.
# namespace: monitoring
# The name of a Kubernetes ConfigMap with a custom HiveMQ Platform Operator Grafana dashboard to override the default dashboard.
# (also set create=false).
# Grafana dashboard ConfigMap content must be in JSON format along with the label `grafana_dashboard: "1"`
name: ""
# Overrides the default HiveMQ Platform Grafana Operator dashboard content via file using --set-file grafana-dashboard.json.
overrideDashboard: ""
serviceMonitor:
# Namespace where the ServiceMonitor will be deployed to. Defaults to use the same namespace where the HiveMQ Platform Operator Helm chart is deployed to.
# Namespace where to deploy the ServiceMonitor. Defaults to the namespace of the HiveMQ Platform Operator.
# namespace: monitoring
# Helm chart release name of the Prometheus Monitoring stack available in the Kubernetes cluster.
# This allows the Prometheus operator to discover the HiveMQ Platform Operator ServiceMonitor. Defaults to the HiveMQ Platform Operator Helm chart release name.
# The release name allows the Prometheus operator to discover the HiveMQ Platform Operator ServiceMonitor. Defaults to the HiveMQ Platform Operator Helm chart release name.
# releaseName: monitoring-stack
# Defines how often Prometheus should scrape metrics from the endpoints defined in the ServiceMonitor resource.
# Format is based on the regular expression `(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)`. For example 1d, 1h30m, 5m, 10s.
# Example of a valid format are `1d`, `1h30m`, `5m`, `10s`.
interval: 15s
# Defines the maximum duration allowed for scraping metrics from the endpoints defined in the ServiceMonitor resource.
# Format is based on the regular expression `(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)`. For example 1d, 1h30m, 5m, 10s.
# Example of a valid format are `1d`, `1h30m`, `5m`, `10s`.
scrapeTimeout: 10s
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.monitoring.enabled }}
{{- if and .Values.monitoring.enabled .Values.monitoring.dashboard.create }}
{{- include "hivemq-platform.validate-prometheus-monitoring-stack-installed" . -}}
apiVersion: v1
kind: ConfigMap
Expand All @@ -13,6 +13,13 @@ metadata:
namespace: {{ .Release.Namespace }}
{{- end }}
data:
{{- if .Values.monitoring.dashboard.overrideDashboard }}
hivemq-dashboard.json: |
{{- range .Values.monitoring.dashboard.overrideDashboard | toStrings }}
{{ . | nindent 4 }}
{{- end }}
{{- else }}
hivemq-dashboard.json: |
{{- .Files.Get "files/grafana-dashboard.json" | nindent 4 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ tests:
- hasDocuments:
count: 1

- it: with monitoring enabled and create disabled, ConfigMap not created
set:
monitoring:
enabled: true
dashboard:
create: false
asserts:
- notFailedTemplate: {}
- hasDocuments:
count: 0

- it: with monitoring enabled, create disabled and invalid ConfigMap name, schema validation fails
set:
monitoring:
enabled: true
dashboard:
create: false
name: this-is-a-very-long-hivemq-platform-operator-grafana-dashboard-configmap-name
asserts:
- failedTemplate: {}

- it: with long Helm release name, ConfigMap name truncated
release:
name: a-very-long-hivemq-platform-release-name
Expand All @@ -45,7 +66,7 @@ tests:
- failedTemplate:
errorPattern: There is no Prometheus ServiceMonitor CustomResourceDefinition \(CRD\) available in your Kubernetes cluster. Prometheus Monitoring CRDs are required before installing the ServiceMonitor resource.

- it: with invalid Dashboard namespace, then schema validation fails
- it: with invalid Dashboard namespace, schema validation fails
set:
monitoring:
enabled: true
Expand Down Expand Up @@ -106,6 +127,25 @@ tests:
name: hivemq-platform-dashboard-custom-release-name
namespace: my-custom-dashboard-namespace

- it: with monitoring enabled and overrideDashboard set, custom ConfigMap spec created with custom values
set:
monitoring:
enabled: true
dashboard:
overrideDashboard: |-
{
"my-custom-grafana-title": "foobar"
}
asserts:
- exists:
path: data["hivemq-dashboard.json"]
- equal:
path: data["hivemq-dashboard.json"]
value: |
{
"my-custom-grafana-title": "foobar"
}
- it: with monitoring enabled and default values, ConfigMap spec created with defaults values
set:
monitoring.enabled: true
Expand Down
13 changes: 13 additions & 0 deletions charts/hivemq-platform/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,23 @@
"dashboard" : {
"description" : "Dashboard configuration options.",
"properties" : {
"create" : {
"description" : "Creates a default HiveMQ Platform Grafana dashboard ConfigMap.",
"type": "boolean"
},
"name" : {
"description" : "Overrides the default HiveMQ Platform Grafana dashboard by providing the name of a Kubernetes ConfigMap that contains the Grafana dashboard.",
"maxLength": 63,
"type": "string"
},
"namespace" : {
"description" : "Namespace where the Grafana dashboard ConfigMap will be deployed to. Defaults to use the same namespace where the HiveMQ Platform chart is deployed to.",
"maxLength": 63,
"type": "string"
},
"overrideDashboard" : {
"description" : "Overrides the default HiveMQ Platform Grafana dashboard content via file using --set-file grafana-dashboard.json.",
"type": "string"
}
},
"type": "object"
Expand Down
26 changes: 17 additions & 9 deletions charts/hivemq-platform/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -627,19 +627,27 @@ monitoring:
# When enabled, deploys a ServiceMonitor resource for the HiveMQ Platform along with a Configmap for a Grafana dashboard.
enabled: false
# Dashboard configuration options.
# dashboard:
# Namespace where the Grafana dashboard ConfigMap will be deployed to. Defaults to use the same namespace where the HiveMQ Platform chart is deployed to.
# namespace: monitoring
dashboard:
# Creates a default HiveMQ Platform Grafana dashboard ConfigMap.
create: true
# Namespace where to deploy the Grafana dashboard ConfigMap. Defaults to the namespace of the HiveMQ Platform.
# namespace: monitoring
# The name of a Kubernetes ConfigMap with a custom HiveMQ Platform Grafana dashboard to override the default dashboard.
# (also set create=false).
# Grafana dashboard ConfigMap content must be in JSON format along with the label `grafana_dashboard: "1"`
name: ""
# Overrides the default HiveMQ Platform Grafana dashboard content via file using --set-file grafana-dashboard.json.
overrideDashboard: ""
# ServiceMonitor configuration options.
serviceMonitor:
# Release name of the Prometheus Monitoring stack available in the Kubernetes cluster.
# This allows the Prometheus operator to discover the HiveMQ Platform ServiceMonitor. Defaults to the HiveMQ Platform release name.
# releaseName: monitoring-stack
# Namespace where the ServiceMonitor will be deployed to. Defaults to use the same namespace where the HiveMQ Platform chart is deployed to.
# Namespace where to deploy the ServiceMonitor. Defaults to the namespace of the HiveMQ Platform.
# namespace: monitoring
# Helm chart release name of the Prometheus Monitoring stack available in the Kubernetes cluster.
# The release name allows the Prometheus operator to discover the HiveMQ Platform ServiceMonitor. Defaults to the HiveMQ Platform Helm chart release name.
# releaseName: monitoring-stack
# Defines how often Prometheus should scrape metrics from the endpoints defined in the ServiceMonitor resource.
# Format is based on the regular expression `(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)`. For example 1d, 1h30m, 5m, 10s.
# Example of a valid format are `1d`, `1h30m`, `5m`, `10s`.
interval: 15s
# Defines the maximum duration allowed for scraping metrics from the endpoints defined in the ServiceMonitor resource.
# Format is based on the regular expression `(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)`. For example 1d, 1h30m, 5m, 10s.
# Example of a valid format are `1d`, `1h30m`, `5m`, `10s`.
scrapeTimeout: 10s

0 comments on commit e23358a

Please sign in to comment.