feat(devops): add out-of-the-box Prometheus metrics and Grafana observability stack#9346
feat(devops): add out-of-the-box Prometheus metrics and Grafana observability stack#9346akoweicollinxx wants to merge 4 commits into
Conversation
…y-parameter Honor `page` in public work-item pagination and terminate `next_cursor` at dataset end
|
|
📝 WalkthroughWalkthroughModifies BasePaginator.paginate to explicitly parse a ChangesPagination page parameter support
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)Not applicable; changes involve internal pagination logic with fewer than 3 distinct interacting components. Poem 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Warning |
There was a problem hiding this comment.
Pull request overview
This PR, as reflected by the included diff, updates the API pagination utility to support a page query parameter (in addition to cursor-based pagination) and adjusts cursor metadata serialization, with accompanying unit tests. However, this does not match the PR title/description about adding Prometheus/Grafana observability (see stored comment).
Changes:
- Added
pagequery param support inBasePaginator.paginate()with validation and conversion into an internal cursor. - Changed
next_cursorserialization to returnnull/Nonewhen there are no further results. - Added unit tests covering
pagebehavior and termination when followingnext_cursor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/api/plane/utils/paginator.py | Adds page parameter handling and modifies cursor metadata serialization in paginated responses. |
| apps/api/plane/tests/unit/utils/test_paginator.py | Adds unit tests for page support and next-cursor termination behavior. |
| "total_count": (cursor_result.hits), | ||
| "next_cursor": str(cursor_result.next), | ||
| "next_cursor": str(cursor_result.next) if cursor_result.next.has_results else None, | ||
| "prev_cursor": str(cursor_result.prev), | ||
| "next_page_results": cursor_result.next.has_results, | ||
| "prev_page_results": cursor_result.prev.has_results, |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
apps/api/plane/tests/unit/utils/test_paginator.py (1)
29-49: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for the new error paths.
The new
paginatelogic raisesParseErrorfor non-integerpage,page < 1, and invalidcursorstrings, but none of these are tested here. Consider adding cases assertingParseError(e.g.,pytest.raises) forpage="abc",page="0", and a malformedcursorvalue.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/api/plane/tests/unit/utils/test_paginator.py` around lines 29 - 49, The paginator tests cover valid page behavior but miss the new ParseError branches in paginate. Add negative test cases in test_paginate_honors_explicit_page_parameter or nearby tests to assert ParseError is raised for non-integer page values, page values less than 1, and malformed cursor strings; use BasePaginator.paginate with the existing OffsetEchoPaginator and pytest.raises to verify these error paths.apps/api/plane/utils/paginator.py (2)
737-738: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win
prev_cursoris not nulled symmetrically withnext_cursor.This change nulls
next_cursorwhencursor_result.next.has_resultsis false, butprev_cursor(line 738) is always returned as a string even whenprev_page_resultsis false (e.g., on the first page). This is an inconsistent API contract for consumers that now rely onNoneto detect the end of pagination — the same pattern should arguably apply toprev_cursorat the start.♻️ Suggested symmetry fix
- "prev_cursor": str(cursor_result.prev), + "prev_cursor": str(cursor_result.prev) if cursor_result.prev.has_results else None,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/api/plane/utils/paginator.py` around lines 737 - 738, The pagination cursor response in paginator.py is inconsistent because `next_cursor` is nulled via `cursor_result.next.has_results` but `prev_cursor` from the pagination result is always stringified. Update the cursor-building logic in the paginator response to mirror the `next_cursor` pattern by returning `None` for `prev_cursor` when the previous page has no results (for example on the first page), using the existing cursor result fields in the paginator method that assembles `next_cursor` and `prev_cursor`.
677-696: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueCursor takes silent precedence over page param.
When both
cursorandpagequery params are supplied,pageis silently ignored with no validation or feedback. Consider documenting this precedence in a comment, or raising aParseErrorif both are supplied to avoid ambiguous client expectations.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/api/plane/utils/paginator.py` around lines 677 - 696, The cursor-handling logic in paginator parsing silently ignores the page parameter when both query params are present. Update the branch in the paginator method that reads input_cursor_value and page_value to either explicitly reject requests containing both with a ParseError or add a clear comment/documented precedence if cursor must win. Keep the behavior consistent in the cursor parsing path and ensure the precedence decision is visible near cursor_cls.from_string and the page_number handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/api/plane/tests/unit/utils/test_paginator.py`:
- Around line 29-49: The paginator tests cover valid page behavior but miss the
new ParseError branches in paginate. Add negative test cases in
test_paginate_honors_explicit_page_parameter or nearby tests to assert
ParseError is raised for non-integer page values, page values less than 1, and
malformed cursor strings; use BasePaginator.paginate with the existing
OffsetEchoPaginator and pytest.raises to verify these error paths.
In `@apps/api/plane/utils/paginator.py`:
- Around line 737-738: The pagination cursor response in paginator.py is
inconsistent because `next_cursor` is nulled via
`cursor_result.next.has_results` but `prev_cursor` from the pagination result is
always stringified. Update the cursor-building logic in the paginator response
to mirror the `next_cursor` pattern by returning `None` for `prev_cursor` when
the previous page has no results (for example on the first page), using the
existing cursor result fields in the paginator method that assembles
`next_cursor` and `prev_cursor`.
- Around line 677-696: The cursor-handling logic in paginator parsing silently
ignores the page parameter when both query params are present. Update the branch
in the paginator method that reads input_cursor_value and page_value to either
explicitly reject requests containing both with a ParseError or add a clear
comment/documented precedence if cursor must win. Keep the behavior consistent
in the cursor parsing path and ensure the precedence decision is visible near
cursor_cls.from_string and the page_number handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5b6ccafe-513d-4be6-a941-d51775abdcbc
📒 Files selected for processing (2)
apps/api/plane/tests/unit/utils/test_paginator.pyapps/api/plane/utils/paginator.py
Description
This PR adds a self-contained observability setup for local development and self-hosted deployments.
What changed
Added django-prometheus to the API so it exposes Prometheus-compatible metrics.
Integrated Prometheus middleware to collect request and database timing data.
Added Prometheus and Grafana services to docker-compose-local.yml.
Included Grafana provisioning so datasources and dashboards are configured automatically.
Added a prebuilt dashboard to visualize API request counts and latency.
Validation
Built the local stack with Docker Compose.
Verified the /metrics endpoint is available.
Confirmed Prometheus is scraping targets successfully.
Opened Grafana and validated the dashboard renders live data.
Summary by CodeRabbit