Skip to content

feat: compute telemetry statistics instead of regex search - #54

Merged
MikolajKos merged 17 commits into
mainfrom
feat/telemetry-stats
Nov 27, 2026
Merged

MikolajKos merged 17 commits into
mainfrom
feat/telemetry-stats

Conversation

@MikolajKos

Copy link
Copy Markdown
Owner

Summary

LogGrid now computes count, sum, min, max and mean of the value column of telemetry CSV files (id,timestamp,channel,value) instead of searching lines with a regex, as decided in the January plan.

Changes

  • Worker: TelemetryParser turns a CSV line into a fixed-point value (value × 10¹⁰, int64_t) without going through floating point; FileProcessor::ProcessChunk computes the stats of a chunk; chunk boundary handling is unchanged.
  • Common: TelemetryStats with Add, AddError and Merge, overflow detection with __builtin_add_overflow; ChunkResult holds ids and stats and is sent whole; kValueScaleDigits and kValueScale defined once.
  • Master: the session keeps TelemetryStats; TaskDone drops results whose task is not in flight and calls Merge. Keyword, max_results and writing matched lines to a file are removed, so dispatch and recovery code no longer depends on the result fields.
  • API: POST /api/search takes path (and outputDir); GET /api/status/{id} returns a stats object.
  • Docs: README, January plan and known issues updated.

Testing

  • 85 tests pass (unit and integration), including a FileProcessor test that splits a file at every byte and master tests for merged, duplicate and reassigned chunk stats.
  • ch60.csv (637 MB, 14,639,410 lines, 122 chunks) on a laptop with WSL2: every run gave the same sum, count equal to the line count, 0 errors. About 0.4 s without a CPU limit, about 3.0 s with 2 workers × 2 CPU.
  • Worker: TelemetryParser turns a CSV line into a fixed-point value (value × 10¹⁰, int64_t) without going through floating point; FileProcessor::ProcessChunk computes the stats of a chunk; chunk boundary handling is unchanged.
  • Common: TelemetryStats with Add, AddError and Merge, overflow detection with __builtin_add_overflow; ChunkResult holds ids and stats and is sent whole; kValueScaleDigits and kValueScale defined once.
  • Master: the session keeps TelemetryStats; TaskDone drops results whose task is not in flight and calls Merge. Keyword, max_results and writing matched lines to a file are removed, so dispatch and recovery code no longer depends on the result fields.
  • API: POST /api/search takes path (and outputDir); GET /api/status/{id} returns a stats object.
  • Docs: README, January plan and known issues updated.

Testing

  • 85 tests pass (unit and integration), including a FileProcessor test that splits a file at every byte and master tests for merged, duplicate and reassigned chunk stats.
  • ch60.csv (637 MB, 14,639,410 lines, 122 chunks) on a laptop with WSL2: every run gave the same sum, count equal to the line count, 0 errors. About 0.4 s without a CPU limit, about 3.0 s with 2 workers × 2 CPU.

Known limitations

See KNOWN_ISSUES.md: a chunk whose file the worker cannot open is merged as empty, a too short TaskDone blocks the session, the sum overflows above about 87 copies of channel 60 in one session, and bench/kill_worker.py does not work with the statistics API yet.

Parse integer and fraction parts with unsigned from_chars, pad the
fraction to scaleDigits, and reject values that would exceed INT64_MAX
before multiplying. Negative range is symmetric; INT64_MIN is not
supported.
Cover valid values, overflow boundaries, invalid formats, scaleDigits
range, GetField and ParseLine. The sample line used by the ParseLine
tests is written by hand, not taken from the dataset.

Document what each parser function accepts and rejects.
TelemetryStats keeps count, errors, sum, min, max and an overflow flag. Add() takes one value, AddError() counts a rejected line, Merge() combines two results. Sums use __builtin_add_overflow; on overflow only the flag is set, other fields stay valid. ChunkResult now holds ids and stats only, so it can be sent with msg << batch.
FileProcessor::ProcessChunk parses each line with TelemetryParser and updates the chunk stats; chunk boundary handling is unchanged. SendTaskDone sends ChunkResult as a whole, SerializeBatch is removed. Master and tests still use the old ChunkResult fields, so the build is broken until they are updated.
…e status API

The session keeps TelemetryStats; on TaskDone the master reads the whole ChunkResult, drops results whose task_id is not in flight, and calls Merge. Keyword, max_results and writing matched lines to a file are removed, so the dispatch and recovery code no longer knows the result fields. GET /api/status returns a stats object with count, errors, sum, min, max, mean, scale and overflow; sum, min and max stay scaled integers. Tests still use the old API and do not build yet.
Describe the engine/computation coupling and the accumulator decision, close items made obsolete by removing regex search, and add issues for failed chunks, min/max with count 0 and the benchmark script.
FakeWorker and TestServer send and read the whole ChunkResult, master tests call StartSearch without a keyword, worker and FileProcessor tests check stats instead of matched lines, with a split at every byte to check that each line is counted once. Add parametrized TelemetryStats::Add tests. Also fix the Pow10 call in SearchController.
Check that AddError counts only errors, that overflow above and below sets the flag without stopping count, and that Merge combines results, keeps values when merging an empty result, carries the overflow flag and detects overflow of the merged sum.
FakeWorker sends the given stats in TaskDone. New master tests check that stats from two chunks are merged, that a duplicate TaskDone does not change them and that a reassigned chunk is counted once. StatsToJson leaves out sum after an overflow; README documents this and the 64-bit integers in the JSON.
kValueScale is computed at compile time next to kValueScaleDigits, with a static_assert that it fits in int64_t. SearchController uses it instead of its own Pow10, FileProcessor checks that the parser's power table gives the same scale, and the unused SendFoundLine declaration is removed.
@MikolajKos
MikolajKos merged commit ebe9e56 into main Nov 27, 2026
4 checks passed
@MikolajKos
MikolajKos deleted the feat/telemetry-stats branch November 27, 2026 14:43
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