Skip to content

Prometheus metrics integration#515

Merged
janbjorge merged 8 commits intomainfrom
feature/prometheus-metrics-integration
Feb 16, 2026
Merged

Prometheus metrics integration#515
janbjorge merged 8 commits intomainfrom
feature/prometheus-metrics-integration

Conversation

@janbjorge
Copy link
Copy Markdown
Owner

@janbjorge janbjorge commented Dec 25, 2025

Closes #513

  • Add pgqueuer.metrics.prometheus module with collect_metrics function
  • Add pgqueuer.metrics.fastapi module with create_metrics_router for plug-and-play FastAPI integration
  • Add fastapi optional dependency (pip install pgqueuer[fastapi])
  • Update documentation with usage examples

Summary

Framework-agnostic Prometheus metrics integration for PGQueuer. The core collect_metrics function returns a Prometheus-formatted string that can be served from any web framework. A plug-and-play FastAPI router is provided for convenience.

Testing

  • make check passed
  • Additional testing steps

Checklist

  • I have read the Contributing Guide
  • I have added or updated tests
  • I have updated documentation if necessary

@janbjorge janbjorge force-pushed the feature/prometheus-metrics-integration branch from 0c8cda2 to b216da4 Compare December 25, 2025 12:37
@janbjorge janbjorge self-assigned this Dec 25, 2025
@janbjorge janbjorge added the enhancement New feature or request label Dec 25, 2025
@janbjorge janbjorge force-pushed the feature/prometheus-metrics-integration branch 2 times, most recently from c1526a4 to d9049ca Compare December 25, 2025 22:45
@janbjorge janbjorge marked this pull request as ready for review December 25, 2025 22:45
@janbjorge janbjorge changed the title Add framework-agnostic Prometheus metrics integration Prometheus metrics integration Dec 25, 2025
@janbjorge janbjorge force-pushed the feature/prometheus-metrics-integration branch 2 times, most recently from b59071e to 12f322a Compare December 25, 2025 22:54
Closes #513

- Add pgqueuer.metrics.prometheus module with collect_metrics function
- Use QueriesProtocol for flexible integration with any queries implementation
- Update documentation with FastAPI, Flask, and Starlette examples
- Add tests for metrics formatting and framework integrations
- Add pgqueuer.metrics.fastapi with create_metrics_router
- Add pgqueuer.metrics.flask with create_metrics_blueprint
- Add optional dependencies: pgqueuer[fastapi], pgqueuer[flask]
- Update documentation with simplified examples
- Add tests for framework integrations
- Remove factory pattern in favor of direct Queries injection
- Simpler API: just pass your Queries instance
- Update docs and tests accordingly
- Delete pgqueuer/metrics/flask.py
- Remove flask from optional and dev dependencies in pyproject.toml
- Remove Flask integration section from prometheus-metrics-service.md
- Remove Flask-related tests from test_metrics_prometheus.py
- Regenerate uv.lock
- Remove QueriesProtocol, use Queries directly
- Remove add_prefix from prometheus_format (metric names are already configurable via MetricNames)
@janbjorge janbjorge force-pushed the feature/prometheus-metrics-integration branch from 12f322a to 108e6ca Compare February 16, 2026 14:41
Align metrics collection with ports-and-adapters architecture by depending
on the QueueRepositoryPort protocol instead of the concrete Queries class.
This enables metrics to work with any repository implementation and improves
testability through dependency injection.

- Add log_statistics method to QueueRepositoryPort
- Update prometheus.py and fastapi.py to accept QueueRepositoryPort
- Update tests to use the protocol abstraction
- Remove unused ReduceFn type alias
Rename test variables to avoid type annotation conflicts and mark
QueueRepositoryPort as @runtime_checkable for proper protocol handling.

- Rename repository variables to fake_repo in tests for clarity
- Add @runtime_checkable to QueueRepositoryPort
- Add minimal type: ignore[arg-type] annotations where needed
Use explicit typing.cast() instead of type: ignore comments to handle
structural subtyping of FakeQueries to QueueRepositoryPort. This is more
semantically correct and avoids suppressing type errors.

- Replace 4 'type: ignore[arg-type]' with cast() calls
- Remove unnecessary @runtime_checkable decorator
- Improve code clarity with explicit intent
@janbjorge janbjorge merged commit 9ff3c4e into main Feb 16, 2026
42 checks passed
@janbjorge janbjorge deleted the feature/prometheus-metrics-integration branch February 16, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Prometheus helper importable from pgqueuer

1 participant