Skip to content

feat: add optional prometheus metrics endpoint.#186

Merged
pantierra merged 10 commits into
mainfrom
feat/prometheus-metrics-endpoint
Jul 22, 2026
Merged

feat: add optional prometheus metrics endpoint.#186
pantierra merged 10 commits into
mainfrom
feat/prometheus-metrics-endpoint

Conversation

@pantierra

Copy link
Copy Markdown
Contributor

Adds opt-in Prometheus metrics support via prometheus-fastapi-instrumentator, controlled by ENABLE_METRICS / enable_metrics. Metrics remain disabled by default and the dependency is available through the metrics extra.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.21053% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.42%. Comparing base (fec33b6) to head (0f1c068).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/stac_auth_proxy/metrics.py 83.33% 4 Missing and 1 partial ⚠️
src/stac_auth_proxy/app.py 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #186      +/-   ##
==========================================
- Coverage   89.49%   89.42%   -0.08%     
==========================================
  Files          29       30       +1     
  Lines        1276     1314      +38     
  Branches      171      176       +5     
==========================================
+ Hits         1142     1175      +33     
- Misses         92       96       +4     
- Partials       42       43       +1     
Flag Coverage Δ
unittests 89.42% <84.21%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alukach alukach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Comment thread src/stac_auth_proxy/app.py Outdated
Comment thread src/stac_auth_proxy/app.py Outdated
@pantierra
pantierra force-pushed the feat/prometheus-metrics-endpoint branch from 6358351 to 78e2486 Compare July 9, 2026 18:16
@pantierra
pantierra force-pushed the feat/prometheus-metrics-endpoint branch from 78e2486 to 83d234a Compare July 9, 2026 18:18
@pantierra
pantierra requested a review from alukach July 9, 2026 18:18
@pantierra

Copy link
Copy Markdown
Contributor Author

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.

@pantierra
pantierra force-pushed the feat/prometheus-metrics-endpoint branch from b3ec14c to 511be54 Compare July 9, 2026 19:28

@alukach alukach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@pantierra sorry for the back-and-forth.

  • serving metrics from /_mgmt/metrics: 👍
  • having /_mgmt/metrics in default public_endpoints: 👍

However, I do still think this should be an optional dependency

@pantierra

Copy link
Copy Markdown
Contributor Author

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 metrics is installed. And we somehow have to deal with adding/removing it from the public_endpoints depending on the conditional.

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.

@pantierra

Copy link
Copy Markdown
Contributor Author

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?

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.

@pantierra

Copy link
Copy Markdown
Contributor Author

Based on input developmentseed/eoAPI#193 (comment), adjusted the structure of the metrics to be more STACish.

@pantierra
pantierra force-pushed the feat/prometheus-metrics-endpoint branch from 12d86c2 to dca2c8b Compare July 13, 2026 23:43
@pantierra
pantierra requested a review from alukach July 21, 2026 22:05
@claude

claude Bot commented Jul 21, 2026

Copy link
Copy Markdown

Claude finished @pantierra's task in 4m 16s —— View job


Reviewing PR #186

  • Gather context (diff, changed files)
  • Review for correctness bugs, security issues, best practices
  • Apply ponytail-review lens for over-engineering
  • Post final review

✅ No blocking issues — safe to merge.

Reviewed the diff of src/stac_auth_proxy/{app.py,metrics.py,config.py}, Dockerfile, pyproject.toml, uv.lock, and the tests against origin/main. The extras-gated approach (METRICS_AVAILABLE set via try/except ImportError at import time, endpoint toggled via presence in public_endpoints) is sound, matches what was agreed upon in the review thread, and is covered by tests for both the "extra installed" and "extra absent" paths.

Two non-blocking observations worth being aware of (not asking for changes, since both reflect the tradeoffs already discussed and approved in this thread):

  • src/stac_auth_proxy/app.py:90-96 — enabling metrics is coupled to /_mgmt/metrics being in public_endpoints. If an operator instead moves the path to private_endpoints (e.g. to require auth/scope for scraping) rather than removing it outright, metrics silently stop being instrumented at all rather than becoming an authenticated endpoint. Worth a doc callout if this comes up in support.
  • src/stac_auth_proxy/metrics.py:8-33 — the OPERATIONS route-shape table (^/collections/[^/]+/items/[^/]+$, etc.) duplicates the path shapes already encoded in config.py's private_endpoints. Low risk today, but the two tables can drift if STAC route shapes change in only one place.

Simplify (ponytail)

  • src/stac_auth_proxy/metrics.py:8-33OPERATIONS regex table re-encodes route shapes that already exist in config.py's private_endpoints/public_endpoints → could derive operation labels from those existing patterns instead of maintaining a second parallel table.

💰 Estimated review cost: $1.09 · 4m16s · 27 turns

@pantierra
pantierra merged commit 6825f23 into main Jul 22, 2026
10 checks passed
@pantierra
pantierra deleted the feat/prometheus-metrics-endpoint branch July 22, 2026 09:21
alukach pushed a commit that referenced this pull request Jul 23, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.2.0](v1.1.1...v1.2.0)
(2026-07-23)


### Features

* add optional prometheus metrics endpoint.
([#186](#186))
([6825f23](6825f23))


### Bug Fixes

* add ROOT_PATH_SKIP_PREFIXES to exempt sibling-service links from
root_path rewriting 2
([#198](#198))
([349986b](349986b))
* allow , delimited string in configuration
([#191](#191))
([df530a2](df530a2))
* allow Any type for classInput
([#182](#182))
([56aa3f5](56aa3f5))
* configurable upstream timeout.
([#174](#174))
([533bac6](533bac6))
* **helm:** make health path take root path into account.
([#189](#189))
([5236a0e](5236a0e))
* publish helm chart only on release
([#178](#178))
([c89f650](c89f650))
* **tests:** fix flaky health-check retry test caused by global
asyncio.sleep patch
([#193](#193))
([fec33b6](fec33b6))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: ds-release-bot[bot] <116609932+ds-release-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants