Skip to content

Commit

Permalink
Adding a conditional to enable or disable bearer token in auto discov…
Browse files Browse the repository at this point in the history
…ery (#686)

* Adding a conditional to enable or disable bearer token in auto discovery

* Adding a conditional to enable or disable bearer token in auto discovery

* update values to use enabled Key

* updating helm docs
  • Loading branch information
reginaldomoura-jr authored Aug 16, 2024
1 parent 65bef9a commit eacedb9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions charts/k8s-monitoring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,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)) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions charts/k8s-monitoring/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,14 @@
"null"
]
},
"bearerToken": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
},
"metricsTuning": {
"type": "object",
"properties": {
Expand Down
5 changes: 5 additions & 0 deletions charts/k8s-monitoring/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit eacedb9

Please sign in to comment.