Skip to content

feat(prometheus): expose an instant PromQL query as a provider method - #6689

Open
dngr2 wants to merge 1 commit into
keephq:mainfrom
dngr2:feat/6475-prometheus-query-method
Open

feat(prometheus): expose an instant PromQL query as a provider method#6689
dngr2 wants to merge 1 commit into
keephq:mainfrom
dngr2:feat/6475-prometheus-query-method

Conversation

@dngr2

@dngr2 dngr2 commented Aug 12, 2026

Copy link
Copy Markdown

Fixes #6475

What was actually missing

The provider can already run instant queries — _query() hits /api/v1/query with the configured basic auth. What was missing is any way to reach it: PROVIDER_METHODS was empty, so the UI and agents report methods: [], 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()
  • declared in PROVIDER_METHODS as a read-only view, scoped to connectivity (the provider's existing scope)

Why the tests check the declaration and not just the call

ProvidersFactory.__get_methods reflects methods with:

inspect.signature(provider_class.__dict__.get(method.func_name))

A func_name that doesn't resolve on the class itself — a typo, or a method that is inherited rather than defined here — makes that inspect.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 in PROVIDER_SCOPES.

Reflection output with this change:

name: Query Prometheus | func_name: query_instant
type: view | scopes: ['connectivity']
params: [('query', 'str', True)]

Tests

New file: tests/providers/prometheus_provider/test_prometheus_query_method.py

Against unmodified main: 8 failed, 2 passed — the 2 are loop-based guards that pass vacuously while PROVIDER_METHODS is empty, so they are regression protection rather than evidence. With the change: 10 passed.

  • the method is declared, resolves on the class, and its scope exists
  • the endpoint and params sent for an instant query
  • the response envelope returned unchanged
  • empty query rejected; non-200 raises
  • basic auth used when credentials are set, omitted when they are not

tests/providers in 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 needs start/stop/step and 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.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. Feature A new feature labels Aug 12, 2026
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
dngr2 force-pushed the feat/6475-prometheus-query-method branch from 7d57921 to a7d8578 Compare August 12, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature A new feature size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[➕ Feature]: Add method to query prometheus provider

1 participant