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

Refactor metrics to use alternate metrics crate #301

Merged
merged 4 commits into from
May 1, 2024

Conversation

adam-cattermole
Copy link
Member

@adam-cattermole adam-cattermole commented Apr 26, 2024

Changes

I've removed the original prometheus crate and added metrics, and prometheus metrics exporter. These support using the metrics API, and the exporter allows us to get a handle to be able to still use actix to export the metrics at /metrics.

  • Metrics are configured with the help message via the describe_* methods on init
  • They are no longer stored in the struct and used from the macro directly (due to the macro supporting labels but no method on the metrics types)
  • The prometheus_metrics struct is still passed to envoy_rls/server and to the http_api/server to retain the config limit_name_in_labels for writing the metrics - not 100% sold on this solution though
  • The prom metrics struct now retains a handle to the global prometheus recorder, as this can only be set once for the lifetime of the application. The tests share a single lazy static handle
  • I've provided an example for adding a datastore_partitioned metric to the limitador library

Verification

Checkout this branch and build server:

cargo build --bin limitador-server

Run the server:

./target/debug/limitador-server -vvv --grpc-reflection-service --limit-name-in-labels limitador-server/sandbox/limits.yaml redis_cached redis://127.0.0.1

Check metrics endpoint:

curl localhost:8080/metrics
# HELP limitador_up Limitador is running
# TYPE limitador_up gauge
limitador_up 1

TODO

  • Fix tests, unable to configure the prometheus exporter

@adam-cattermole adam-cattermole marked this pull request as ready for review May 1, 2024 10:34
Copy link
Member

@alexsnaps alexsnaps left a comment

Choose a reason for hiding this comment

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

🥳

limitador-server/src/main.rs Show resolved Hide resolved
@adam-cattermole adam-cattermole merged commit 754a319 into main May 1, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants