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

Include skip_methods option to avoid collecting metrics for specific methods #66

Conversation

adinsoon
Copy link

@adinsoon adinsoon commented Apr 27, 2023

What does this Pull Request do?

Adds an option to avoid collecting metrics on request with specific methods.
This option can be used to avoid collecting metrics on, for example, communication description requests for endpoints (but can be used in any other method).
The new option is an optional list called skip_methods.

Example:

app.add_middleware(
  PrometheusMiddleware,
  app_name="hello_world",
  prefix='myapp',
  labels={
      "server_name": os.getenv("HOSTNAME"),
  }),
  group_paths=True,
  buckets=[0.1, 0.25, 0.5],
  skip_paths=['/health'],
  skip_methods=['OPTIONS'],
  always_use_int_status=False),
  exemplars=lambda: {"trace_id": get_trace_id}  # function that returns a trace id

On the justification

We have an application using microservices architecture, at the beginning of which there is a gateway that forwards requests with a given path or method. From this point, we monitor the metrics. Prometheus is not able to process such a large generated traffic, which we already reduce by ignoring some paths, so we also want to reduce it by ignoring requests containing some methods (namely OPTIONS), because they are not important to us. This change may allow us to get a performance benefit. I will be very pleased with the opportunity to contribute to your project.

@stephenhillier

@stephenhillier
Copy link
Owner

@adinsoon thanks! This looks totally reasonable. I am away for the next couple days and will look at merging this and cutting a new release soon. Thank you for your patience.

@@ -2,7 +2,7 @@

setup(
name="starlette_exporter",
version="0.15.1",
version="0.15.2",
Copy link
Owner

Choose a reason for hiding this comment

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

Going to bump the minor version to 0.16.0 to indicate there's a new feature here. I'll take care of it when I create the release though, just letting you know.

@stephenhillier
Copy link
Owner

Looks great, thank you for the contribution! Thanks for updating the docs and adding a test too. Cheers

@stephenhillier stephenhillier merged commit 3724ee3 into stephenhillier:master May 5, 2023
@adinsoon
Copy link
Author

adinsoon commented May 7, 2023

@stephenhillier Great that it came in handy, thank you for merging, take care

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.

2 participants