diff --git a/charts/k8s-monitoring/charts/feature-integrations/docs/integrations/grafana.md b/charts/k8s-monitoring/charts/feature-integrations/docs/integrations/grafana.md index 00d9246fe..d722b4f11 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/docs/integrations/grafana.md +++ b/charts/k8s-monitoring/charts/feature-integrations/docs/integrations/grafana.md @@ -7,7 +7,7 @@ | Key | Type | Default | Description | |-----|------|---------|-------------| | fieldSelectors | list | `[]` | Discover Grafana instances based on field selectors. | -| labelSelectors | object | `{}` | Discover Grafana instances based on label selectors. Will automatically set a matcher for `app.kubernetes.io/name: ` unless set here. | +| labelSelectors | object | `{}` | Discover Grafana instances based on label selectors. | | metrics.portName | string | `"grafana"` | Name of the port to scrape metrics from. | | namespaces | list | `[]` | The namespaces to look for Grafana instances in. Will automatically look for Grafana instances in all namespaces unless specified here | @@ -18,7 +18,7 @@ | logs.enabled | bool | `true` | Whether to enable special processing of Grafana pod logs. | | logs.tuning.dropLogLevels | list | `[]` | The log levels to drop. Will automatically keep all log levels unless specified here. | | logs.tuning.excludeLines | list | `[]` | Line patterns (valid RE2 regular expression)to exclude from the logs. | -| logs.tuning.scrubTimestamp | bool | `true` | Whether or not the timestamp should be scrubbed from the log line | +| logs.tuning.scrubTimestamp | bool | `true` | Whether the timestamp should be scrubbed from the log line | | logs.tuning.structuredMetadata | object | `{}` | The structured metadata mappings to set. To not set any structured metadata, set this to an empty object (e.g. `{}`) | | logs.tuning.timestampFormat | string | `"RFC3339Nano"` | The timestamp format to use for the log line, if not set the default timestamp which is the collection will be used for the log line | diff --git a/charts/k8s-monitoring/charts/feature-integrations/integrations/grafana-values.yaml b/charts/k8s-monitoring/charts/feature-integrations/integrations/grafana-values.yaml index 9b5a4fdd9..c870f4110 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/integrations/grafana-values.yaml +++ b/charts/k8s-monitoring/charts/feature-integrations/integrations/grafana-values.yaml @@ -3,11 +3,6 @@ # @section -- General Settings name: "" -# -- Discover Grafana instances based on label selectors. -# Will automatically set a matcher for `app.kubernetes.io/name: ` unless set here. -# @section -- Discovery Settings -labelSelectors: {} - # -- The namespaces to look for Grafana instances in. # Will automatically look for Grafana instances in all namespaces unless specified here # @section -- Discovery Settings @@ -17,6 +12,10 @@ namespaces: [] # @section -- Discovery Settings fieldSelectors: [] +# -- Discover Grafana instances based on label selectors. +# @section -- Discovery Settings +labelSelectors: {} + # Settings for metrics collection metrics: # -- Whether to enable metrics collection from Grafana. @@ -67,7 +66,7 @@ logs: # @section -- Logs Settings timestampFormat: "RFC3339Nano" - # -- Whether or not the timestamp should be scrubbed from the log line + # -- Whether the timestamp should be scrubbed from the log line # @section -- Logs Settings scrubTimestamp: true diff --git a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana.tpl b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana.tpl index 67677ba73..a65e96eea 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana.tpl +++ b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana.tpl @@ -1,3 +1,22 @@ -{{- define "integrations.grafana.defaultSelectorLabel" -}}app.kubernetes.io/name{{- end }} -{{- define "integrations.grafana.defaultSelectorValue" -}}grafana{{- end }} -{{- define "integrations.grafana.validate" }}{{- end }} +{{- define "integrations.grafana.validate" }} + {{- range $instance := $.Values.grafana.instances }} + {{- include "integrations.grafana.instance.validate" (merge $ (dict "instance" $instance)) | nindent 2 }} + {{- end }} +{{- end }} + +{{- define "integrations.grafana.instance.validate" }} + {{- if not .instance.labelSelectors }} + {{- $msg := list "" "The Grafana integration requires a label selector" }} + {{- $msg = append $msg "For example, please set:" }} + {{- $msg = append $msg "integrations:" }} + {{- $msg = append $msg " grafana:" }} + {{- $msg = append $msg " instances:" }} + {{- $msg = append $msg (printf " - name: %s" .instance.name) }} + {{- $msg = append $msg " labelSelectors:" }} + {{- $msg = append $msg (printf " app.kubernetes.io/name: %s" .instance.name) }} + {{- $msg = append $msg "OR" }} + {{- $msg = append $msg " labelSelectors:" }} + {{- $msg = append $msg " app.kubernetes.io/name: [grafana-one, grafana-two]" }} + {{- fail (join "\n" $msg) }} + {{- end }} +{{- end }} diff --git a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana_logs.tpl b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana_logs.tpl index fe954843d..e0c7f5363 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana_logs.tpl +++ b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana_logs.tpl @@ -17,14 +17,18 @@ {{- if .logs.enabled }} {{- $labelList := list }} {{- $valueList := list }} - {{- $selectors := dict (include "integrations.grafana.defaultSelectorLabel" $) ($instance.name | default (include "integrations.grafana.defaultSelectorValue" $)) }} - {{- if $instance.labelSelectors }} - {{- $selectors = $instance.labelSelectors }} + {{- if .namespaces }} + {{- $labelList = append $labelList "__meta_kubernetes_namespace" -}} + {{- $valueList = append $valueList (printf "(%s)" (join "|" .namespaces)) -}} {{- end }} - - {{- range (keys $selectors) }} - {{- $labelList = append $labelList (include "pod_label" .) -}} - {{- $valueList = append $valueList (index $selectors .) -}} + {{- range $k, $v := .labelSelectors }} + {{- if kindIs "slice" $v }} + {{- $labelList = append $labelList (include "pod_label" $k) -}} + {{- $valueList = append $valueList (printf "(%s)" (join "|" $v)) -}} + {{- else }} + {{- $labelList = append $labelList (include "pod_label" $k) -}} + {{- $valueList = append $valueList $v -}} + {{- end }} {{- end }} rule { source_labels = {{ $labelList | sortAlpha | toJson }} diff --git a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana_metrics.tpl b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana_metrics.tpl index 4f84b4ade..6334bd9f6 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana_metrics.tpl +++ b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_grafana_metrics.tpl @@ -88,6 +88,11 @@ declare "grafana_integration" { comment = "Must be a list(MetricsReceiver) where collected metrics should be forwarded to" } + argument "job_label" { + comment = "The job label to add for all Loki metrics (default: integrations/grafana)" + optional = true + } + argument "keep_metrics" { comment = "A regular expression of metrics to keep (default: see below)" optional = true @@ -114,7 +119,7 @@ declare "grafana_integration" { } prometheus.scrape "grafana" { - job_name = "integrations/grafana" + job_name = coalesce(argument.job_label.value, "integrations/grafana") forward_to = [prometheus.relabel.grafana.receiver] targets = argument.targets.value scrape_interval = coalesce(argument.scrape_interval.value, "60s") @@ -148,35 +153,28 @@ declare "grafana_integration" { {{- define "integrations.grafana.include.metrics" }} {{- $defaultValues := "integrations/grafana-values.yaml" | .Files.Get | fromYaml }} {{- with $defaultValues | merge (deepCopy .instance) }} - {{- $metricAllowList := include "integrations.grafana.allowList" (dict "instance" . "Files" $.Files) | fromYamlArray }} - {{- $metricDenyList := .excludeMetrics }} - - {{- $nameLabelDefined := false }} - {{- $labelSelectors := list }} - {{- range $k, $v := .labelSelectors }} - {{- if eq $k "app.kubernetes.io/name" }}{{- $nameLabelDefined = true }}{{- end }} - {{- if $v }} - {{- $labelSelectors = append $labelSelectors (printf "%s=%s" $k $v) }} - {{- end }} - {{- end }} - {{- if not $nameLabelDefined }} - {{- $labelSelectors = append $labelSelectors (printf "app.kubernetes.io/name=%s" .name) }} - {{- end }} - {{- $fieldSelectors := list }} - {{- range $k, $v := .fieldSelectors }} - {{- $fieldSelectors = append $fieldSelectors (printf "%s=%s" $k $v) }} +{{- $metricAllowList := include "integrations.grafana.allowList" (dict "instance" . "Files" $.Files) | fromYamlArray }} +{{- $metricDenyList := .excludeMetrics }} +{{- $labelSelectors := list }} +{{- range $k, $v := .labelSelectors }} + {{- if kindIs "slice" $v }} + {{- $labelSelectors = append $labelSelectors (printf "%s in (%s)" $k (join "," $v)) }} + {{- else }} + {{- $labelSelectors = append $labelSelectors (printf "%s=%s" $k $v) }} {{- end }} +{{- end }} grafana_integration_discovery {{ include "helper.alloy_name" .name | quote }} { namespaces = {{ .namespaces | toJson }} label_selectors = {{ $labelSelectors | toJson }} -{{- if $fieldSelectors }} - field_selectors = {{ $fieldSelectors | toJson }} +{{- if .fieldSelectors }} + field_selectors = {{ .fieldSelectors | toJson }} {{- end }} port_name = {{ .metrics.portName | quote }} } grafana_integration_scrape {{ include "helper.alloy_name" .name | quote }} { targets = grafana_integration_discovery.{{ include "helper.alloy_name" .name }}.output + job_label = {{ .jobLabel | quote }} clustering = true {{- if $metricAllowList }} keep_metrics = {{ $metricAllowList | join "|" | quote }} diff --git a/charts/k8s-monitoring/charts/feature-integrations/tests/grafana_logs_test.yaml b/charts/k8s-monitoring/charts/feature-integrations/tests/grafana_logs_test.yaml index d778311b8..fca0fb872 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/tests/grafana_logs_test.yaml +++ b/charts/k8s-monitoring/charts/feature-integrations/tests/grafana_logs_test.yaml @@ -10,6 +10,8 @@ tests: grafana: instances: - name: grafana + labelSelectors: + app.kubernetes.io/name: grafana asserts: - isKind: of: ConfigMap @@ -90,6 +92,8 @@ tests: grafana: instances: - name: grafana + labelSelectors: + app.kubernetes.io/name: grafana logs: tuning: timestampFormat: "RFC3339" @@ -110,6 +114,8 @@ tests: grafana: instances: - name: grafana + labelSelectors: + app.kubernetes.io/name: grafana logs: tuning: scrubTimestamp: true @@ -135,6 +141,8 @@ tests: grafana: instances: - name: grafana + labelSelectors: + app.kubernetes.io/name: grafana logs: tuning: structuredMetadata: @@ -159,6 +167,8 @@ tests: grafana: instances: - name: grafana + labelSelectors: + app.kubernetes.io/name: grafana logs: tuning: dropLogLevels: @@ -187,6 +197,8 @@ tests: grafana: instances: - name: grafana + labelSelectors: + app.kubernetes.io/name: grafana logs: tuning: excludeLines: diff --git a/charts/k8s-monitoring/charts/feature-integrations/tests/grafana_metrics_test.yaml b/charts/k8s-monitoring/charts/feature-integrations/tests/grafana_metrics_test.yaml index 2ee1129bc..d02db39c5 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/tests/grafana_metrics_test.yaml +++ b/charts/k8s-monitoring/charts/feature-integrations/tests/grafana_metrics_test.yaml @@ -10,6 +10,8 @@ tests: grafana: instances: - name: grafana + labelSelectors: + app.kubernetes.io/name: grafana asserts: - isKind: of: ConfigMap @@ -228,36 +230,6 @@ tests: } } - - it: should allow you to overwrite the name label - set: - deployAsConfigMap: true - alloy: - instances: - - name: grafana - labelSelectors: - app.kubernetes.io/name: my-grafana-instance - asserts: - - isKind: - of: ConfigMap - - matchRegex: - path: data["metrics.alloy"] - pattern: label_selectors = \["app.kubernetes.io/name=my-grafana-instance"\] - - - it: should allow you to dismiss the name label - set: - deployAsConfigMap: true - alloy: - instances: - - name: grafana - labelSelectors: - app.kubernetes.io/name: null - app.kubernetes.io/instance: k8smon - asserts: - - isKind: - of: ConfigMap - - matchRegex: - path: data["metrics.alloy"] - pattern: label_selectors = \["app.kubernetes.io/instance=k8smon"\] - it: should allow you to restrict the namespaces for metrics set: @@ -267,6 +239,8 @@ tests: - name: grafana namespaces: - k8smon + labelSelectors: + app.kubernetes.io/name: grafana asserts: - isKind: of: ConfigMap diff --git a/charts/k8s-monitoring/charts/feature-integrations/tests/loki_logs_test.yaml b/charts/k8s-monitoring/charts/feature-integrations/tests/loki_logs_test.yaml index 8bbbb7ba9..394b1c49e 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/tests/loki_logs_test.yaml +++ b/charts/k8s-monitoring/charts/feature-integrations/tests/loki_logs_test.yaml @@ -10,6 +10,8 @@ tests: loki: instances: - name: loki + labelSelectors: + app.kubernetes.io/name: loki asserts: - isKind: of: ConfigMap @@ -74,6 +76,8 @@ tests: loki: instances: - name: loki + labelSelectors: + app.kubernetes.io/name: loki namespaces: - k8smon asserts: @@ -89,6 +93,8 @@ tests: loki: instances: - name: loki + labelSelectors: + app.kubernetes.io/name: loki logs: tuning: timestampFormat: "RFC3339" @@ -109,6 +115,8 @@ tests: loki: instances: - name: loki + labelSelectors: + app.kubernetes.io/name: loki logs: tuning: scrubTimestamp: true @@ -134,6 +142,8 @@ tests: loki: instances: - name: loki + labelSelectors: + app.kubernetes.io/name: loki logs: tuning: structuredMetadata: @@ -156,6 +166,8 @@ tests: loki: instances: - name: loki + labelSelectors: + app.kubernetes.io/name: loki logs: tuning: dropLogLevels: @@ -184,6 +196,8 @@ tests: loki: instances: - name: loki + labelSelectors: + app.kubernetes.io/name: loki logs: tuning: excludeLines: diff --git a/charts/k8s-monitoring/docs/examples/features/integrations/grafana/README.md b/charts/k8s-monitoring/docs/examples/features/integrations/grafana/README.md index f75827b01..79c99c510 100644 --- a/charts/k8s-monitoring/docs/examples/features/integrations/grafana/README.md +++ b/charts/k8s-monitoring/docs/examples/features/integrations/grafana/README.md @@ -23,6 +23,8 @@ integrations: grafana: instances: - name: grafana + labelSelectors: + app.kubernetes.io/name: grafana namespaces: - o11y diff --git a/charts/k8s-monitoring/docs/examples/features/integrations/grafana/alloy-logs.alloy b/charts/k8s-monitoring/docs/examples/features/integrations/grafana/alloy-logs.alloy index 402f3b121..46f4b0bba 100644 --- a/charts/k8s-monitoring/docs/examples/features/integrations/grafana/alloy-logs.alloy +++ b/charts/k8s-monitoring/docs/examples/features/integrations/grafana/alloy-logs.alloy @@ -77,16 +77,16 @@ declare "pod_logs" { regex = "__meta_kubernetes_pod_annotation_(.+)" } rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"] + source_labels = ["__meta_kubernetes_namespace","__meta_kubernetes_pod_label_app_kubernetes_io_name"] separator = ";" - regex = "grafana" + regex = "(o11y);grafana" target_label = "job" replacement = "integrations/grafana" } rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"] + source_labels = ["__meta_kubernetes_namespace","__meta_kubernetes_pod_label_app_kubernetes_io_name"] separator = ";" - regex = "grafana" + regex = "(o11y);grafana" target_label = "instance" replacement = "grafana" } diff --git a/charts/k8s-monitoring/docs/examples/features/integrations/grafana/alloy-metrics.alloy b/charts/k8s-monitoring/docs/examples/features/integrations/grafana/alloy-metrics.alloy index 9622474e1..c761ff6a1 100644 --- a/charts/k8s-monitoring/docs/examples/features/integrations/grafana/alloy-metrics.alloy +++ b/charts/k8s-monitoring/docs/examples/features/integrations/grafana/alloy-metrics.alloy @@ -194,6 +194,11 @@ declare "grafana_integration" { comment = "Must be a list(MetricsReceiver) where collected metrics should be forwarded to" } + argument "job_label" { + comment = "The job label to add for all Loki metrics (default: integrations/grafana)" + optional = true + } + argument "keep_metrics" { comment = "A regular expression of metrics to keep (default: see below)" optional = true @@ -220,7 +225,7 @@ declare "grafana_integration" { } prometheus.scrape "grafana" { - job_name = "integrations/grafana" + job_name = coalesce(argument.job_label.value, "integrations/grafana") forward_to = [prometheus.relabel.grafana.receiver] targets = argument.targets.value scrape_interval = coalesce(argument.scrape_interval.value, "60s") @@ -252,6 +257,7 @@ declare "grafana_integration" { grafana_integration_scrape "grafana" { targets = grafana_integration_discovery.grafana.output + job_label = clustering = true scrape_interval = "60s" max_cache_size = 100000 diff --git a/charts/k8s-monitoring/docs/examples/features/integrations/grafana/output.yaml b/charts/k8s-monitoring/docs/examples/features/integrations/grafana/output.yaml index 69eaee3f8..f690a5db1 100644 --- a/charts/k8s-monitoring/docs/examples/features/integrations/grafana/output.yaml +++ b/charts/k8s-monitoring/docs/examples/features/integrations/grafana/output.yaml @@ -235,6 +235,11 @@ data: comment = "Must be a list(MetricsReceiver) where collected metrics should be forwarded to" } + argument "job_label" { + comment = "The job label to add for all Loki metrics (default: integrations/grafana)" + optional = true + } + argument "keep_metrics" { comment = "A regular expression of metrics to keep (default: see below)" optional = true @@ -261,7 +266,7 @@ data: } prometheus.scrape "grafana" { - job_name = "integrations/grafana" + job_name = coalesce(argument.job_label.value, "integrations/grafana") forward_to = [prometheus.relabel.grafana.receiver] targets = argument.targets.value scrape_interval = coalesce(argument.scrape_interval.value, "60s") @@ -293,6 +298,7 @@ data: grafana_integration_scrape "grafana" { targets = grafana_integration_discovery.grafana.output + job_label = clustering = true scrape_interval = "60s" max_cache_size = 100000 @@ -447,16 +453,16 @@ data: regex = "__meta_kubernetes_pod_annotation_(.+)" } rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"] + source_labels = ["__meta_kubernetes_namespace","__meta_kubernetes_pod_label_app_kubernetes_io_name"] separator = ";" - regex = "grafana" + regex = "(o11y);grafana" target_label = "job" replacement = "integrations/grafana" } rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"] + source_labels = ["__meta_kubernetes_namespace","__meta_kubernetes_pod_label_app_kubernetes_io_name"] separator = ";" - regex = "grafana" + regex = "(o11y);grafana" target_label = "instance" replacement = "grafana" } diff --git a/charts/k8s-monitoring/docs/examples/features/integrations/grafana/values.yaml b/charts/k8s-monitoring/docs/examples/features/integrations/grafana/values.yaml index b53d0f137..7dd6e2ff1 100644 --- a/charts/k8s-monitoring/docs/examples/features/integrations/grafana/values.yaml +++ b/charts/k8s-monitoring/docs/examples/features/integrations/grafana/values.yaml @@ -14,6 +14,8 @@ integrations: grafana: instances: - name: grafana + labelSelectors: + app.kubernetes.io/name: grafana namespaces: - o11y diff --git a/charts/k8s-monitoring/docs/examples/meta-monitoring/alloy-singleton.alloy b/charts/k8s-monitoring/docs/examples/meta-monitoring/alloy-singleton.alloy index 159a86964..1099a463d 100644 --- a/charts/k8s-monitoring/docs/examples/meta-monitoring/alloy-singleton.alloy +++ b/charts/k8s-monitoring/docs/examples/meta-monitoring/alloy-singleton.alloy @@ -347,16 +347,16 @@ declare "pod_logs" { regex = "__meta_kubernetes_pod_annotation_(.+)" } rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"] + source_labels = ["__meta_kubernetes_namespace"] separator = ";" - regex = "grafana" + regex = "(o11y)" target_label = "job" replacement = "integrations/grafana" } rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"] + source_labels = ["__meta_kubernetes_namespace"] separator = ";" - regex = "grafana" + regex = "(o11y)" target_label = "instance" replacement = "grafana" } @@ -778,7 +778,7 @@ declare "alloy_integration" { } alloy_integration_discovery "alloy_in_logs" { - port_name = "http-metrics" + port_name = "grafana" namespaces = ["logs"] label_selectors = ["app.kubernetes.io/name=alloy-singleton"] } @@ -961,6 +961,11 @@ declare "grafana_integration" { comment = "Must be a list(MetricsReceiver) where collected metrics should be forwarded to" } + argument "job_label" { + comment = "The job label to add for all Loki metrics (default: integrations/grafana)" + optional = true + } + argument "keep_metrics" { comment = "A regular expression of metrics to keep (default: see below)" optional = true @@ -987,7 +992,7 @@ declare "grafana_integration" { } prometheus.scrape "grafana" { - job_name = "integrations/grafana" + job_name = coalesce(argument.job_label.value, "integrations/grafana") forward_to = [prometheus.relabel.grafana.receiver] targets = argument.targets.value scrape_interval = coalesce(argument.scrape_interval.value, "60s") @@ -1013,12 +1018,13 @@ declare "grafana_integration" { grafana_integration_discovery "grafana" { namespaces = ["o11y"] - label_selectors = ["app.kubernetes.io/name=grafana"] + label_selectors = [] port_name = "grafana" } grafana_integration_scrape "grafana" { targets = grafana_integration_discovery.grafana.output + job_label = clustering = true scrape_interval = "60s" max_cache_size = 100000 diff --git a/charts/k8s-monitoring/docs/examples/meta-monitoring/output.yaml b/charts/k8s-monitoring/docs/examples/meta-monitoring/output.yaml index 8bb14d019..11628d6fc 100644 --- a/charts/k8s-monitoring/docs/examples/meta-monitoring/output.yaml +++ b/charts/k8s-monitoring/docs/examples/meta-monitoring/output.yaml @@ -389,16 +389,16 @@ data: regex = "__meta_kubernetes_pod_annotation_(.+)" } rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"] + source_labels = ["__meta_kubernetes_namespace"] separator = ";" - regex = "grafana" + regex = "(o11y)" target_label = "job" replacement = "integrations/grafana" } rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"] + source_labels = ["__meta_kubernetes_namespace"] separator = ";" - regex = "grafana" + regex = "(o11y)" target_label = "instance" replacement = "grafana" } @@ -820,7 +820,7 @@ data: } alloy_integration_discovery "alloy_in_logs" { - port_name = "http-metrics" + port_name = "grafana" namespaces = ["logs"] label_selectors = ["app.kubernetes.io/name=alloy-singleton"] } @@ -1003,6 +1003,11 @@ data: comment = "Must be a list(MetricsReceiver) where collected metrics should be forwarded to" } + argument "job_label" { + comment = "The job label to add for all Loki metrics (default: integrations/grafana)" + optional = true + } + argument "keep_metrics" { comment = "A regular expression of metrics to keep (default: see below)" optional = true @@ -1029,7 +1034,7 @@ data: } prometheus.scrape "grafana" { - job_name = "integrations/grafana" + job_name = coalesce(argument.job_label.value, "integrations/grafana") forward_to = [prometheus.relabel.grafana.receiver] targets = argument.targets.value scrape_interval = coalesce(argument.scrape_interval.value, "60s") @@ -1055,12 +1060,13 @@ data: grafana_integration_discovery "grafana" { namespaces = ["o11y"] - label_selectors = ["app.kubernetes.io/name=grafana"] + label_selectors = [] port_name = "grafana" } grafana_integration_scrape "grafana" { targets = grafana_integration_discovery.grafana.output + job_label = clustering = true scrape_interval = "60s" max_cache_size = 100000 diff --git a/charts/k8s-monitoring/tests/integration/integration-grafana/.rendered/output.yaml b/charts/k8s-monitoring/tests/integration/integration-grafana/.rendered/output.yaml index ef8fe3a2f..f318c52e3 100644 --- a/charts/k8s-monitoring/tests/integration/integration-grafana/.rendered/output.yaml +++ b/charts/k8s-monitoring/tests/integration/integration-grafana/.rendered/output.yaml @@ -575,6 +575,11 @@ data: comment = "Must be a list(MetricsReceiver) where collected metrics should be forwarded to" } + argument "job_label" { + comment = "The job label to add for all Loki metrics (default: integrations/grafana)" + optional = true + } + argument "keep_metrics" { comment = "A regular expression of metrics to keep (default: see below)" optional = true @@ -601,7 +606,7 @@ data: } prometheus.scrape "grafana" { - job_name = "integrations/grafana" + job_name = coalesce(argument.job_label.value, "integrations/grafana") forward_to = [prometheus.relabel.grafana.receiver] targets = argument.targets.value scrape_interval = coalesce(argument.scrape_interval.value, "60s") @@ -633,6 +638,7 @@ data: grafana_integration_scrape "grafana" { targets = grafana_integration_discovery.grafana.output + job_label = clustering = true scrape_interval = "60s" max_cache_size = 100000 diff --git a/charts/k8s-monitoring/tests/integration/integration-grafana/values.yaml b/charts/k8s-monitoring/tests/integration/integration-grafana/values.yaml index c72289a3b..7f30aef75 100644 --- a/charts/k8s-monitoring/tests/integration/integration-grafana/values.yaml +++ b/charts/k8s-monitoring/tests/integration/integration-grafana/values.yaml @@ -26,6 +26,8 @@ integrations: grafana: instances: - name: grafana + labelSelectors: + app.kubernetes.io/name: grafana logs: enabled: true