Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helm: enable prometheus autodiscovery #393

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

klihub
Copy link
Collaborator

@klihub klihub commented Nov 2, 2024

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.

@klihub klihub force-pushed the fixes/prometheus-autodiscovery branch 4 times, most recently from de1f636 to cdce5b6 Compare November 3, 2024 13:19
@fmuyassarov
Copy link
Collaborator

fmuyassarov commented Nov 4, 2024

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
Copy link
Collaborator Author

klihub commented Nov 4, 2024

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

  • allow prometheus to automatically discover and start scraping our metrics
  • remove the metric port exposure to the host as it now should be unnecessary

@klihub
Copy link
Collaborator Author

klihub commented Nov 4, 2024

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
Copy link
Collaborator

prometheus auto-discovery

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

@fmuyassarov
Copy link
Collaborator

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
Copy link
Collaborator Author

klihub commented Nov 4, 2024

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.

deployment/helm/balloons/templates/daemonset.yaml Outdated Show resolved Hide resolved
deployment/helm/balloons/values.schema.json Outdated Show resolved Hide resolved
deployment/helm/balloons/values.schema.json Show resolved Hide resolved
deployment/helm/balloons/values.yaml Outdated Show resolved Hide resolved
@fmuyassarov
Copy link
Collaborator

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

There is:

@fmuyassarov
Copy link
Collaborator

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

@fmuyassarov
Copy link
Collaborator

Also, I would merge b437b94 and cdce5b6 into a single commit.

@klihub
Copy link
Collaborator Author

klihub commented Nov 4, 2024

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 klihub force-pushed the fixes/prometheus-autodiscovery branch 2 times, most recently from 5ba8185 to 5092c00 Compare November 4, 2024 12:58
@klihub
Copy link
Collaborator Author

klihub commented Nov 4, 2024

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

There is:

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 klihub requested a review from fmuyassarov November 4, 2024 13:12
@klihub klihub force-pushed the fixes/prometheus-autodiscovery branch 4 times, most recently from 8df426f to 650cee4 Compare November 4, 2024 15:38
@klihub klihub requested a review from fmuyassarov November 4, 2024 15:40
Copy link
Collaborator

@fmuyassarov fmuyassarov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@askervin askervin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Allow autodiscovery of prometheus metrics by annotation.
IOW, annotate our plugins' pods according to the Helm
`config.instrumentation.{prometheusExport,httpEndpoint}`
values.

Since we're adding annotations to our plugins' pods, add
support for injecting custom annotations using the Helm
`plugin.annotations` value.

Signed-off-by: Krisztian Litkey <[email protected]>
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. Similarly remove
hostPort from the nriplugindeployments CRD.

Signed-off-by: Krisztian Litkey <[email protected]>
@klihub klihub force-pushed the fixes/prometheus-autodiscovery branch from 650cee4 to b346bc3 Compare November 8, 2024 09:29
@klihub klihub requested a review from askervin November 8, 2024 09:29
@klihub
Copy link
Collaborator Author

klihub commented Nov 8, 2024

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.

Copy link
Collaborator

@askervin askervin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@askervin askervin merged commit d267a4a into containers:main Nov 8, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants