diff --git a/charts/k8s-monitoring/README.md b/charts/k8s-monitoring/README.md index e653907d88..e25cb10501 100644 --- a/charts/k8s-monitoring/README.md +++ b/charts/k8s-monitoring/README.md @@ -493,6 +493,7 @@ The Prometheus and Loki services may be hosted on the same cluster, or remotely | metrics.autoDiscover.annotations.metricsScheme | string | `"k8s.grafana.com/metrics.scheme"` | Annotation for setting the metrics scheme, default: http. | | metrics.autoDiscover.annotations.metricsScrapeInterval | string | `"k8s.grafana.com/metrics.scrapeInterval"` | Annotation for overriding the scrape interval for this service or pod. Value should be a duration like "15s, 1m". Overrides metrics.autoDiscover.scrapeInterval | | metrics.autoDiscover.annotations.scrape | string | `"k8s.grafana.com/scrape"` | Annotation for enabling scraping for this service or pod. Value should be either "true" or "false" | +| metrics.autoDiscover.bearerToken | object | `{"enabled":true}` | Sets bearer_token_file line in the prometheus.scrape annotation_autodiscovery. | | metrics.autoDiscover.enabled | bool | `true` | Enable annotation-based auto-discovery | | metrics.autoDiscover.extraMetricRelabelingRules | string | `""` | Rule blocks to be added to the prometheus.relabel component for auto-discovered entities. These relabeling rules are applied post-scrape against the metrics returned from the scraped target, no `__meta*` labels are present. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus.relabel/#rule-block)) | | metrics.autoDiscover.extraRelabelingRules | string | `""` | Rule blocks to be added to the discovery.relabel component for auto-discovered entities. These relabeling rules are applied pre-scrape against the targets from service discovery. Before the scrape, any remaining target labels that start with `__` (i.e. `__meta_kubernetes*`) are dropped. ([docs](https://grafana.com/docs/alloy/latest/reference/components/discovery.relabel/#rule-block)) | diff --git a/charts/k8s-monitoring/templates/alloy_config/_annotation_autodiscovery.alloy.txt b/charts/k8s-monitoring/templates/alloy_config/_annotation_autodiscovery.alloy.txt index 8a9dbd2585..318981098e 100644 --- a/charts/k8s-monitoring/templates/alloy_config/_annotation_autodiscovery.alloy.txt +++ b/charts/k8s-monitoring/templates/alloy_config/_annotation_autodiscovery.alloy.txt @@ -170,7 +170,9 @@ prometheus.scrape "annotation_autodiscovery_http" { targets = discovery.relabel.annotation_autodiscovery_http.output scrape_interval = {{ .Values.metrics.autoDiscover.scrapeInterval | default .Values.metrics.scrapeInterval | quote }} honor_labels = true +{{- if .Values.metrics.autoDiscover.bearerToken.enabled }} bearer_token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token" +{{- end }} {{- if .Values.alloy.alloy.clustering.enabled }} clustering { enabled = true @@ -183,7 +185,9 @@ prometheus.scrape "annotation_autodiscovery_https" { targets = discovery.relabel.annotation_autodiscovery_https.output scrape_interval = {{ .Values.metrics.autoDiscover.scrapeInterval | default .Values.metrics.scrapeInterval | quote }} honor_labels = true +{{- if .Values.metrics.autoDiscover.bearerToken.enabled }} bearer_token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token" +{{- end }} tls_config { insecure_skip_verify = true } diff --git a/charts/k8s-monitoring/values.schema.json b/charts/k8s-monitoring/values.schema.json index c3dbf8fa72..7a53167647 100644 --- a/charts/k8s-monitoring/values.schema.json +++ b/charts/k8s-monitoring/values.schema.json @@ -1263,6 +1263,14 @@ "null" ] }, + "bearerToken": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + } + } + }, "metricsTuning": { "type": "object", "properties": { diff --git a/charts/k8s-monitoring/values.yaml b/charts/k8s-monitoring/values.yaml index e603f2f173..88dc952fe4 100644 --- a/charts/k8s-monitoring/values.yaml +++ b/charts/k8s-monitoring/values.yaml @@ -583,6 +583,11 @@ metrics: # @section -- Metrics Job: Auto-Discovery maxCacheSize: + # -- Sets bearer_token_file line in the prometheus.scrape annotation_autodiscovery. + # @section -- Metrics Job: Auto-Discovery + bearerToken: + enabled: true + # Metrics from Grafana Alloy # @section -- Metrics -> Alloy Job alloy: