Skip to content

chore: pre-release gap fixes#33

Merged
zakame merged 6 commits intomasterfrom
chore/prerelease
Mar 16, 2026
Merged

chore: pre-release gap fixes#33
zakame merged 6 commits intomasterfrom
chore/prerelease

Conversation

@zakame
Copy link
Owner

@zakame zakame commented Mar 13, 2026

Summary

Pre-release audit and gap fixes identified by a full team review (Copilot baseline audit, Tester adversarial review, Language Lawyer, Program Clerk, Editor, Toolsmith).

Changes

refactor

  • Extend SpeedtestClient interface to context-aware fetch methods (FetchServerByIDContext, FetchServerListContext) so cancellation and deadlines propagate into server-fetch HTTP requests, not just the test phase
  • Defer s.Context.Reset() so DataManager snapshot state is always cleared on any return path, preventing stale data bleeding into the next scrape cycle
  • Add defensive len(targets) == 0 guard after FindServer

fix

  • Guard against (nil, nil) return from Runner — previously panicked in Collect; now emits zeroed metrics with speedtest_up=0
  • Distinguish context.DeadlineExceeded from other errors in log output: "Speedtest timed out" vs "Speedtest failed"

test

  • 14 new tests: context cancellation/deadline propagation through fetch methods, context identity forwarding, error-path log branching, nil-result guard, registration side-effect
  • Merge registerer_test.go into collector_test.go (orphan filename — no matching source file); delete registerer_test.go
  • Assert DefaultCollectTimeout is wired into the collector registered by NewSpeedtestRunner
  • Assert "Speedtest returned no result" is logged on (nil, nil) runner return
  • Fix stale doc comments in runner_test.go referencing old method names (FetchServerByIDFetchServerByIDContext, FetchServersFetchServerListContext)
  • Remove stale "RED test" annotation from nil-result test (guard is implemented)

docs

  • Fix Go version requirement: 1.25 → 1.26
  • Fix SPEEDTEST_EXPORTER_DEBUG default (any non-empty string, not false)
  • Add metric units, no-labels note, and verbatim Prometheus exposition example to README

build

  • Add Makefile with build, test, cover, lint, vet, fmt, run, clean, help targets
  • Bump go directive from 1.25 → 1.26 for security fixes in net/url, crypto/tls, html/template, os

ci

  • Bump golangci-lint from v2.5.0 → v2.11.3; v2.5.0 was built with Go 1.25 and hard-rejects modules targeting Go 1.26

zakame added 6 commits March 14, 2026 03:20
Replace FetchServerByID/FetchServers with FetchServerByIDContext/
FetchServerListContext so the caller's context deadline and cancellation
propagates into server-fetch HTTP requests, not just the
ping/download/upload test phase.

Also add a defensive len(targets)==0 guard after FindServer, and defer
s.Context.Reset() so DataManager snapshot state is always cleared on
any return path (error or cancellation), preventing stale data bleeding
into the next Run cycle.

Update MockSpeedtestClient and all mock.On() call sites to match the
new interface signatures.
Add a nil-result guard in Collect so a (nil, nil) return from Runner
no longer panics at the field access on line 89; emit zeroed metrics
with speedtest_up=0 instead.

Distinguish context.DeadlineExceeded from other errors in log output
('Speedtest timed out' vs 'Speedtest failed') to help operators tell
a collection timeout apart from a network failure.
Add 14 new tests across runner_test.go and collector_test.go:

runner_test.go (8 tests):
- ContextCancelledBefore/DeadlineBefore FetchServerByID and FetchServers:
  verify cancellation and timeout propagate end-to-end through the new
  context-aware interface methods
- ContextForwardedTo FetchServerByID and FetchServers: assert the exact
  context identity is forwarded, not a detached background context

collector_test.go (6 tests):
- DeadlineExceededLogsTimedOut, WrappedDeadlineExceededLogsTimedOut:
  verify the new errors.Is branch fires for direct and wrapped deadlines
- NonDeadlineErrorLogsFailed: verify non-deadline errors still log 'failed'
- BothResultAndErrorTakesErrorPath: (result, err) both non-nil takes error path
- ContextHasDeadline: Collect creates a deadline-bearing context before Run
- NilResultNilErrorDoesNotPanic: (nil, nil) from runner emits zeroed metrics

Also merge registerer_test.go into collector_test.go since
RegisterSpeedtestCollector lives in collector.go; delete the orphan file.
- Fix SPEEDTEST_EXPORTER_DEBUG default: any non-empty string enables it
  (not a boolean false), matching the os.Getenv(...) != "" check in main.go
- Add Unit column to metrics table (milliseconds / bits per second / dimensionless)
- Document that no labels are present on any metric
- Add verbatim example Prometheus exposition output
- Name the debug collectors explicitly (go_* and process_*)
Add Makefile with targets: build, test, lint (golangci-lint with go vet
fallback), run (respects SPEEDTEST_PORT/SPEEDTEST_SERVER/
SPEEDTEST_EXPORTER_DEBUG), clean, and help (default goal).

Bump go directive from 1.25 to 1.26 to pick up security fixes in
net/url, crypto/tls, html/template, and os included in the 1.26 line.
The installed toolchain (go1.26.1) already satisfies this requirement.
v2.5.0 was built with Go 1.25 and refuses to lint modules targeting
Go 1.26, causing the lint job to exit with code 3. v2.11.3 is the
latest release and supports Go 1.26.
@zakame zakame force-pushed the chore/prerelease branch from 240c240 to 97e36d1 Compare March 13, 2026 20:44
@zakame zakame merged commit c44972b into master Mar 16, 2026
2 checks passed
@zakame zakame deleted the chore/prerelease branch March 16, 2026 16:18
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.

1 participant