Skip to content

fix(roadmap): eval grades reaches Loki with no localhost fallback #5481

Done

Description

@dan-petty

Problem Description

devops roadmap eval grades fails on a workstation that has no loki.url setting:

Loki at http://localhost:3100 did not answer: [Errno 111] Connection refused. Set loki.url, or give --loki-url with the address of a Loki that this host reaches.

resolve_loki_url in src/devops_cli/k8s/logql.py uses the option, then loki.url, then DEFAULT_LOKI_URL (http://localhost:3100). Nothing listens on that address unless a person starts a port-forward. The title of #1165 states the rule: service clients use only configured URLs and never fall back to an unconfigured localhost default. DEFAULT_LOKI_URL is still such a fallback. The Grafana datasource reached the same Loki at the same time.

Reproduction Steps

  1. Leave loki.url unset, and start no port-forward to Loki.
  2. Run devops roadmap eval grades --window 24h.

Expected vs Actual Behavior

Expected: the command reaches the Loki of the cluster, through a port-forward that it opens itself, or it stops before a request with an error that names loki.url.

Actual: the command sends a request to http://localhost:3100 and gets Connection refused.

Environment Diagnostics

devops-cli at origin/main of 2026-11-13, a devcontainer with kubectl access to the cluster.

Logs, Traces, or Terminal Output

Found while writing the agentic workflow spec (#5443). The spec measured the grades with LogQL through the Grafana datasource because of this failure.

Source: #5443

Alternatives check of 2026-11-23: none.
Tool: none found.
Reason: Searches returned no open, maintained tool for configured-URL resolution: the need is a change inside the project's own resolve_loki_url, constant removal and selector settings, which no Loki client or Kubernetes library supplies.

Lacks:

  • No configured-URL resolution without a localhost default
  • No early error naming loki.url before a request
  • No LogQL selector built from the roadmap Service settings

Proposed design

Problem statement

On a host with no loki.url setting, devops roadmap eval grades dials http://localhost:3100 from DEFAULT_LOKI_URL and fails with Connection refused. This breaks the rule of #1165 that a service client uses only a configured URL. The change removes the constant and stops the command before a request with an error that names loki.url. It keeps the kubectl fallback of execute_logql_query. The selector change of the earlier plan is dropped because #5556 already replaced it on main.

Acceptance criteria

Requirement: Explicit Loki URL

resolve_loki_url SHALL return the explicit loki_url argument when it is set.

Scenario: Explicit URL wins

  • WHEN resolve_loki_url receives http://loki.example:3100 while the loki.url setting is http://loki.team:3100.
  • THEN The call returns http://loki.example:3100.

Requirement: Configured Loki setting

resolve_loki_url SHALL return the loki.url setting when the explicit argument is not set.

Scenario: Setting supplies the URL

  • WHEN resolve_loki_url receives no argument and the loki.url setting is http://loki.team:3100.
  • THEN The call returns http://loki.team:3100.

Requirement: Missing Loki URL

resolve_loki_url MUST raise KubernetesLoggingError with a message that names loki.url when neither the argument nor the setting is set.

Scenario: No URL configured

  • WHEN resolve_loki_url receives no argument and the loki.url setting is unset.
  • THEN The call raises KubernetesLoggingError whose message contains loki.url.

Requirement: Explicit URL argument on the query

execute_loki_query MUST declare loki_url with no default value.

Scenario: The query signature has no default

  • WHEN A test reads the signature of execute_loki_query with inspect.signature.
  • THEN The parameter loki_url has the default inspect.Parameter.empty.

Requirement: Remove the fallback constant

The package MUST NOT define or import DEFAULT_LOKI_URL after the change.

Scenario: The constant is gone

  • WHEN A test imports devops_cli.config.defaults and devops_cli.k8s.logql.
  • THEN Neither module has an attribute DEFAULT_LOKI_URL.

Requirement: Kubectl fallback without a Loki URL

execute_logql_query SHALL use the kubectl log stream when no loki.url is set and SHALL send no request to a localhost address.

Scenario: No URL falls back to kubectl

  • WHEN execute_logql_query runs with {namespace="devops"}, no loki.url setting and a fake HTTP client that records each request.
  • THEN The result has source k8s_fallback, and the fake records no request.

Requirement: Grades command stops before the request

devops roadmap eval grades MUST stop before a Loki request with an error that names loki.url when no URL is configured.

Scenario: Grades with no URL

  • WHEN loki.url is unset and devops roadmap eval grades --window 24h runs with no --loki-url and a fake HTTP client that records each request.
  • THEN The command exits with a non-zero code, its output contains loki.url, and the fake records no request.

Existing Tool Considered

The alternatives check of 2026-11-23 in the issue body returned none with Tool: none found; the block and its comment list what no tool covers. No open, maintained tool or library covers this need. The change edits the project's own resolve_loki_url, removes DEFAULT_LOKI_URL and keeps the kubectl fallback of execute_logql_query. The cost is about 30 changed lines in src/devops_cli/k8s/logql.py and one constant, under one hour to build, keep and fix.

Key questions

  • How should resolve_loki_url behave when neither the option nor loki.url is set?: It MUST raise KubernetesLoggingError with a message that names loki.url, and it MUST NOT return a localhost default. (best practice) [sources: src/devops_cli/k8s/logql.py:443, src/devops_cli/config/defaults.py:304, src/devops_cli/commands/roadmap_eval_grades.py:75]
  • Should DEFAULT_LOKI_URL remain as a default in execute_loki_query?: No. The change MUST remove the constant and MUST require an explicit loki_url on execute_loki_query. (best practice) [sources: src/devops_cli/config/defaults.py:304, src/devops_cli/k8s/logql.py:325]
    • Chosen: Remove the constant and require the argument. No service client keeps an unconfigured localhost default, and each caller resolves the URL once.
    • Rejected: Keep the constant for tests only. A test-only default can leak into a production path and keeps the fallback.
  • Should execute_logql_query and plan_k8s_logs also require loki.url?: No. execute_logql_query SHALL skip the Loki request and use its kubectl fallback when no URL is set. plan_k8s_logs keeps its current behavior through that entrypoint. (best practice) [sources: src/devops_cli/k8s/logql.py, src/devops_cli/k8s/cluster_plans.py:112, tests/ai/mcp/test_k8s_logql.py:272]
    • Chosen: Keep the kubectl fallback when no URL is set. The fallback works with no configuration, and tests/ai/mcp/test_k8s_logql.py:272 proves it.
    • Rejected: Raise KubernetesLoggingError in execute_logql_query. It removes a working fallback and breaks plan_k8s_logs on a host with no loki.url.
  • Should the grades report build its LogQL selector from settings?: No. origin/main already replaced _SELECTOR with RESULT_LINE_SELECTOR, and ServiceConfig has no namespace or app-label field. The change drops this part. (best practice) [sources: src/devops_cli/roadmap/job_grade_report.py:122, openspec/specs/roadmap-job-grades/spec.md:70, src/devops_cli/config/settings.py:1811]
  • Should the grades command open a port-forward when no loki.url is set?: No. It SHALL stop before a request with an error that names loki.url. (best practice) [sources: src/devops_cli/commands/roadmap_eval_grades.py, AGENTS.md]
    • Chosen: Stop with an error that names loki.url. The issue allows it, and it adds no process lifecycle to the command.
    • Rejected: Open a port-forward. It adds a lifecycle, and the alternatives check found no maintained tool for it.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 13, 2026
  2. added
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/low
    on Nov 13, 2026
  3. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 13, 2026
  5. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    Related defect found in the spec split (2026-11-13)

    _SELECTOR in src/devops_cli/roadmap/job_grade_report.py (line 88 on main) hard-codes the deployment:

    _SELECTOR: Final = '{namespace="devops", app_kubernetes_io_name="roadmap-service"}'

    So devops roadmap eval grades reads only one deployment of the roadmap Service. Read the namespace and the app label from settings, as this item reads the Loki URL from loki.url. Fix both in the same change, because both are about where the grades come from.

  6. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Searches for a Python Loki/LogQL client and for a programmatic port-forward library returned no relevant tool or library, only unrelated documentation pages. The need is an internal change to the project's own resolve_loki_url (drop DEFAULT_LOKI_URL) and to the hard-coded _SELECTOR in job_grade_report.py, which no external tool can cover.

    Tool: none found

    Lacks:

    • No tool resolves the Loki address from loki.url alone and fails before a request when it is unset
    • No tool opens the cluster port-forward for the roadmap eval grades command
    • No tool replaces the hard-coded namespace and app label _SELECTOR with settings
    • Grafana Loki itself is the server the command queries, not a client that fixes the fallback

    Searches run:

    • python client library Grafana Loki LogQL query API, results: 5
    • python library open kubectl port-forward programmatically, results: 5
    • logcli Grafana Loki command line query tool, results: 5
    • github "loki" python client logql query library pypi, results: 5
    • pypi package loki logql client python requests, results: 5
    • grafana loki github repository logcli, results: 5

    Sources:

    Checked on 2026-11-17. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    status/ready
    and removed
    status/new
    on Nov 18, 2026
  8. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 2b7f32c (see proposed design in issue body).

  9. dan-petty commented on Nov 25, 2026

    @dan-petty
    OwnerAuthor

    Return to New: selector requirement conflicts with #5556

    This item cannot be implemented as written because the main branch supersedes its design:

    1. Contradicts the Job-pod selector of fix(roadmap): eval grades counts the result lines of Job pods #5556: The Selector from settings requirement expects {namespace="team-a", app_kubernetes_io_name="roadmap-service-canary"} from Service settings, and Key Questions keeps both changes together because the report hard-codes app_kubernetes_io_name="roadmap-service". On origin/main, commit 1eb3ea4ff (fix(roadmap): eval grades counts the result lines of Job pods #5556 / PR fix(roadmap): eval grades counts the result lines of Job pods #5569) replaced _SELECTOR with RESULT_LINE_SELECTOR: Final = '{namespace="devops", container=~"service|stage|fix-plan"}' (src/devops_cli/roadmap/job_grade_report.py:122, openspec/specs/roadmap-job-grades/spec.md:70-83). It removed app_kubernetes_io_name because the Service, stage Job pods, and fix-plan Job pods use different app labels (tests/support/roadmap_job_grades.py:52,60,68,77).
    2. Missing settings and static dashboard contract: ServiceConfig (src/devops_cli/config/settings.py:1811) defines no namespace or app-label field, and tests/prometheus/test_k8s_monitoring_dashboards.py:147-165 enforces that every count query in roadmap-service-telemetry.json starts with the static RESULT_LINES string.
    3. Unaddressed fallback impact in execute_logql_query: Making resolve_loki_url raise KubernetesLoggingError when loki.url is unset affects execute_logql_query (src/devops_cli/k8s/logql.py:474,497-502), which catches ConnectionError and httpx2 timeouts to fall back to kubectl logs (tests/ai/mcp/test_k8s_logql.py:272-288), as well as plan_k8s_logs (src/devops_cli/k8s/cluster_plans.py:112).

    Returning #5481 to New so refinement can remove the obsolete Selector from settings requirement and specify whether execute_logql_query and plan_k8s_logs also require loki.url.

  10. added
    status/new
    and removed
    status/ready
    on Nov 25, 2026
  11. added
    status/ready
    and removed
    status/new
    on Nov 27, 2026
  12. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  13. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  14. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  15. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 16:50 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions