Skip to content

test(integration): Loki push ingestion conformance (M8, #924) - #1118

Open
Guess-Who-sec wants to merge 11 commits into
metrico:masterfrom
Guess-Who-sec:test/m8-ingest-loki-push
Open

Guess-Who-sec wants to merge 11 commits into
metrico:masterfrom
Guess-Who-sec:test/m8-ingest-loki-push

Conversation

@Guess-Who-sec

@Guess-Who-sec Guess-Who-sec commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Part of #924 (M8): ingestion conformance, the first protocol, Loki push, as you suggested on #924 (one protocol per PR, Loki push and Prometheus remote-write first).

Depends on #1063 (M2 4/4), which builds on #1062 and #1061: this branch is built on the whole M2 stack, so its first 10 commits are theirs (#1061: 4, #1062: 3, #1063: 3). It uses the seed from #1061 and #1062, and #1063's ClickHouse ports and clickhouseQuery helper. Merge those first; I'll rebase this one onto master then. Only the last commit is new here.

What it does

The M2 round trips check that what goes in comes back out through the query API. This test checks the other end: what a Loki client sends is checked where gigapipe stores it, by reading the rows from ClickHouse. When the storage changes underneath (the samples table split in #972, or the writer refactor in M8), a case fails if any of these change:

  • which tables get rows
  • the fingerprint
  • the labels
  • the timestamps
  • the line text
  • the sample type

TestLokiPushConformance in test/integration/ingest_loki_push_test.go runs in the existing integration lane (build tag integration). Every expected value is what gigapipe stores today, measured on a real stack.

Case What is sent What is checked in ClickHouse
seed as JSON the M2 seed (4 streams, 17 lines), application/json time_series: one row per stream and day, exact labels JSON (service_name added from app), type 1, empty name and metadata. samples_v3: one row per line with the stream's fingerprint, exact nanosecond timestamp and text, value 0, type 1. time_series_gin: one row per label. metrics_15s: line count and bytes per stream. Fingerprints differ between streams.
seed as protobuf the same streams, snappy-compressed protobuf, as Promtail and Alloy send them same as the JSON case
pinned fingerprint one fixed stream, once as JSON and once as protobuf both lines stored under the pinned fingerprint 18270485951633840138 (default CityHash). This covers the whole path: label cleanup, the added service_name, and the hash. Its lines have sub-second timestamps; the seed's are whole seconds.
label order one stream sent twice with its labels in different orders one fingerprint
service_name streams with app; with service_name already set; with neither checkout; kept as shop; unknown
label names k8s.pod-name (dots and dashes, as in Kubernetes or OpenTelemetry-style names) stored as k8s_pod_name
long label values a 125-character URL stored as its first 100 characters plus ...
structured metadata a JSON line [ts, line, {"trace_id": …}] line stored, metadata not stored as labels
two days one stream, lines 24 hours apart two time_series rows (one per date), same fingerprint
old push format labels string plus entries with an RFC 3339 timestamp labels and exact nanosecond timestamp

Other changes:

Questions for you

  1. service_name with several candidate labels: gigapipe takes the last candidate in the order the labels arrive. Measured: {job="batch", container="worker"} gets service_name="worker". So for a client that sends labels sorted by name, the alphabetically last candidate wins. I didn't pin this case. Is that intended?
  2. Label values over 100 characters are stored cut to 100 characters plus ..., so two values that differ only after character 100 become the same label. The test pins today's behaviour. Is that intended?
  3. You suggested splitting ingestion conformance into its own issue. Should I open one for the protocol PRs to link to, or keep linking them to M8 — Writer/lifecycle refactor + ingestion conformance + stack layer #924?

Noticed while writing the test, for #972: time_series is a ReplacingMergeTree(date) ordered by (fingerprint, type). On this table, SELECT … FINAL keeps only the newest day's row of a stream: measured, two rows on disk and one with FINAL. The test reads without FINAL so it sees what's stored.

Verification

After rebasing onto the updated M2 stack and current master (ClickHouse 26.10): master's #1122 made the line field of gigapipe's Loki protobuf types bytes, so seed.LokiPushProto now writes the line as bytes (same wire format). Checked: the protobuf body sent to a real Loki 3.7.10 was stored exactly (19 lines, sub-second timestamps and a non-ASCII line); the whole integration suite passes on a fresh stack via run.sh (23 tests, all 10 conformance subtests) and the way the CI lane runs it; with #1122's new decoder, the planted "protobuf drops nanoseconds" and "protobuf lines stored as metric type" changes still fail only the cases meant to catch them; gofmt, go vet (no new findings), the build, go test ./..., golangci-lint and staticcheck are clean.

Earlier results, before the rebase:

  • Real runs (Docker: ClickHouse 24.9.1 + gigapipe built from this tree):

  • Planted changes, each rebuilt and run, then reverted. Each one failed only the case meant to catch it:

    Planted change Cases that failed
    label cleanup keeps . only label names
    protobuf drops the sub-second part of timestamps only pinned fingerprint
    values cut at 200 instead of 100 only long label values
    protobuf lines stored with the metric type only seed as protobuf and pinned fingerprint
  • Mistakes in my own test, found and fixed while writing it:

    • I first read with FINAL, which hid the second day (see above).
    • I first read time_series as soon as the samples had arrived. gigapipe writes the two separately, so the test now waits for both.
    • The pinned case first checked every time_series row of its fixed stream, including rows left by earlier runs on the same database. Reproduced: a run with a planted bug (JSON lines stored with the metric type) left a type-2 row, and the next run with correct gigapipe then failed. It now checks only the log-type row; the samples check covers this run's type. On that same database the fixed test passed 3 of 3, and the two planted changes aimed at this case still fail it. In CI each run starts with a fresh database, so CI never hit this.
  • gofmt; go vet (no new findings compared with the base) and with -tags integration and integration,integration_cluster; CGO_ENABLED=0 go build; root go test ./... (37 packages); -race on the seed package; make lint as CI runs it, and golangci-lint and staticcheck with both tag sets (0 issues)

Potential risks

metrico#920)

The integration workflow built, started and tested gigapipe with raw
commands. It now runs make build, make integration-start and
make test-integration, and test/integration/run.sh runs the same
make test-integration, so CI and local runs are the same commands.

integration-start waits up to 60s for /api/v1/status/buildinfo and prints
gigapipe.log if gigapipe never answers.
run.sh changed to the repository root before running the tests, but the
EXIT trap runs `docker compose -f docker-compose.yml` with a relative
path, so teardown failed (hidden by `|| true`) and left the gigapipe and
ClickHouse containers running after every run. Run the tests in a
subshell so the trap still runs from test/integration.
…/4, metrico#920)

Add test/integration/seed, a deterministic declaration of the data the
integration tests write: services and pods, from which every signal is
derived. Logs are generated with a fixed random seed, so the same fixture
always produces the same push body; Run only sets the m2_run label that
keeps one run's data apart from earlier runs.

TestLogsRoundTrip pushes the fixture through /loki/api/v1/push and checks
what the Loki read APIs return against it, one named case each: every line
per stream, a line filter, the json parser with a label filter,
count_over_time per pod, labels, label values and series.

The query_range, instant query, label values and series responses are also
compared with pinned copies under testdata/logs/, since that JSON is what
Grafana reads. Run-specific values (the run label, timestamps) are
normalized before the comparison. The pins are maintained by hand; there is
no regeneration mode.

gigapipe's labels endpoint ignores the query parameter Loki uses to narrow
it to a selector, so that case cannot be limited to one run; the series
case covers the label sets.
…ctly (M2 2/4, metrico#920)

Review of metrico#1061: the label values come from SELECT DISTINCT without
ORDER BY, so they are sorted before comparing. The pinned responses are
decoded strictly: an undeclared field or data after the response fails,
and log entries and vector samples must have exactly two elements.
gigapipe.log and gigapipe.pid, created by make integration-start, are
ignored.
…(M2 3/4, metrico#920)

Extend the seed with the other three signals, all derived from the same
declaration of services and pods:

- metrics: per pod, an http_requests_total counter growing by
  RequestsPerScrape at every 15s scrape and a process_resident_memory_bytes
  gauge, sent as a Prometheus remote-write request (snappy protobuf)
- traces: per checkout pod, a POST /checkout -> charge -> INSERT payments
  trace across both services, sent as OTLP/HTTP protobuf; trace IDs are
  derived from the run, so runs never share one
- profiles: per pod, three consecutive 10s CPU profiles uploaded to /ingest
  the way the Pyroscope Go SDK uploads them (multipart pprof, name
  "<app>{labels}")

TestMetricsRoundTrip, TestTracesRoundTrip and TestProfilesRoundTrip read
them back the way their clients do: the Prometheus query API; the Tempo API
as Grafana's Tempo data source uses it (trace by ID as protobuf, TraceQL
search, tag names and values); the Pyroscope Connect API as Grafana's
Pyroscope data source uses it, plus /pyroscope/render and
/pyroscope/render-diff. Every value is checked against the fixture, one
named case each.

Pinned responses under testdata/{metrics,traces,profiles} follow the same
rules as the logs pins: run-specific values normalized, maintained by hand.
The rate query is checked with a 1e-9 tolerance and not pinned, since its
last digits depend on the order the per-pod rates are added.

If data does not show up within 30s, the tests log it and still run every
named case, so a broken ingest path reports which answers are wrong.
…y (M2 3/4, metrico#920)

Review of metrico#1062: the flame graph pins (SelectMergeStacktraces, render,
render-diff) hold call stacks with their total and self values instead
of the raw names and levels arrays, whose order the query doesn't
define. The matrix, search and render responses are decoded strictly,
and matrix points must have exactly two elements.
metrico#920)

Several pinned values of the render responses are zero, empty or null
(leftTicks, rightTicks, spyName, timeline), so a missing key would
decode to the same value: every declared field is now required.
…/4, metrico#920)

TestSchemaMigrations runs gigapipe with MODE=init_only against a new
database and checks it holds every table and view the single-node scripts
in ctrl/qryn/sql declare (plus ver, where the migration runner records its
progress). A second run on the same database, as on restarting an existing
install, must succeed and change nothing.

TestRulerBootOrder starts gigapipe in all mode with the ruler enabled and
checks it from outside, as metrico#920 asks: GET /api/v1/rules answers (a ruler
started before the reader registers no routes, so the failure is a 404),
and a recording rule uploaded through that API writes back samples with
the expected values. Moving the ruler before the reader in bootSequence
makes both cases fail; restoring the order makes them pass.

Both start their own gigapipe process, each with a database of its own, so
docker-compose.yml now publishes ClickHouse's ports to the host and run.sh
builds the binary first. A process that exits because its port was taken
is restarted on another port.
…/4, metrico#920)

TestSchemaMigrationsCluster runs gigapipe's migrations with CLUSTER_NAME
set against a two-node ClickHouse cluster (test_cluster_two_shards) that
reuses the e2e stack's configuration. Every node must hold the objects of
the single-node and *_dist.sql scripts, plus ver and ver_dist, and a second
run must change nothing.

It has its own build tag (integration_cluster) and runs through
make test-integration-cluster, which starts the cluster, runs the test and
always stops the cluster. A new workflow runs it on the release cadence metrico#920
names (pushes to master, by hand) and on pull requests that change
ctrl/qryn or this lane.

The ClickHouse helpers can now target a given node, and declaredTables takes
the scripts to read, so the single-node and cluster checks share them.
…cluster (M2 4/4, metrico#920)

Review of metrico#1063: rerunning the migrations must leave every table's
create_table_query unchanged, on every node. The cluster lane runs the
e2e stack's two ClickHouse services with an override that only adds
ports on 127.0.0.1, healthchecks and CLICKHOUSE_SKIP_USER_SETUP, and
is torn down also when it fails to start. The integration stack
publishes ClickHouse's HTTP port on 127.0.0.1 for the tests that read
it, and the gigapipe processes the tests start listen on 127.0.0.1.
TestLokiPushConformance sends Loki pushes and checks the rows gigapipe
stores in ClickHouse: time_series, samples_v3, time_series_gin and
metrics_15s. Cases: the M2 seed as JSON and as snappy protobuf, a pinned
fingerprint shared by both formats, label order, service_name, label
name cleanup, values over 100 characters, structured metadata, lines on
two days, and the old labels/entries format. Expected values are what
gigapipe stores today, measured.

seed.LokiPushProto encodes streams the way Promtail sends them.
ClickHouse is read with the clickhouseQuery helper and ports from the
M2 lifecycle tests.
@Guess-Who-sec
Guess-Who-sec force-pushed the test/m8-ingest-loki-push branch from 450baca to 032ee2d Compare November 25, 2026 15:01
@Guess-Who-sec

Copy link
Copy Markdown
Contributor Author

Rebased onto the updated M2 stack and current master. One change: since #1122 the line field of gigapipe's Loki protobuf types is bytes, so seed.LokiPushProto now writes the line as bytes (same wire format; a real Loki still stores the body exactly). The suite passes on ClickHouse 26.10, and the planted protobuf bugs still fail the right cases with #1122's new decoder. Details in the description.

This branch has not been deployed

No deployments
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