From 72f81fad4fbcdc7c7496fd2cf1f75af88ebe1f64 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Sun, 7 Jan 2024 13:42:30 +0100 Subject: [PATCH] feat(prometheus, prometheus-operator): add support for automatic grafana datasources/dashboards (#16917) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** This PR aims to do two things: 1. It enabled automatic loading of grafana dashboards to the prometheus-operator. Dashboards fetched directly from upstream 2. It enables automatic loading of Prometheus as grafana datasource Why have the dashboards on the operator? We use upstream operator helm-chart dependency, which already allows us to use the latest dashboards from upstream. Without custom code, copying etc. Which limits the chance of mistakes/bugs. **โš™๏ธ Type of change** - [x] โš™๏ธ Feature/App addition - [ ] ๐Ÿช› Bugfix - [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] ๐Ÿ”ƒ Refactor of current code **๐Ÿงช How Has This Been Tested?** **๐Ÿ“ƒ Notes:** **โœ”๏ธ Checklist:** - [ ] โš–๏ธ My code follows the style guidelines of this project - [ ] ๐Ÿ‘€ I have performed a self-review of my own code - [ ] #๏ธโƒฃ I have commented my code, particularly in hard-to-understand areas - [ ] ๐Ÿ“„ I have made corresponding changes to the documentation - [ ] โš ๏ธ My changes generate no new warnings - [ ] ๐Ÿงช I have added tests to this description that prove my fix is effective or that my feature works - [ ] โฌ†๏ธ I increased versions for any altered app according to semantic versioning **โž• App addition** If this PR is an app addition please make sure you have done the following. - [ ] ๐Ÿชž I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] ๐Ÿ–ผ๏ธ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --- charts/enterprise/prometheus/Chart.yaml | 2 +- charts/enterprise/prometheus/questions.yaml | 4 +-- charts/enterprise/prometheus/values.yaml | 34 +++++++++++++++++-- .../operators/prometheus-operator/Chart.yaml | 2 +- .../operators/prometheus-operator/values.yaml | 1 + 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/charts/enterprise/prometheus/Chart.yaml b/charts/enterprise/prometheus/Chart.yaml index 3258f798c78..34539c9039a 100644 --- a/charts/enterprise/prometheus/Chart.yaml +++ b/charts/enterprise/prometheus/Chart.yaml @@ -1,7 +1,7 @@ kubeVersion: ">=1.24.0-0" apiVersion: v2 name: prometheus -version: 16.1.9 +version: 16.2.0 appVersion: 2.48.1 description: kube-prometheus-stack collects Kubernetes manifests, Grafana dashboards, and Prometheus rules combined with documentation and scripts to provide easy to operate end-to-end Kubernetes cluster monitoring with Prometheus using the Prometheus Operator. home: https://truecharts.org/charts/enterprise/prometheus diff --git a/charts/enterprise/prometheus/questions.yaml b/charts/enterprise/prometheus/questions.yaml index 72689e3ac7e..545d8bec543 100644 --- a/charts/enterprise/prometheus/questions.yaml +++ b/charts/enterprise/prometheus/questions.yaml @@ -194,7 +194,7 @@ questions: description: "This port exposes the container port on the service" schema: type: int - default: 10086 + default: 9090 required: true - variable: alertmanager label: "alertmanager Service" @@ -216,7 +216,7 @@ questions: description: "This port exposes the container port on the service" schema: type: int - default: 10087 + default: 9093 required: true # Include{serviceExpertRoot} # Include{serviceExpert} diff --git a/charts/enterprise/prometheus/values.yaml b/charts/enterprise/prometheus/values.yaml index e69d185b554..704cfe9f417 100644 --- a/charts/enterprise/prometheus/values.yaml +++ b/charts/enterprise/prometheus/values.yaml @@ -23,6 +23,36 @@ workload: enabled: false startup: enabled: false + + +configmap: + grafana-datasource: + enabled: "{{ if .Values.grafana.datasource.enabled }}true{{ else }}false{{ end }}" + data: + datasource.yaml: |- + apiVersion: 1 + datasources: + - name: Prometheus + type: prometheus + uid: {{ .Values.grafana.datasource.uid | default "prometheus" }} + url: http://{{ include "tc.v1.common.lib.chart.names.fullname" $ }}.{{ include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $ "objectData" . "caller" "Configmap") }}:{{ .Values.service.main.ports.main.port }} + access: proxy + isDefault: {{ .Values.grafana.datasource.default | default true }} + jsonData: + httpMethod: {{ .Values.grafana.datasource.httpMethod | default "POST" }} + timeInterval: {{ .Values.grafana.datasource.scrapeInterval | default "30s" }} + {{- if .Values.grafana.datasource.timeout }} + timeout: {{ .Values.grafana.datasource.timeout }} + {{- end }} + +grafana: + datasource: + enabled: true + default: true + httpMethod: "POST" + scrapeInterval: "30s" + uid: "prometheus" + service: main: selectorLabels: @@ -30,7 +60,7 @@ service: prometheus: '{{ template "kube-prometheus.prometheus.fullname" . }}' ports: main: - port: 10086 + port: 9090 targetPort: 9090 protocol: http alertmanager: @@ -41,7 +71,7 @@ service: ports: alertmanager: enabled: true - port: 10087 + port: 9093 targetPort: 9093 protocol: http thanos: diff --git a/charts/operators/prometheus-operator/Chart.yaml b/charts/operators/prometheus-operator/Chart.yaml index 65643d54768..f64f9b5b8b2 100644 --- a/charts/operators/prometheus-operator/Chart.yaml +++ b/charts/operators/prometheus-operator/Chart.yaml @@ -1,7 +1,7 @@ kubeVersion: ">=1.24.0-0" apiVersion: v2 name: prometheus-operator -version: 4.1.0 +version: 4.2.0 appVersion: latest description: Prometheus Operator is an operator for prometheus home: https://truecharts.org/charts/operators/prometheus-operator diff --git a/charts/operators/prometheus-operator/values.yaml b/charts/operators/prometheus-operator/values.yaml index c1a8fae2185..98f9d1dc2b8 100644 --- a/charts/operators/prometheus-operator/values.yaml +++ b/charts/operators/prometheus-operator/values.yaml @@ -74,6 +74,7 @@ kps: ## grafana: enabled: false + forceDeployDashboards: true ## Flag to disable all the kubernetes component scrapers ##