|
| 1 | +--- |
| 2 | +title: "0005: Loki mixin configuration improvements" |
| 3 | +description: "Improve Loki mixin configurations" |
| 4 | +draft: false |
| 5 | +--- |
| 6 | + |
| 7 | +# 0005: Loki mixin configuration improvements |
| 8 | + |
| 9 | +**Author: ** Alexandre Chouinard ( [email protected]) |
| 10 | + |
| 11 | +**Date:** 03/2025 |
| 12 | + |
| 13 | +**Sponsor(s):** N/A |
| 14 | + |
| 15 | +**Type:** Feature |
| 16 | + |
| 17 | +**Status:** Draft |
| 18 | + |
| 19 | +**Related issues/PRs:** |
| 20 | +- https://github.com/grafana/loki/issues/13631 |
| 21 | +- https://github.com/grafana/loki/issues/15881 |
| 22 | +- https://github.com/grafana/loki/issues/11820 |
| 23 | +- https://github.com/grafana/loki/issues/11806 |
| 24 | +- https://github.com/grafana/loki/issues/7730 |
| 25 | +- and more ... |
| 26 | + |
| 27 | +**Thread from [mailing list](https://groups.google.com/forum/#!forum/lokiproject):** N/A |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Background |
| 32 | + |
| 33 | +There is no easy way to set up dashboards and alerts for Loki on a pre-existing Prometheus stack that does not use the Prometheus Operator with a specific configuration. |
| 34 | + |
| 35 | +The metrics selectors are hardcoded, making the dashboard unusable without manual modifications in many cases. |
| 36 | +It is assumed that `job`, `cluster`, `namespace`, `container` and/or a combination of other labels are present on metrics and have very specific values. |
| 37 | + |
| 38 | +## Problem Statement |
| 39 | + |
| 40 | +This renders the dashboards and alerts unusable for setups that do not conform to the current assumptions about which label(s) should be present in the metrics. |
| 41 | + |
| 42 | +A good example of that would be the "job" label used everywhere: |
| 43 | +[`job=~\"$namespace/bloom-planner\"`](https://github.com/grafana/loki/blob/475d25f459575312adb25ff90abf8f10d521ad4b/production/loki-mixin/dashboards/dashboard-bloom-build.json#L267C101-L267C134) |
| 44 | + |
| 45 | +Usually the job label refer to the task name used to scrape the targets, as per [Prometheus documentation](https://prometheus.io/docs/concepts/jobs_instances/), and |
| 46 | +in k8s, if you are not using `prometheus-operator` with `ServiceMonitor`, it's pretty common to have something like this as a scraping config: |
| 47 | +``` |
| 48 | + - job_name: "kubernetes-pods" # Can actually be anything you want. |
| 49 | + kubernetes_sd_configs: |
| 50 | + - role: pod |
| 51 | + relabel_configs: |
| 52 | + # Cluster label is "required" by kubernetes-mixin dashboards |
| 53 | + - target_label: cluster |
| 54 | + replacement: '${cluster_label}' |
| 55 | + ... |
| 56 | +``` |
| 57 | +which would scrape all pods and yield something like: |
| 58 | +``` |
| 59 | +up{job="kubernetes-pods", ...} |
| 60 | +``` |
| 61 | +Right off the bat, that makes the dashboards unusable because it's incompatible with what is **hardcoded** in the dashboards and alerts. |
| 62 | + |
| 63 | +## Goals |
| 64 | + |
| 65 | +Ideally, selectors should default to the values required internally by Grafana but remain configurable so users can tailor them to their setup. |
| 66 | + |
| 67 | +A good example of this is how [kubernetes-monitoring/kubernetes-mixin](kubernetes-monitoring) did it: |
| 68 | +https://github.com/kubernetes-monitoring/kubernetes-mixin/blob/1fa3b6731c93eac6d5b8c3c3b087afab2baabb42/config.libsonnet#L20-L33 |
| 69 | +Every possible selector is configurable and thus allow for various setup to properly work. |
| 70 | + |
| 71 | +The structure is already there to support this. It just has not been leveraged properly. |
| 72 | + |
| 73 | +## Non-Goals (optional) |
| 74 | + |
| 75 | +It would be desirable to create some automated checks verifying that all metrics used in dashboard and alerts are using the proper selector(s) from the configuration. |
| 76 | +There are many issues in the repository about new dashboards or dashboard updates not using the proper labels on metrics. |
| 77 | + |
| 78 | +## Proposals |
| 79 | + |
| 80 | +### Proposal 0: Do nothing |
| 81 | + |
| 82 | +This forces the community to either manually edit the dashboards/alerts or conform to a specific metric collection approach for Loki. |
| 83 | + |
| 84 | +### Proposal 1: Allow metrics label selectors to be configurable |
| 85 | + |
| 86 | +This will require a good amount of refactoring. |
| 87 | + |
| 88 | +It allows easier adoption of the "official" dashboards and alerts by the community. |
| 89 | + |
| 90 | +Define once, reuse everywhere. (Currently, updating requires extensive search and replace.) |
| 91 | + |
| 92 | +## Other Notes |
| 93 | + |
| 94 | +If this proposal is accepted, I am willing to do the necessary work to move it forward. |
0 commit comments