Skip to content

Add context-aware requests and configurable timeout - #27

Merged
andreagrandi merged 1 commit into
masterfrom
context-aware-requests
May 21, 2026
Merged

Add context-aware requests and configurable timeout#27
andreagrandi merged 1 commit into
masterfrom
context-aware-requests

Conversation

@andreagrandi

@andreagrandi andreagrandi commented May 21, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #11.

Threads context.Context through the Metabase client and CLI so HTTP
requests can be cancelled and time-bounded consistently, as requested in
issue #11.

  • Client request methods accept a context and build requests with
    http.NewRequestWithContext; Do reports clear request timed out /
    request canceled errors while still wrapping context.DeadlineExceeded
    and context.Canceled for programmatic detection.
  • The root context is cancelled on SIGINT/SIGTERM via signal.NotifyContext,
    so commands abort cleanly on Ctrl+C.
  • New --timeout flag (duration, default 30s, 0 disables) bounds each
    command's API requests, replacing the fixed http.Client timeout.
  • Timeout and cancellation errors are classified as TIMEOUT_ERROR /
    CANCELED_ERROR for --error-format json.

Existing command output and PII redaction behavior are unchanged.

Changelog

  • Added an entry under ## [Unreleased] in CHANGELOG.md
  • No changelog entry needed

Test plan

  • make fmt, make vet, make test, make build all pass.
  • New tests/request_context_test.go covers Get/Post cancellation, Get
    timeout, context propagation through a high-level client method, and an
    end-to-end --timeout CLI test; error-classification tests cover the new
    error types.
  • Smoke-tested against a real Metabase instance: database/table/field/card/
    dashboard/query/search commands return expected output.
  • --timeout 1ms produces a structured TIMEOUT_ERROR.
  • Verified Ctrl+C aborts an in-flight SELECT pg_sleep(10) with
    request canceled: ... context canceled and a non-zero exit.

Thread context.Context through the Metabase client and CLI so HTTP
requests can be cancelled and time-bounded consistently.

- Client request methods accept a context and build requests with
  http.NewRequestWithContext; report clear timeout/cancellation errors.
- Root context is cancelled on SIGINT/SIGTERM so commands abort on Ctrl+C.
- New --timeout flag (default 30s, 0 disables) bounds each command's
  API requests.
- Classify timeout and cancellation errors for --error-format json.

Closes #11
@andreagrandi
andreagrandi merged commit 708127c into master May 21, 2026
7 checks passed
@andreagrandi
andreagrandi deleted the context-aware-requests branch May 21, 2026 05: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.

Add context-aware requests and configurable timeout

1 participant