canonical / grafana-agent-k8s-operator

https://charmhub.io/grafana-agent-k8s
Apache License 2.0
8 stars 18 forks source link

Alert rules expressions include a `juju_charm`, but metrics do not #227

Closed neoaggelos closed 1 year ago

neoaggelos commented 1 year ago

Bug Description

So, we are defining alert rules and passing them through the grafana-agent relation. Juju does its magic for us and automatically includes topology labels for the model, the application, the unit and the charm name.

However, that last bit is problematic. An example rule:

Indeed, running the query expression manually on prometheus returns an empty result, but works if I manually remove the juju_charm="microk8s" label. A hacky solution I tried, which worked, was this https://github.com/neoaggelos/grafana-agent-k8s-operator/commit/7364e4080cec3db17c16e10433d6b0f1e82d5d85

However, I am not in favor of changing PrometheusRemoteWriteProvider like this, because it might break other valid scenarios.

My understanding is that the problem arises because the grafana-agent unit has no idea about the charm name of its primary unit.

So, two possible solutions:

like above, do not include the juju_charm label on alerts (somehow) pass the charm_name name via relation data from the principal unit to the grafana-agent unit, and use it to annotate the alert rules (if available). I am more inclined towards option 2, even though it would need some minor refactoring on the provider and the requirer side. I also imagine that if that relation data is missing, then we can keep the current behaviour (so perhaps we can skip bumping the library API)

To Reproduce

See description above.

Environment

juju deploy grafana-agent --channel edge

Relevant log output

none

Additional context

No response

neoaggelos commented 1 year ago

As @dstathis , duplicate of https://github.com/canonical/grafana-agent-k8s-operator/issues/190