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

add metrics endpoint to monitor API requests #831

Closed
pitwegner opened this issue Jun 20, 2023 · 6 comments
Closed

add metrics endpoint to monitor API requests #831

pitwegner opened this issue Jun 20, 2023 · 6 comments

Comments

@pitwegner
Copy link

/kind feature

Describe the solution you'd like
I would like a metrics endpoint for data like hcloud_api_requests_total, so that the API requests to Hetzner can be monitored.

Anything else you would like to add:
Similar endpoints are implemented for hcloud-cloud-controller-manager and csi-driver.

@pitwegner pitwegner changed the title add metrics endpoint add metrics endpoint to monitor API requests Jun 20, 2023
@janiskemper
Copy link
Contributor

Sounds like a good feature. Would you be able to do a PR? We can support you there but lack currently the resources to focus on this.

@pitwegner
Copy link
Author

My time is also currently limited. I'll try and see what I can do.

@apricote
Copy link
Contributor

For the hcloud-go client you need to call WithInstrumentation(registry *prometheus.Registry). I am not sure if this properly handles multiple clients writing to the same registry, never tested this. AFAIK CAPH creates a new client per reconciliation loop.

@apricote
Copy link
Contributor

We just discovered that its not possible right now to have multiple instrumented clients on the same registry: hetznercloud/hcloud-go#288

Working on a fix though.

@apricote
Copy link
Contributor

Hey all :)

the metrics endpoint already exists in beta.22, it just binds to localhost and is not enumerated in the Pod, but if you port-forward you can access the metrics from controller-runtime:

$ kubectl port-forward -n caph-system deployments/caph-controller-manager 8080:8080
$ curl localhost:8080/metrics | tail
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 70717    0 70717    0     0   750k      0 --:--:-- --:--:-- --:--:--  758k
workqueue_work_duration_seconds_bucket{name="hetznercluster",le="9.999999999999999e-06"} 0
workqueue_work_duration_seconds_bucket{name="hetznercluster",le="9.999999999999999e-05"} 0
workqueue_work_duration_seconds_bucket{name="hetznercluster",le="0.001"} 3
workqueue_work_duration_seconds_bucket{name="hetznercluster",le="0.01"} 21
workqueue_work_duration_seconds_bucket{name="hetznercluster",le="0.1"} 21
workqueue_work_duration_seconds_bucket{name="hetznercluster",le="1"} 78
workqueue_work_duration_seconds_bucket{name="hetznercluster",le="10"} 111
workqueue_work_duration_seconds_bucket{name="hetznercluster",le="+Inf"} 111
workqueue_work_duration_seconds_sum{name="hetznercluster"} 97.379931617
workqueue_work_duration_seconds_count{name="hetznercluster"} 111

Adding the metrics for hcloud-go was also pretty easy. Only issue is that controller-runtime hides their default registry (which is exported at localhost:8080) behind a custom interface. This requires a type assertation back to *prometheus.Registry so we can pass it to WithInstrumentation().

I will create a PR for the hcloud-go changes.

Not sure if we want a "world-readable" metrics endpoint by default, there is an open CAPI discussion (kubernetes-sigs/cluster-api#7957) as well as a new controller-runtime feature (kubernetes-sigs/controller-runtime#2407) related to this.

@batistein
Copy link
Contributor

closing because this is already merged

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

No branches or pull requests

4 participants