Skip to content

fix: preserve unavailable observations as gaps in stored trends - #87

Open
DivyamTalwar wants to merge 1 commit into
pgrundev:mainfrom
DivyamTalwar:fix/preserve-scalar-observation-gaps
Open

DivyamTalwar wants to merge 1 commit into
pgrundev:mainfrom
DivyamTalwar:fix/preserve-scalar-observation-gaps

Conversation

@DivyamTalwar

Copy link
Copy Markdown
Contributor

What and why

Closes #86.

Keep unavailable table/activity measurements out of scalar trend columns and retain explicitly observed zero connection counts. Preserve the independently measured positive connection gauge when a counter reset invalidates rates, rather than discarding the whole Health section.

The regression drives actual Save, Trend, SQLite reopen and Context JSON round trips. It also covers legacy metadata and the reset/gauge boundary used by #73. No existing historical rows are rewritten.

Verification

Verified commit: b866ab08a0281b5213b545207c3c4c8601d25cb4.

  • New real-store regressions fail on base 282ffe8fdd7acdd7b6e1dbd8cf04c155401d3a92: extra zeros from unavailable sections and missing measured-zero connections.
  • go test -race ./internal/store -run TestSaveTrendPreservesScalarAvailabilityAcrossReopen -count=20: passed.
  • go test -race ./internal/store ./internal/collect ./internal/why ./cmd/pgbot: passed.
  • bash scripts/gate.sh: passed on committed HEAD, including pinned lint, unit tests and all six release-target builds.
  • go test -race ./...: passed; formatting and git diff --check clean.
  • Byte-for-byte saved Context JSON and section provenance remain unchanged after reopen.

Scope and risk

This affects scalar columns extracted for newly saved observations only. It does not repair already-stored false zeros, change retention, introduce migrations or alter the model JSON contract. Tests use real SQLite and synthetic collector contexts; no live PostgreSQL failure is claimed. Positive current connection gauges remain usable even when sampled rates are unavailable. Revert this commit to restore the old extraction rules.

Checklist

  • Committed-HEAD gate and full race suite pass.
  • Read-only, privacy and deterministic-finding invariants preserved.
  • No new finding or model JSON field; catalog/schema unchanged.

Unavailable table/activity sections have zero-valued numeric fields, which
were persisted as measured trend values. Conversely, an observed zero
connection count was discarded. Preserve missing observations as NULL and
store actual zeros only with availability metadata.

A counter reset may invalidate rates while preserving a positive current
connection gauge, so keep that gauge independently. Leave unknown legacy
zero connections as gaps and preserve positive legacy observations.

Regression tests drive Save, Trend, SQLite reopen and serialized Context
round trips. They fail on 282ffe8 and pass 20 race-enabled repetitions;
full store, collector, why and CLI race tests pass with real dependencies.
No schema migration, historical rewrite, collector SQL or JSON changes.
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.

Failed collection creates false zero-valued trend observations

1 participant