Skip to content

fix(BA-5470): Add missing update, execute commands and admin CLI module for v2 prometheus-query-preset#10606

Open
seedspirit wants to merge 9 commits intomainfrom
BA-5470
Open

fix(BA-5470): Add missing update, execute commands and admin CLI module for v2 prometheus-query-preset#10606
seedspirit wants to merge 9 commits intomainfrom
BA-5470

Conversation

@seedspirit
Copy link
Contributor

Summary

  • Add execute() method to v2 SDK and REST handler for prometheus query presets
  • Add update and execute CLI commands to user-facing v2 prometheus-query-preset module
  • Create admin CLI module with search, create, update, delete commands registered via LazyGroup
  • Fix ExecuteQueryDefinitionInput.time_range type to use QueryTimeRangeInputDTO for consistency

Test plan

  • pants check --changed-since=origin/main passes
  • pants test --changed-since=origin/main passes
  • ./bai prometheus-query-preset update <id> <json> works
  • ./bai prometheus-query-preset execute <id> works with time range and label options
  • ./bai admin prometheus-query-preset search works
  • ./bai admin prometheus-query-preset create/update/delete work

Resolves BA-5470

seedspirit and others added 6 commits March 27, 2026 07:54
Add execute() to V2PrometheusQueryPresetClient that POSTs to
/v2/prometheus-query-presets/{preset_id}/execute with
ExecuteQueryDefinitionInput and returns ExecuteQueryDefinitionPayload.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…T handler

Add execute handler method that calls adapter.execute_preset() and converts
QueryDefinitionResultInfo to ExecuteQueryDefinitionPayload. Register route
POST /{preset_id}/execute with superadmin_required middleware. Also fix
ExecuteQueryDefinitionInput.time_range to use QueryTimeRangeInputDTO (datetime)
instead of client QueryTimeRange (str) for type consistency with the adapter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add execute command with --start, --end, --step, --label, --group-labels,
and --time-window options. Includes _parse_label_filters helper for
parsing key=value label format into MetricLabelEntry objects.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add admin commands (search, create, update, delete) under
`./bai admin prometheus-query-preset` and register the LazyGroup
in the admin __init__.py.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…e_label_filters

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 26, 2026 23:09
@github-actions github-actions bot added the size:L 100~500 LoC label Mar 26, 2026
@github-actions github-actions bot added comp:manager Related to Manager component comp:client Related to Client component comp:common Related to Common component comp:cli Related to CLI component labels Mar 26, 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

Completes the v2 Prometheus query preset surface area by adding preset execution support across the REST API, SDK, and CLIs, plus introducing an admin-focused CLI module.

Changes:

  • Added REST v2 route + handler for executing a Prometheus query preset.
  • Added v2 SDK execute() plus CLI update/execute commands for prometheus-query-preset.
  • Introduced an admin CLI module (lazy-registered) with search/create/update/delete commands; aligned time_range DTO type.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
src/ai/backend/manager/api/rest/v2/prometheus_query_preset/registry.py Registers the new execute endpoint for presets.
src/ai/backend/manager/api/rest/v2/prometheus_query_preset/handler.py Implements the REST handler for preset execution and response shaping.
src/ai/backend/common/dto/manager/v2/prometheus_query_preset/request.py Updates ExecuteQueryDefinitionInput.time_range to use QueryTimeRangeInputDTO.
src/ai/backend/client/v2/domains_v2/prometheus_query_preset.py Adds SDK method to call the new execute endpoint.
src/ai/backend/client/cli/v2/prometheus_query_preset/commands.py Adds user-facing update and execute commands and label/time-range parsing.
src/ai/backend/client/cli/v2/admin/prometheus_query_preset.py Adds admin CLI commands for managing query presets.
src/ai/backend/client/cli/v2/admin/init.py Lazy-registers the new admin CLI group.
changes/10606.feature.md Adds changelog entry for the new CLI/SDK features.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 24 to 28
reg.add("POST", "/search", handler.admin_search, middlewares=[superadmin_required])
reg.add("GET", "/{preset_id}", handler.get, middlewares=[superadmin_required])
reg.add("PATCH", "/{preset_id}", handler.update, middlewares=[superadmin_required])
reg.add("POST", "/{preset_id}/execute", handler.execute, middlewares=[superadmin_required])
reg.add("POST", "/delete", handler.delete, middlewares=[superadmin_required])
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The PR description says update/execute are added to the “user-facing v2 prometheus-query-preset module”, but the manager REST routes (including the newly added execute) are guarded by superadmin_required. If these commands are intended for non-superadmins, the REST route middleware needs to be relaxed (or a separate non-admin route should be added). If they are superadmin-only, consider moving these CLI commands under the admin CLI module to match the authorization model.

Copilot uses AI. Check for mistakes.
Comment on lines +142 to +144
result = await registry.prometheus_query_preset.update(
UUID(preset_id), ModifyQueryDefinitionInput(**data)
)
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

Same as the user CLI: preset_id is typed as str but is later coerced to UUID(...), which can lead to unhandled tracebacks on invalid input. Use a Click UUID argument type (or explicit click.BadParameter) for consistent, user-friendly validation failures.

Copilot uses AI. Check for mistakes.
…etheus-query-definition

The external-facing CLI command name should match the v1 naming
convention (query-definition), not the internal package name
(query-preset).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@seedspirit seedspirit changed the title feat(BA-5470): complete v2 CLI/SDK for prometheus-query-preset fix(BA-5470): complete v2 CLI/SDK for prometheus-query-definition Mar 26, 2026
@seedspirit seedspirit changed the title fix(BA-5470): complete v2 CLI/SDK for prometheus-query-definition fix(BA-5470): Add missing update, execute commands and admin CLI module for v2 prometheus-query-preset Mar 26, 2026
… validation

- Use click.UUID type for all preset_id arguments instead of str+UUID()
  conversion, providing clean CLI validation errors on invalid input
- Add validation that --start, --end, --step must all be provided
  together or none at all, instead of silently ignoring partial input

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@seedspirit seedspirit requested review from a team March 27, 2026 03:52
@seedspirit seedspirit added this to the 26.4 milestone Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:cli Related to CLI component comp:client Related to Client component comp:common Related to Common component comp:manager Related to Manager component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants