feat(BA-4054): Add REST API endpoints for prometheus query preset CRUD and execution#9640
feat(BA-4054): Add REST API endpoints for prometheus query preset CRUD and execution#9640seedspirit wants to merge 4 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Implements REST API endpoints for Prometheus query preset management per BEP-1050, providing CRUD operations restricted to SUPERADMIN and an execute endpoint available to all authenticated users.
Changes:
- New handler with 6 endpoints (create, list, get, modify, delete, execute) for prometheus query preset management
- New request/response/path DTOs in the common package shared with the Client SDK
- Route registration wired into the REST API tree under
/resource/prometheus-query-presets
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tree.py |
Registers the new prometheus query preset routes in the API route list |
registry.py |
Defines the route-to-handler mappings with appropriate auth middleware |
handler.py |
Implements all 6 API endpoint handlers and helper conversion functions |
response.py |
Defines response DTOs for all endpoints |
request.py |
Defines request DTOs for all endpoints |
path.py |
Defines path parameter DTO for preset ID |
__init__.py |
Re-exports all DTOs from the package |
changes/9640.feature.md |
Changelog entry for the new feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
src/ai/backend/manager/api/rest/prometheus_query_preset/handler.py
Outdated
Show resolved
Hide resolved
src/ai/backend/common/dto/manager/prometheus_query_preset/request.py
Outdated
Show resolved
Hide resolved
src/ai/backend/manager/api/rest/prometheus_query_preset/registry.py
Outdated
Show resolved
Hide resolved
| session_id: str | None = Field(default=None) | ||
|
|
||
| model_config = ConfigDict(validate_by_name=True, validate_by_alias=True) | ||
| model_config = ConfigDict(extra="allow", validate_by_name=True, validate_by_alias=True) |
There was a problem hiding this comment.
Is there a reason it was changed to extra="allow"?
There was a problem hiding this comment.
I made the change in case an unexpected value came in, but I will delete it for compatibility
| parsed = body.parsed | ||
| updater_spec = PrometheusQueryPresetUpdaterSpec( | ||
| name=( | ||
| OptionalState.update(parsed.name) | ||
| if parsed.name is not None | ||
| else OptionalState.nop() | ||
| ), | ||
| metric_name=( | ||
| OptionalState.update(parsed.metric_name) | ||
| if parsed.metric_name is not None | ||
| else OptionalState.nop() | ||
| ), | ||
| query_template=( | ||
| OptionalState.update(parsed.query_template) | ||
| if parsed.query_template is not None | ||
| else OptionalState.nop() | ||
| ), | ||
| time_window=TriState.nop() | ||
| if isinstance(parsed.time_window, Sentinel) | ||
| else TriState.nullify() | ||
| if parsed.time_window is None | ||
| else TriState.update(parsed.time_window), | ||
| filter_labels=( | ||
| OptionalState.update(parsed.options.filter_labels) | ||
| if parsed.options is not None and parsed.options.filter_labels is not None | ||
| else OptionalState.nop() | ||
| ), | ||
| group_labels=( | ||
| OptionalState.update(parsed.options.group_labels) | ||
| if parsed.options is not None and parsed.options.group_labels is not None | ||
| else OptionalState.nop() | ||
| ), |
There was a problem hiding this comment.
Is there no to_updater() method in ModifyQueryDefinitionRequest type?
| if action.time_range is None: | ||
| # TODO: Implement instant query execution (query_instant) in the Prometheus client and use it here. | ||
| raise InvalidAPIParameters("time_range is required for preset execution") |
There was a problem hiding this comment.
Is there no instant query preset yet?
There was a problem hiding this comment.
yes, so I need to implement in follow up issue
Summary
/resource/prometheus-query-presetsin the REST API treeTest plan
Resolves BA-4054 #8268