containers / nri-plugins

A collection of community maintained NRI plugins
https://containers.github.io/nri-plugins/
Apache License 2.0
68 stars 25 forks source link

helm: enable prometheus autodiscovery #393

Closed klihub closed 1 month ago

klihub commented 1 month ago

helm: allow autodiscovery by prometheus.

Allow autodiscovery of prometheus metrics by annotation. IOW, annotate our plugins' pods according to the Helm config.instrumentation.{prometheusExport,httpEndpoint} values. Since this PR adds annotations to our plugins' pods, add support for additional injection of other custom annotations using the Helm plugin.annotations value.

Also, since it's now uneccessary to expose our custom metrics port on the host side, remove the required and dedicated hostPort Helm value. Add instead an optional generic ports array to allow exposing arbitrary ports to the host. Remove hostPort from the nriplugindeployments CRD as well.

fmuyassarov commented 1 month ago

I'm not sure if I'm missing some context, but could you clarify why we need to introduce these annotations when we already have Helm flags that control the instrumentation of the balloons policy CR? The only reason I can think of for having two methods to enable scraping on the pod would be to allow overriding the default port and scraping settings. Is that the case, or is there something else at play here?

Also, the nri.plugin.annotations setting initially gave an impression that users could pass any annotation they wanted, suggesting it wasn't exclusively linked to Prometheus. However, in the daemonSet spec, it seems that whatever is passed through 'nri.plugin.annotations' ultimately maps to prometheus.io/port, which is a bit odd.

klihub commented 1 month ago

I'm not sure if I'm missing some context, but could you clarify why we need to introduce these annotations when we already have Helm flags that control the instrumentation of the balloons policy CR? The only reason I can think of for having two methods to enable scraping on the pod would be to allow overriding the default port and scraping settings. Is that the case, or is there something else at play here?

There is no existing helm flag to control instrumentation, only a CR configuration setting. There is a Helm value to expose the metrics port to a host port which should not be necessary at all and is removed by this PR, or actually converted to generic port expose mechanism.

All in all, the purpose of this PR is to

klihub commented 1 month ago

Also, the nri.plugin.annotations setting initially gave an impression that users could pass any annotation they wanted, suggesting it wasn't exclusively linked to Prometheus. However, in the daemonSet spec, it seems that whatever is passed through 1nri.plugin.annotations1 ultimately maps to prometheus.io/port, which is a bit odd.

If that is the case then I screwed up the latest rebase. The ide is exactly to provide a way to inject arbitrary annotations. But in addition to any custom annotations by Helm config we always annotate for prometheus auto-discovery.

fmuyassarov commented 1 month ago

prometheus auto-discovery

btw, what is prometheus auto-discovery, do you have some reference documentation ?

fmuyassarov commented 1 month ago

prometheus auto-discovery

btw, what is prometheus auto-discovery, do you have some reference documentation ?

I guess you mean that you want the pod to advertise itself as it it can be scraped by prometheus right? like sending ARP

klihub commented 1 month ago

prometheus auto-discovery

btw, what is prometheus auto-discovery, do you have some reference documentation ?

I guess you mean that you want the pod to advertise itself as it it can be scraped by prometheus right? like sending ARP

Yes.

klihub commented 1 month ago

prometheus auto-discovery

btw, what is prometheus auto-discovery, do you have some reference documentation ?

I just googled for autodiscovery then found a few articles describing it. For instance,

fmuyassarov commented 1 month ago

There is no existing helm flag to control instrumentation, only a CR configuration setting.

There is: https://github.com/containers/nri-plugins/blob/a0d1476769b0fa4d7dae5f6871f46cf4ef26f3bb/deployment/helm/balloons/values.yaml#L43

fmuyassarov commented 1 month ago

Don't we need prometheus.io/path: '/metrics' annotation alongside other too?

fmuyassarov commented 1 month ago

Also, I would merge https://github.com/containers/nri-plugins/pull/393/commits/b437b94d90bdd57c610a3a6ed2df067d57349d51 and https://github.com/containers/nri-plugins/pull/393/commits/cdce5b6959c5d380a8f3b086594ab0b07616093f into a single commit.

klihub commented 1 month ago

Don't we need prometheus.io/path: '/metrics' annotation alongside other too?

That would only be necessary if we exposed our metrics on a non-standard path, something else than the default /metrics.

klihub commented 1 month ago

There is no existing helm flag to control instrumentation, only a CR configuration setting.

There is:

https://github.com/containers/nri-plugins/blob/a0d1476769b0fa4d7dae5f6871f46cf4ef26f3bb/deployment/helm/balloons/values.yaml#L43

That is not a genuine Helm-level setting. It is part of the Helm-level opaque config YAML blob we inject into the default policy CRD. If you look at values.schema.json, it (intentionally) says nothing about config.instrumentation.prometheusExport or even config.instrumentation.

klihub commented 1 month ago

I've got only one question on this.

Could we enable installation so that only the port name is defined but the host is not? That is, we would not ever specify hostPort unless user very very much wants it there.

Updated, making ports.host/hostPort optional.