Skip to content

feat(BA-4702): Implement prometheus query preset repository layer#9470

Merged
HyeockJinKim merged 5 commits intomainfrom
feat/BA-4702
Mar 3, 2026
Merged

feat(BA-4702): Implement prometheus query preset repository layer#9470
HyeockJinKim merged 5 commits intomainfrom
feat/BA-4702

Conversation

@seedspirit
Copy link
Contributor

resolves #9365 (BA-4702)

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • Installer updates including:
    • Fixtures for db schema changes
    • New mandatory config options
  • Update of end-to-end CLI integration tests in ai.backend.test
  • API server-client counterparts (e.g., manager API -> client SDK)
  • Test case(s) to:
    • Demonstrate the difference of before/after
    • Demonstrate the flow of abstract/conceptual models with a concrete implementation
  • Documentation
    • Contents in the docs directory
    • docstrings in public interfaces and type annotations

@seedspirit seedspirit self-assigned this Feb 27, 2026
@github-actions github-actions bot added size:XL 500~ LoC comp:manager Related to Manager component comp:common Related to Common component labels Feb 27, 2026
@seedspirit seedspirit marked this pull request as ready for review February 27, 2026 06:58
@seedspirit seedspirit requested review from a team and Copilot February 27, 2026 06:58
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

This PR implements the repository layer for the prometheus query preset system as specified in issue #9365 (BA-4702). It provides the foundational data access layer that enables CRUD operations for managing prometheus query presets, including support for filtering, searching, and ordering. The implementation follows established repository patterns in the codebase, using resilience policies and the base repository abstractions.

Changes:

  • Added data types, modifiers, and list result classes for prometheus query presets
  • Implemented repository with CRUD operations (create, get_by_id, search, update, delete)
  • Added query conditions and orders for flexible searching and filtering
  • Created comprehensive unit tests covering CRUD operations and query options

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/ai/backend/manager/data/prometheus_query_preset/types.py Added frozen dataclass for preset data, modifier for updates, and list result type
src/ai/backend/manager/data/prometheus_query_preset/init.py Exported new data types
src/ai/backend/common/exception.py Added PrometheusQueryPresetNotFound exception and PROMETHEUS_QUERY_PRESET error domain
src/ai/backend/common/metrics/metric.py Added PROMETHEUS_QUERY_PRESET_REPOSITORY layer type for metrics
src/ai/backend/manager/repositories/prometheus_query_preset/repository.py Main repository class with resilience policies and public CRUD methods
src/ai/backend/manager/repositories/prometheus_query_preset/db_source/db_source.py Database operations implementation with session management
src/ai/backend/manager/repositories/prometheus_query_preset/creators.py Creator spec for preset creation
src/ai/backend/manager/repositories/prometheus_query_preset/updaters.py Updater spec for preset updates
src/ai/backend/manager/repositories/prometheus_query_preset/repositories.py Repositories wrapper following established pattern
src/ai/backend/manager/repositories/prometheus_query_preset/options.py Query conditions and orders for search operations
src/ai/backend/manager/repositories/prometheus_query_preset/init.py Package exports
tests/unit/manager/repositories/prometheus_query_preset/test_prometheus_query_preset_repository.py Unit tests for CRUD operations
tests/unit/manager/repositories/prometheus_query_preset/test_prometheus_query_preset_options.py Unit tests for query conditions and orders
tests/unit/manager/repositories/prometheus_query_preset/BUILD Build configuration for tests
changes/9470.feature.md Changelog entry

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

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

Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.


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

Comment on lines +44 to +45
self.filter_labels.update_dict(to_update, "filter_labels")
self.group_labels.update_dict(to_update, "group_labels")
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

PrometheusQueryPresetModifier.fields_to_update() populates keys "filter_labels" and "group_labels", but PrometheusQueryPresetRow does not have such columns (they are nested under the JSONB "options" column). If this modifier is used to build an UPDATE statement (as other *Modifier types are), it will generate invalid column updates. Consider either removing this modifier until it is wired correctly, or have it emit an "options" update (or provide a dedicated updater spec that correctly merges/updates PresetOptions).

Suggested change
self.filter_labels.update_dict(to_update, "filter_labels")
self.group_labels.update_dict(to_update, "group_labels")
# NOTE: filter_labels and group_labels are stored under a JSONB "options"
# column in the underlying row type, so they must be handled by a dedicated
# updater/merger rather than as top-level columns here.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +84
@prometheus_query_preset_repository_resilience.apply()
async def get_by_id(self, preset_id: UUID) -> PrometheusQueryPresetData:
"""Retrieves a prometheus query preset by ID."""
return await self._db_source.get_by_id(preset_id)
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

The repository layer currently exposes create/update/delete/get_by_id/search, but the referenced issue scope/acceptance criteria also calls for get_by_name. If get_by_name is required for the service/API layers, please add it to both PrometheusQueryPresetRepository and PrometheusQueryPresetDBSource (with a matching unit test) to avoid forcing callers to emulate it via a search.

Copilot uses AI. Check for mistakes.
test_case: SearchContext,
) -> None:
assert isinstance(
test_case.case, ConditionCase
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

This isinstance() assert is only here for type-narrowing, but when it fails it won’t provide a helpful message. Consider matching the pattern used in test_search_with_order (line ~301) by adding an explicit assertion message (or using typing.cast) so failures are easier to diagnose.

Suggested change
test_case.case, ConditionCase
test_case.case, ConditionCase
), (
f"Expected test_case.case to be ConditionCase in test_search_by_condition, "
f"got {type(test_case.case)!r}"

Copilot uses AI. Check for mistakes.
@HyeockJinKim HyeockJinKim merged commit f87bb74 into main Mar 3, 2026
25 checks passed
@HyeockJinKim HyeockJinKim deleted the feat/BA-4702 branch March 3, 2026 02:58
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.

Add data types, error definitions, and repository layer for prometheus query presets

5 participants