Skip to content

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

Open

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 workstation with no loki.url, devops roadmap eval grades uses DEFAULT_LOKI_URL (http://localhost:3100), sends a request, and fails with Connection refused. This violates the rule of #1165 that service clients use only configured URLs. The grades report also hard-codes the roadmap Service selector to namespace devops and app label roadmap-service, so it reads only one deployment. The fix removes the localhost fallback, stops before a request with an error that names loki.url, and builds the selector from settings.

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 loki.url is unset.
  • THEN It returns http://loki.example:3100.

Requirement: Configured Loki setting

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

Scenario: Setting supplies URL

  • WHEN resolve_loki_url receives no argument and loki.url is http://loki.team:3100.
  • THEN It returns http://loki.team:3100.

Requirement: Missing Loki URL

resolve_loki_url SHALL raise KubernetesLoggingError that names loki.url when neither the explicit argument nor the setting is set.

Scenario: No URL configured

  • WHEN resolve_loki_url receives no argument and loki.url is unset.
  • THEN It raises KubernetesLoggingError whose message contains loki.url, and no HTTP request is sent.

Requirement: No localhost default in query

execute_loki_query SHALL require an explicit loki_url and SHALL NOT use DEFAULT_LOKI_URL as a default.

Scenario: Direct query without URL

  • WHEN execute_loki_query is called without a loki_url argument.
  • THEN The call raises TypeError and no request to http://localhost:3100 is made.

Requirement: Remove fallback constant

The source SHALL NOT define or import DEFAULT_LOKI_URL after the change.

Scenario: Fallback constant is gone

  • WHEN The test searches src/devops_cli for DEFAULT_LOKI_URL.
  • THEN The search returns no match.

Requirement: Grades command fails early

devops roadmap eval grades SHALL 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.
  • THEN The command exits with an error that contains loki.url and sends no request to http://localhost:3100.

Requirement: Selector from settings

The grades report SHALL build its LogQL stream selector from the configured namespace and app label of the roadmap Service.

Scenario: Configured roadmap Service

  • WHEN The roadmap Service namespace setting is team-a and the app label setting is roadmap-service-canary.
  • THEN The selector is {namespace="team-a", app_kubernetes_io_name="roadmap-service-canary"}.

Existing Tool Considered

The alternatives check of 2026-11-17 in the issue body returned none with Tool: none found. No open, maintained tool or library covers this need. The change edits the project's own resolve_loki_url, removes DEFAULT_LOKI_URL, and reads the selector from settings. This is not a new tool, so it has no separate build cost.

Key questions

  • How should resolve_loki_url behave when neither the option nor loki.url is set?: It SHALL stop before any request with KubernetesLoggingError that names loki.url; it SHALL NOT use DEFAULT_LOKI_URL. (best practice) [sources: src/devops_cli/k8s/logql.py:414, src/devops_cli/config/defaults.py:290]
  • Should DEFAULT_LOKI_URL remain as a default in execute_loki_query?: No. Remove the constant and its imports, and make execute_loki_query require an explicit loki_url. (best practice) [sources: src/devops_cli/config/defaults.py:290, src/devops_cli/k8s/logql.py:19, src/devops_cli/k8s/logql.py:324, src/devops_cli/k8s/logql.py:421]
    • Chosen: Remove DEFAULT_LOKI_URL and require an explicit URL. No service client may use an unconfigured localhost default.
    • Rejected: Keep the constant for tests only. A test-only default can leak into production paths and keeps the fallback.
  • Where should the grades report get the namespace and app label for its selector?: From the roadmap Service settings, with the current values as defaults if the settings are absent. (best practice) [sources: src/devops_cli/roadmap/job_grade_report.py:88, src/devops_cli/commands/roadmap_eval_grades.py:75]
    • Chosen: Read the namespace and app label from settings. The reply asks for it, and the hard-coded selector reads only one deployment.
    • Rejected: Keep _SELECTOR hard-coded. It ignores other deployments and contradicts the reply.
  • Should the selector fix be in the same change as the Loki URL fix?: Yes. Fix both in one change because both control where the grades come from. (best practice) [sources: src/devops_cli/roadmap/job_grade_report.py:88, src/devops_cli/commands/roadmap_eval_grades.py:75]
    • Chosen: Fix both in one change. The reply says both are about where the grades come from.
    • Rejected: Split the selector fix into another issue. It is a small change in the same command path, and the reply asks for one change.

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
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/agentstatus/newtype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions