feat(prometheus): honor PROMETHEUS_URL as the default server URL - #71
Open
jedi-tal wants to merge 1 commit into
Open
feat(prometheus): honor PROMETHEUS_URL as the default server URL#71jedi-tal wants to merge 1 commit into
jedi-tal wants to merge 1 commit into
Conversation
`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
force-pushed
the
feat/prometheus-url-env
branch
from
August 14, 2026 18:56
ebfbf9d to
3ad9e20
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.
Problem
PROMETHEUS_URLis documented in the README as "Default Prometheus server URL", but nothing reads it. Everyprometheus_*handler hard-codes the fallback:and the chart's
tools.prometheus.urlvalue 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_urlon every single call. Since the parameter is optional and the schema advertises a plausible default, models routinely omit it — the call fails withconnection refusedagainst 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()readsPROMETHEUS_URL(trimmed), falling back tohttp://localhost:9090when unset — existing deployments are unchanged.prometheus_urlparameter 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.PROMETHEUS_URLfromtools.prometheus.url, only when set. That value's previous default was schemeless (prometheus.kagent.svc.cluster.local:9090) and would be rejected bysecurity.ValidateURL("must start with http:// or https://"), so it now defaults to empty = tool default.An explicit
prometheus_urlargument still wins when supplied.Test
TestDefaultPrometheusURL— unset → localhost fallback; set (with surrounding whitespace) → honored, and reflected in the parameter description.TestPrometheusURLDefaultsToEnv— a call that omitsprometheus_urlreaches the env-configured server, asserted on the recorded request URL.go vet+go test ./pkg/prometheus/...pass;gofmtclean. Chart rendered both ways: env present whentools.prometheus.urlis set, absent when it is not.Closes #63