feat: add optional prometheus metrics endpoint.#186
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #186 +/- ##
==========================================
- Coverage 89.39% 89.34% -0.06%
==========================================
Files 29 30 +1
Lines 1273 1304 +31
Branches 170 174 +4
==========================================
+ Hits 1138 1165 +27
- Misses 92 96 +4
Partials 43 43
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Left some thoughts.
As stated in developmentseed/eoapi-k8s#541 (comment), I'm generally in favor of this idea.
Before we merge this, we will want to ensure that the PR includes an update to our documentation. At the very least, we should update the config docs. We may also want to include something long-form within /tips.
One thing that stands out to me is how I don't really understand how this works in various deployment scenarios. Based on the fact that we're not configuring any datastore with this plugin, I assume these metrics are held within memory. So how would that work in a multi-node environment? Or what about a serverless environment where an AWS Lambda may or may not be warmed?
|
|
||
| if settings.enable_metrics: | ||
| add_metrics(app) | ||
| public_endpoints = {**public_endpoints, r"^/metrics$": ["GET"]} |
There was a problem hiding this comment.
Currently, we just auto-include optional endpoints in the default public setting:
stac-auth-proxy/src/stac_auth_proxy/config.py
Lines 101 to 110 in c89f650
Any reason to not do this?
There was a problem hiding this comment.
I added it this way to handle the dependency as conditional. But If we move it to a normal dependency it would be much simpler. I like this more. Now it would be enabled by default, is this ok?
| "is not installed. Install stac-auth-proxy[metrics]." | ||
| ) from exc | ||
|
|
||
| Instrumentator().instrument(app).expose(app) |
There was a problem hiding this comment.
It's interesting that /metrics path is never specified. Is this a hard requirement? I assume it's a common convention for prometheus? It would be nice to tuck it behind /_mgmt so it can sit alongside the other meta-endpoints, but if that's super atypical then it's not a big deal to leave it as it currently is written.
There was a problem hiding this comment.
It is the normal convention, but no problem moving it under /_mgmt as there should always be a configuration option when scraping the metrics.
6358351 to
78e2486
Compare
78e2486 to
83d234a
Compare
|
Can you have a look again, please? If you agree with this approach (enabled by default, dependency added in main bulk) I am happy to add the documentation. |
b3ec14c to
511be54
Compare
alukach
left a comment
There was a problem hiding this comment.
@pantierra sorry for the back-and-forth.
- serving metrics from
/_mgmt/metrics: 👍 - having
/_mgmt/metricsin defaultpublic_endpoints: 👍
However, I do still think this should be an optional dependency
|
I wasn't sure how you want to do the conditional. Inspired from stac-fastapi-elasticsearch-opensearch I made it to add the metrics endpoint if the dependency extra I gave it a try. Feel free to add over this branch if you prefer to change it. Or just let me know, I am fine to change it to you think is best. |
Yes, metrics are held in memory. In a multi-node setup, Prometheus scrapes each pod separately with possible aggregation when querying them. Serverless is trickier as the metrics need to be pushed. Afaik there are several approaches, but i don't have experience with any. |
|
Based on input developmentseed/eoAPI#193 (comment), adjusted the structure of the metrics to be more STACish. |
12d86c2 to
dca2c8b
Compare
Adds opt-in Prometheus metrics support via
prometheus-fastapi-instrumentator, controlled byENABLE_METRICS/enable_metrics. Metrics remain disabled by default and the dependency is available through themetricsextra.