Skip to content

bug: Validate CODER_URL scheme at startup and add observability for failed requests #146

@uzair-coder07

Description

@uzair-coder07

Reported by customer on ticket 4838

Problem

When CODER_URL is configured without a scheme (e.g., new-coder.svc.cluster.local instead of https://new-coder.svc.cluster.local/), the application starts successfully but fails silently at runtime with:

post log source resource_name=coder-xxx error="Post \"/api/v2/workspaceagents/me/log-source\": unsupported protocol scheme \"\""

The pod reports as Ready: True in Kubernetes despite being unable to communicate with Coder.

Probable Cause

Go's url.Parse() is lenient and successfully parses URLs without schemes, leaving parsedURL.Scheme empty. The current validation only checks for parse errors, not for valid schemes.

Suggested Improvements

1. Fail fast on invalid URL

Add scheme validation after parsing:

if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
    return fmt.Errorf("CODER_URL must include http:// or https:// scheme, got: %q", coderURL)
}

2. Add Prometheus metrics

Expose metrics for failed API requests so operators can monitor and alert on issues:

  • coder_logstream_requests_total{status="success|failure"}
  • coder_logstream_errors_total{type="auth|network|parse"}

Impact

Operators cannot easily detect misconfigurations since the pod appears healthy. This leads to silent failures where workspace startup logs are not streamed.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions