Skip to content

feat(prometheus): honor PROMETHEUS_URL as the default server URL - #71

Open
jedi-tal wants to merge 1 commit into
kagent-dev:mainfrom
jedi-tal:feat/prometheus-url-env
Open

feat(prometheus): honor PROMETHEUS_URL as the default server URL#71
jedi-tal wants to merge 1 commit into
kagent-dev:mainfrom
jedi-tal:feat/prometheus-url-env

Conversation

@jedi-tal

Copy link
Copy Markdown

Problem

PROMETHEUS_URL is documented in the README as "Default Prometheus server URL", but nothing reads it. Every prometheus_* handler hard-codes the fallback:

prometheusURL := mcp.ParseString(request, "prometheus_url", "http://localhost:9090")

and the chart's tools.prometheus.url value is never passed to the container (#63, #36).

So the only way to reach a Prometheus that is not on localhost is for the model to pass prometheus_url on every single call. Since the parameter is optional and the schema advertises a plausible default, models routinely omit it — the call fails with connection refused against a port nothing serves inside the tool server's pod, and the agent burns a turn retrying.

That is not theoretical: on a scheduled cluster-health agent of ours (tool server pointed at an in-cluster Thanos Query), one run omitted the parameter on its first 12 calls and spent its entire 24-call budget re-issuing them, shipping a report with several findings left unidentified.

Change

  • defaultPrometheusURL() reads PROMETHEUS_URL (trimmed), falling back to http://localhost:9090 when unset — existing deployments are unchanged.
  • The prometheus_url parameter description is built from that same value, so the tool schema advertises the default a caller will actually get rather than always claiming localhost. This is the part that stops the model from omitting it wrongly.
  • The chart renders PROMETHEUS_URL from tools.prometheus.url, only when set. That value's previous default was schemeless (prometheus.kagent.svc.cluster.local:9090) and would be rejected by security.ValidateURL ("must start with http:// or https://"), so it now defaults to empty = tool default.

An explicit prometheus_url argument still wins when supplied.

Test

  • TestDefaultPrometheusURL — unset → localhost fallback; set (with surrounding whitespace) → honored, and reflected in the parameter description.
  • TestPrometheusURLDefaultsToEnv — a call that omits prometheus_url reaches the env-configured server, asserted on the recorded request URL.

go vet + go test ./pkg/prometheus/... pass; gofmt clean. Chart rendered both ways: env present when tools.prometheus.url is set, absent when it is not.

Closes #63

`PROMETHEUS_URL` is documented in the README ("Default Prometheus server
URL") but was never read: every prometheus_* handler hard-coded
`http://localhost:9090` as the fallback for the optional `prometheus_url`
parameter, and the Helm chart's `tools.prometheus.url` value was never
passed to the container (kagent-dev#63, kagent-dev#36).

The practical effect is that the ONLY way to reach a Prometheus that is
not on localhost is for the model to pass `prometheus_url` on every single
call. Because the parameter is optional and the schema advertises a
plausible-looking default, models routinely omit it - the call then fails
with "connection refused" against a port nothing serves inside the tool
server's pod, and the agent burns a turn retrying. On one of our scheduled
survey agents this wasted 12 of a 24-call budget in a single run.

- read `PROMETHEUS_URL` (trimmed) as the default, falling back to
  `http://localhost:9090` when unset, so existing deployments are unchanged
- build the `prometheus_url` parameter description from that same value, so
  the tool schema advertises the default a caller will actually get instead
  of always claiming localhost
- render `PROMETHEUS_URL` in the chart from `tools.prometheus.url`, only
  when set; its previous default was schemeless
  (`prometheus.kagent.svc.cluster.local:9090`) and would have been rejected
  by `security.ValidateURL`, so it now defaults to empty = tool default

The explicit `prometheus_url` parameter still wins when supplied.

Closes kagent-dev#63

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: jedi-tal <tal@jedify.com>
@jedi-tal
jedi-tal force-pushed the feat/prometheus-url-env branch from ebfbf9d to 3ad9e20 Compare August 14, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant