feat(prometheus): expose an instant PromQL query as a provider method - #6689
Open
dngr2 wants to merge 1 commit into
Open
feat(prometheus): expose an instant PromQL query as a provider method#6689dngr2 wants to merge 1 commit into
dngr2 wants to merge 1 commit into
Conversation
The provider could already run instant queries through _query(), but PROVIDER_METHODS was empty, so the UI and agents saw `methods: []` on this provider and had no way to reach it — which is what keephq#6475 reports. Adds query_instant(query: str), a thin public wrapper over the existing _query(), and declares it in PROVIDER_METHODS as a read-only view scoped to `connectivity`. No query logic changes: the endpoint, auth handling and error behaviour are the ones already in _query(). ProvidersFactory reflects methods via provider_class.__dict__, so the function must be defined on the class itself; the tests assert that invariant along with the declared scope existing, since getting either wrong fails at provider-load time rather than at call time. Scope note: this covers instant queries only. /api/v1/query_range needs start/stop/step and a decision about result size limits, so it is left out pending maintainer preference. Fixes keephq#6475
dngr2
force-pushed
the
feat/6475-prometheus-query-method
branch
from
August 12, 2026 02:51
7d57921 to
a7d8578
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6475
What was actually missing
The provider can already run instant queries —
_query()hits/api/v1/querywith the configured basic auth. What was missing is any way to reach it:PROVIDER_METHODSwas empty, so the UI and agents reportmethods: [], which is what the issue shows.So this is an exposure change, not a new query implementation. No change to the endpoint, the auth handling or the error behaviour.
The change
query_instant(query: str) -> dict, a public wrapper over the existing_query()PROVIDER_METHODSas a read-onlyview, scoped toconnectivity(the provider's existing scope)Why the tests check the declaration and not just the call
ProvidersFactory.__get_methodsreflects methods with:A
func_namethat doesn't resolve on the class itself — a typo, or a method that is inherited rather than defined here — makes thatinspect.signature(None), which raises when the provider is loaded, not when the method is called. The tests assert that invariant, and that every scope a method declares exists inPROVIDER_SCOPES.Reflection output with this change:
Tests
New file:
tests/providers/prometheus_provider/test_prometheus_query_method.pyAgainst unmodified
main: 8 failed, 2 passed — the 2 are loop-based guards that pass vacuously whilePROVIDER_METHODSis empty, so they are regression protection rather than evidence. With the change: 10 passed.paramssent for an instant querytests/providersin full: 63 passed. I have not run the suites needing Docker and a database locally — leaving those to CI.Question before I extend this
I have deliberately left out
/api/v1/query_range. It needsstart/stop/stepand a decision about capping result size, and the issue only asks to run PromQL. Happy to add it in this PR if you'd like it — I'd rather ask than guess at the parameter shape.Worth noting separately:
_query()sends its request with no timeout, so a slow or hanging Prometheus will block the caller. I left that alone to keep this focused, but I'm glad to open a separate PR for it.