From 07f719152ed2bc7c6616ad1d5202d8f519b8a69d Mon Sep 17 00:00:00 2001 From: Michel Hollands Date: Thu, 22 Jun 2023 13:18:11 +0100 Subject: [PATCH] Add local.enabled setting and make it work Signed-off-by: Michel Hollands --- charts/meta-monitoring/Chart.yaml | 4 ++- .../templates/agent/_helpers-agent.tpl | 22 +++++++++++++ .../templates/agent/config.yaml | 31 +++++++++++++++++-- .../templates/grafana/configmap-1.yaml | 4 ++- .../templates/grafana/configmap-2.yaml | 4 ++- .../templates/grafana/dashboard.yaml | 4 ++- .../templates/grafana/datasources.yaml | 4 ++- .../templates/grafana/grafana.yaml | 4 ++- charts/meta-monitoring/values.yaml | 12 +++++++ 9 files changed, 80 insertions(+), 9 deletions(-) diff --git a/charts/meta-monitoring/Chart.yaml b/charts/meta-monitoring/Chart.yaml index 8c4ba98..dde9cb7 100644 --- a/charts/meta-monitoring/Chart.yaml +++ b/charts/meta-monitoring/Chart.yaml @@ -27,9 +27,11 @@ dependencies: - name: loki repository: https://grafana.github.io/helm-charts version: "5.8.0" + condition: local.enabled - name: grafana-agent repository: https://grafana.github.io/helm-charts version: "0.15.0" - name: mimir-distributed repository: https://grafana.github.io/helm-charts - version: "4.4.1" \ No newline at end of file + version: "4.4.1" + condition: local.enabled \ No newline at end of file diff --git a/charts/meta-monitoring/templates/agent/_helpers-agent.tpl b/charts/meta-monitoring/templates/agent/_helpers-agent.tpl index 7ef0195..8cf12ae 100644 --- a/charts/meta-monitoring/templates/agent/_helpers-agent.tpl +++ b/charts/meta-monitoring/templates/agent/_helpers-agent.tpl @@ -5,3 +5,25 @@ {{- end }} {{- join ", " $list }} {{- end }} + +{{- define "agent.loki_write_targets" -}} +{{- $list := list }} +{{- if .Values.local.enabled }} +{{- $list = append $list ("loki.write.local.receiver") }} +{{- end }} +{{- if .Values.cloud.enabled }} +{{- $list = append $list ("loki.write.cloud.receiver") }} +{{- end }} +{{- join ", " $list }} +{{- end }} + +{{- define "agent.prometheus_write_targets" -}} +{{- $list := list }} +{{- if .Values.local.enabled }} +{{- $list = append $list ("prometheus.remote_write.local.receiver") }} +{{- end }} +{{- if .Values.cloud.enabled }} +{{- $list = append $list ("prometheus.remote_write.cloud.receiver") }} +{{- end }} +{{- join ", " $list }} +{{- end }} \ No newline at end of file diff --git a/charts/meta-monitoring/templates/agent/config.yaml b/charts/meta-monitoring/templates/agent/config.yaml index 80834eb..06d5ca7 100644 --- a/charts/meta-monitoring/templates/agent/config.yaml +++ b/charts/meta-monitoring/templates/agent/config.yaml @@ -32,7 +32,7 @@ data: } loki.process "loki" { - forward_to = [loki.write.local.receiver] + forward_to = [ {{ include "agent.loki_write_targets" . }} ] stage.static_labels { values = { @@ -47,19 +47,44 @@ data: prometheus.scrape "pods" { targets = discovery.relabel.rename_meta_labels.output - forward_to = [prometheus.remote_write.default.receiver] + forward_to = [ {{ include "agent.prometheus_write_targets" . }} ] } + + {{- if .Values.local.enabled }} loki.write "local" { endpoint { url = "http://{{- .Release.Name -}}-loki.{{- .Release.Namespace -}}.svc.cluster.local:3100/loki/api/v1/push" } } - prometheus.remote_write "default" { + prometheus.remote_write "local" { endpoint { url = "http://{{- .Release.Name -}}-mimir-nginx.{{- .Release.Namespace -}}.svc:80/api/v1/push" } } + {{- end }} + {{- if .Values.cloud.enabled }} + loki.write "cloud" { + endpoint { + url = "{{- .Values.cloud.logs.endpoint -}}/loki/api/v1/push" + basic_auth { + username = "{{- .Values.cloud.logs.username -}}" + password = "{{- .Values.cloud.logs.password -}}" + } + } + } + + prometheus.remote_write "cloud" { + endpoint { + url = "{{- .Values.cloud.metrics.endpoint -}}/api/prom/push" + + basic_auth { + username = "{{- .Values.cloud.metrics.username -}}" + password = "{{- .Values.cloud.metrics.password -}}" + } + } + } + {{- end }} \ No newline at end of file diff --git a/charts/meta-monitoring/templates/grafana/configmap-1.yaml b/charts/meta-monitoring/templates/grafana/configmap-1.yaml index db257bb..0557dae 100644 --- a/charts/meta-monitoring/templates/grafana/configmap-1.yaml +++ b/charts/meta-monitoring/templates/grafana/configmap-1.yaml @@ -1,3 +1,4 @@ +{{ if .Values.local.enabled }} --- apiVersion: v1 kind: ConfigMap @@ -14,4 +15,5 @@ data: "loki-mixin-recording-rules.json": | {{ $.Files.Get "src/dashboards/loki-mixin-recording-rules.json" | fromJson | toJson }} "loki-operational.json": | - {{ $.Files.Get "src/dashboards/loki-operational.json" | fromJson | toJson }} \ No newline at end of file + {{ $.Files.Get "src/dashboards/loki-operational.json" | fromJson | toJson }} +{{- end }} \ No newline at end of file diff --git a/charts/meta-monitoring/templates/grafana/configmap-2.yaml b/charts/meta-monitoring/templates/grafana/configmap-2.yaml index d7c6479..c41a732 100644 --- a/charts/meta-monitoring/templates/grafana/configmap-2.yaml +++ b/charts/meta-monitoring/templates/grafana/configmap-2.yaml @@ -1,3 +1,4 @@ +{{ if .Values.local.enabled }} --- apiVersion: v1 kind: ConfigMap @@ -14,4 +15,5 @@ data: "loki-writes-resources.json": | {{ $.Files.Get "src/dashboards/loki-writes-resources.json" | fromJson | toJson }} "loki-writes.json": | - {{ $.Files.Get "src/dashboards/loki-writes.json" | fromJson | toJson }} \ No newline at end of file + {{ $.Files.Get "src/dashboards/loki-writes.json" | fromJson | toJson }} +{{- end }} \ No newline at end of file diff --git a/charts/meta-monitoring/templates/grafana/dashboard.yaml b/charts/meta-monitoring/templates/grafana/dashboard.yaml index 6f20359..be2761a 100644 --- a/charts/meta-monitoring/templates/grafana/dashboard.yaml +++ b/charts/meta-monitoring/templates/grafana/dashboard.yaml @@ -1,3 +1,4 @@ +{{ if .Values.local.enabled }} --- apiVersion: v1 kind: ConfigMap @@ -24,4 +25,5 @@ data: options: path: /var/lib/grafana/dashboards/loki-2 orgId: 1 - type: file \ No newline at end of file + type: file +{{- end }} \ No newline at end of file diff --git a/charts/meta-monitoring/templates/grafana/datasources.yaml b/charts/meta-monitoring/templates/grafana/datasources.yaml index f2730db..d4e2bc2 100644 --- a/charts/meta-monitoring/templates/grafana/datasources.yaml +++ b/charts/meta-monitoring/templates/grafana/datasources.yaml @@ -1,3 +1,4 @@ +{{ if .Values.local.enabled }} --- apiVersion: v1 kind: ConfigMap @@ -56,4 +57,5 @@ data: isDefault: # Allows users to edit data sources from the # Grafana UI. - editable: true \ No newline at end of file + editable: true +{{- end }} \ No newline at end of file diff --git a/charts/meta-monitoring/templates/grafana/grafana.yaml b/charts/meta-monitoring/templates/grafana/grafana.yaml index cc5afe6..d9765bb 100644 --- a/charts/meta-monitoring/templates/grafana/grafana.yaml +++ b/charts/meta-monitoring/templates/grafana/grafana.yaml @@ -1,3 +1,4 @@ +{{ if .Values.local.enabled }} --- apiVersion: v1 kind: PersistentVolumeClaim @@ -100,4 +101,5 @@ spec: selector: app: grafana sessionAffinity: None - type: ClusterIP # Make this configurable \ No newline at end of file + type: ClusterIP # Make this configurable +{{- end }} \ No newline at end of file diff --git a/charts/meta-monitoring/values.yaml b/charts/meta-monitoring/values.yaml index bb80753..0e102dc 100644 --- a/charts/meta-monitoring/values.yaml +++ b/charts/meta-monitoring/values.yaml @@ -3,6 +3,18 @@ namespacesToMonitor: - mimir - tempo clusterName: "observability" # TODO check if this can be derived +local: + enabled: false +cloud: + enabled: true + logs: + endpoint: + username: + password: + metrics: + endpoint: + username: + password: # The following are configuration for the dependencies. # These should not be changed.