Skip to content

feat: add server-side batching, -once/-stdin input modes, and optimized schema#30

Merged
peterborodatyy merged 18 commits into
masterfrom
feat/server-side-batching
Mar 29, 2026
Merged

feat: add server-side batching, -once/-stdin input modes, and optimized schema#30
peterborodatyy merged 18 commits into
masterfrom
feat/server-side-batching

Conversation

@peterborodatyy

@peterborodatyy peterborodatyy commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add use_server_side_batching config toggle that enables ClickHouse async inserts (async_insert=1, wait_for_async_insert=1) per-query via the idiomatic clickhouse-go/v2 WithSettings API, preserving at-least-once
    delivery
  • Add -once flag to read a log file from start to EOF and exit (bulk loading)
  • Add -stdin flag to read log lines from standard input with streaming support (pipes, journald, etc.)
  • Replace basic ClickHouse schema in README with production-optimized version using compression codecs (Delta/ZSTD), LowCardinality, IPv4, monthly partitioning, and 180-day TTL

Test plan

  • go test ./... -race — 78 unit tests pass
  • make test-integration — 12 integration tests against ClickHouse (including async insert round-trip)
  • make test-e2e — 4 binary-level tests: -once inserts rows, -stdin inserts rows, -check passes, -check fails on bad config
  • gofmt -l . and go vet ./... clean
  • CI passes (lint + unit + integration + e2e)

peterborodatyy and others added 17 commits March 24, 2026 00:24
Add use_server_side_batching toggle to ClickHouseConfig. When enabled,
sets async_insert=1 and wait_for_async_insert=1 on the PrepareBatch
context using the idiomatic clickhouse-go/v2 WithSettings API, preserving
at-least-once delivery guarantees. Logs a warning if disk buffer is also
enabled since ClickHouse handles durability via async inserts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add feature bullet, env var, config example, and Reliability subsection
explaining async insert behavior and interaction with disk buffer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Verify Save() with UseServerSideBatching=true inserts rows correctly
via ClickHouse async inserts (async_insert=1, wait_for_async_insert=1).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add async inserts to project overview, architecture, and config sections.
Correct test counts to reflect current state across all packages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add optimized CREATE TABLE with Delta/ZSTD codecs, LowCardinality for
enrichment columns, IPv4 native type, monthly partitioning, 180-day TTL,
codec rationale table, and ALTER TABLE migration from basic schema.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove basic schema and migration SQL. Keep one schema with codecs,
partitioning, TTL, and rationale table.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add -once flag to read a log file from start to EOF and exit, and -stdin
flag to read log lines from standard input (supports both pipes and
streaming). Both modes reuse the existing buffer/flush pipeline.

Extract line source abstraction (scanLines, openLineSource) so all three
modes (tail, once, stdin) feed lines into the same processing loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Go's flag package uses single dash by convention. Replace --check with
-check for consistency with -once, -stdin, -config_path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Build the binary, run it with each flag against a real ClickHouse,
and verify results. Tests cover:
- -once: reads file, inserts 3 rows, exits
- -stdin: reads piped input, inserts 3 rows, exits
- -check: validates config, expects success
- -check with bad config: expects failure

Also update CI workflow and Makefile to run root integration tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Rename integration_test.go to e2e_test.go with build tag "e2e".
Integration tests (clickhouse/) test the Go API directly.
E2e tests (root) build the binary and test flags end-to-end.

Add make test-e2e target and separate CI step.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Increase bufio.Scanner max line size to 1MB (default 64KB truncates
  long URLs/user agents)
- Guard shutdown with sync.Once to prevent race between signal handler
  and EOF-triggered shutdown
- Use strings.Contains instead of bytes.Contains in e2e test

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@peterborodatyy peterborodatyy changed the title Feat/server side batching feat: add server-side batching, -once/-stdin input modes, and optimized schema Mar 29, 2026
Replace inline commands with make lint, make test, make test-integration,
and make test-e2e. Align Makefile lint target with CI (fail on unformatted
files instead of just listing them).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@peterborodatyy
peterborodatyy merged commit daf19a7 into master Mar 29, 2026
4 checks passed
@peterborodatyy
peterborodatyy deleted the feat/server-side-batching branch March 29, 2026 11:24
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