Skip to content

fix(traffic): Store request times in a format SQLite can read #173

Description

@nfebe

Request times are written to traffic_logs.created_at as Go's own rendering of a time.Time (internal/traffic/db.go:76 binds the value straight through), which produces 2026-07-15 19:07:56.357597184 +0100 WAT m=+0.002158540, monotonic clock reading and all. SQLite cannot parse that, so strftime('%s', created_at) returns NULL and any date arithmetic on the column silently yields nothing rather than failing loudly. The column is declared DATETIME (internal/traffic/db.go:50), so this is not the format anything reading the schema would expect.

The existing filters survive only because both sides of a comparison are rendered the same way and the leading wall clock sorts correctly: GetLogs and GetStats compare text, not time. The offset suffix takes no part in that, so times either side of an offset change compare by wall clock rather than by instant, and no query can bucket, extract or convert the column at all.

Constraint: the storage format and the queries that compare against it have to change together. Both sides currently render through the same driver path, so correcting one alone breaks the comparison that works today.

Checklist

  • Store request times as UTC in a format SQLite's date functions parse.
  • Bind the same format in every query that compares created_at.
  • Migrate existing rows, which are in the old format and will not compare against the new one.
  • Confirm retention cleanup still drops what it should once the format changes.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions