Skip to content

feat(BA-4054): Add REST API endpoints for prometheus query preset CRUD and execution#9640

Open
seedspirit wants to merge 4 commits intomainfrom
BA-4054
Open

feat(BA-4054): Add REST API endpoints for prometheus query preset CRUD and execution#9640
seedspirit wants to merge 4 commits intomainfrom
BA-4054

Conversation

@seedspirit
Copy link
Contributor

@seedspirit seedspirit commented Mar 5, 2026

Summary

  • Add REST API handler with 6 endpoints for prometheus query preset management per BEP-1050
  • CRUD endpoints (create, list, get, modify, delete) restricted to SUPERADMIN via middleware
  • Execute endpoint available to all authenticated users, converts MetricLabelEntry key-value pairs to filter_labels dict and transforms Prometheus response to BEP-1050 format
  • Register routes at /resource/prometheus-query-presets in the REST API tree

Test plan

  • [] Verify CRUD endpoints return correct responses with valid input
  • [] Verify SUPERADMIN-only access for CRUD endpoints
  • Verify execute endpoint works for authenticated non-admin users
  • Verify proper error responses for invalid parameters
  • CI passes (lint, type check, tests)

Resolves BA-4054 #8268

Copilot AI review requested due to automatic review settings March 5, 2026 01:22
seedspirit added a commit that referenced this pull request Mar 5, 2026
@github-actions github-actions bot added size:XL 500~ LoC comp:manager Related to Manager component comp:common Related to Common component labels Mar 5, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@seedspirit seedspirit requested a review from a team March 6, 2026 06:59
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)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason it was changed to extra="allow"?

Copy link
Contributor Author

@seedspirit seedspirit Mar 6, 2026

Choose a reason for hiding this comment

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

I made the change in case an unexpected value came in, but I will delete it for compatibility

Comment on lines +135 to +166
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()
),
Copy link
Member

Choose a reason for hiding this comment

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

Is there no to_updater() method in ModifyQueryDefinitionRequest type?

Comment on lines +104 to +106
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")
Copy link
Member

Choose a reason for hiding this comment

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

Is there no instant query preset yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, so I need to implement in follow up issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:common Related to Common component comp:manager Related to Manager component size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants