Skip to content

test(integration): schema migration and ruler boot-order checks (M2 4/4, #920) - #1063

Open
Guess-Who-sec wants to merge 10 commits into
metrico:masterfrom
Guess-Who-sec:test/m2-lifecycle
Open

Guess-Who-sec wants to merge 10 commits into
metrico:masterfrom
Guess-Who-sec:test/m2-lifecycle

Conversation

@Guess-Who-sec

@Guess-Who-sec Guess-Who-sec commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Part of M2 (#920), PR 4 of 4. Epic: #917.

M2 is split into four PRs:

  1. test(writer): pin label fingerprint values (M2 1/4, #991) #1060: fingerprint value pins (Pin the label-fingerprint contract: three implementations, zero tests #991)
  2. test(integration): seed package and write-read harness for logs (M2 2/4, #920) #1061: seed package and write-read harness for logs
  3. test(integration): write-read cases for metrics, traces and profiles (M2 3/4, #920) #1062: write-read cases for metrics, traces and profiles
  4. this one: test(integration): schema migration and ruler boot-order checks (M2 4/4, #920) #1063: schema migration and ruler boot-order checks

Depends on #1062 (M2 3/4) and the PRs below it. Please merge those first. This PR's own changes are its last three commits; the last one addresses the review. The whole M2 stack is rebased onto current master (with #1127), so #1061 and #1062 were rebased too, without changes.

What

Schema migration lane: TestSchemaMigrations.

  • An empty database gets every declared table. gigapipe runs with MODE=init_only against a new database. The database must then hold every table and view that the single-node scripts in ctrl/qryn/sql declare: currently 28, read from the scripts so the list needs no upkeep. It must also hold ver, where the migration runner records its progress.
  • Running the migrations again changes nothing. A second run on the same database, as when an existing install restarts, must succeed and leave the same tables, each with the same create_table_query from system.tables, so a changed column, engine, TTL or view query fails.

Cluster variant: TestSchemaMigrationsCluster. This is the cluster half of #920's migration lane: the same checks with CLUSTER_NAME set, against a two-node ClickHouse cluster (test_cluster_two_shards).

  • The cluster. The lane runs the two ClickHouse services of the e2e stack (scripts/test/e2e/docker-compose.yml, whose image comes from scripts/test/docker-compose.clickhouse.yml). test/integration/cluster/docker-compose.yml is an override that only adds host ports (on 127.0.0.1), healthchecks and CLICKHOUSE_SKIP_USER_SETUP, so no image version is written here.
  • What every node must hold. On a cluster the migrations also run the four *_dist.sql scripts. Every node must hold every object of both script sets (28 local, 14 distributed), plus ver and ver_dist. A second run must change nothing on any node: the same tables with the same create_table_query.
  • How it runs. make test-integration-cluster starts the cluster, runs the test and stops the cluster, also when the cluster fails to start. The tests have their own build tag, integration_cluster, so the normal integration lane does not need a cluster.
  • When it runs. A new workflow, integration-cluster.yml (same action versions as the other workflows), runs it on the release cadence M2 — Write→read roundtrip harness + regression bank #920 names (pushes to master and by hand), and on pull requests that change ctrl/qryn/**, scripts/test/** (so a ClickHouse update runs it) or this lane's own files.

Boot-order lane: TestRulerBootOrder. gigapipe starts in all mode with GIGAPIPE_RULER_ENABLED=true (the current name for QRYN_RULER_ENABLED) and a 2s poll interval. The test checks the ruler from outside:

  • The rules API answers. GET /api/v1/rules must return 200. A ruler started before the reader registers no routes, so it answers 404.
  • A recording rule produces samples. The seed's metrics are written, then app:http_requests:sum = sum by (app) (http_requests_total{…}) is uploaded through the rules API. The recorded series must come back with the expected values.

How these tests run. Each starts its own gigapipe process with a database of its own. The single-node migration and ruler tests use the ClickHouse of the run.sh stack, so:

  • docker-compose.yml publishes ClickHouse's HTTP port too, on 127.0.0.1:8123, next to the native port master already publishes on 127.0.0.1:9000.
  • run.sh builds the binary before the tests.
  • A process that exits because its port was taken is restarted on another port. Any other failure to start fails the test and prints gigapipe's output.
  • The processes run without authentication, so they listen on 127.0.0.1 only (HOST=127.0.0.1); gigapipe's default is every interface.

Verification

After the rebase onto current master and the review changes, on ClickHouse 26.10:

  • Whole integration suite: once on a fresh stack via run.sh, 3 runs in a row against one stack, and once the way the CI lane runs it. All green, 21 tests each.
  • A definition that changes on a rerun is caught. With gigapipe changed to add a column to time_series when the migrations run on an existing database, "running the migrations again changes nothing" fails, naming time_series changed on the single node and on both cluster nodes. With the previous test code, which compared table names only, it passed. Change reverted.
  • Cluster lane: make test-integration-cluster passes on the e2e stack's two nodes.
  • The test processes stay on this machine: during the ruler test, gigapipe listened on 127.0.0.1:<port>; the same binary without HOST listens on *:<port>.
  • Teardown when the cluster fails to start: with port 8124 taken, up --wait fails, the target exits non-zero without running the test and leaves no containers. The previous target stopped at that point and left both nodes running.
  • gofmt is clean. go vet ./... (same findings as master), go vet with integration and with integration,integration_cluster, the build of ./cmd/gigapipe, go test ./... and -race on the seed package pass. make lint and golangci-lint with both tag sets report 0 issues; staticcheck and actionlint are clean, and both compose setups validate.

Before the rebase: moving the ruler before the reader in bootSequence made both boot-order cases fail (GET /api/v1/rules: status 404); 10 consecutive runs of the whole suite were green; skipping profiles_dist.sql failed both cluster cases naming the four missing *_dist tables on each node; and the cluster lane passed in GitHub Actions on a fork (54s job).

Potential risks

  • Port clashes for local runs. docker-compose.yml publishes ClickHouse on 127.0.0.1:9000 (as on master) and now 127.0.0.1:8123. A contributor already running ClickHouse on those ports gets a clash when using run.sh.
  • Extra load on ClickHouse. Both tests start extra gigapipe processes against the same ClickHouse, and each creates and then drops a database of about 30 tables per run. That adds roughly 10s to the lane.
  • Migration-check blind spot. The expected tables are read from the scripts' CREATE TABLE and CREATE [MATERIALIZED] VIEW statements. An object created another way, such as a dictionary, would not be checked.
  • Ruler timing. The ruler case depends on the 2s poll interval and a 60s deadline for the recorded samples.
  • Shared cluster services. The cluster lane runs the e2e stack's ClickHouse services and configuration, so changing them affects both lanes, and the two can't run at the same time (the e2e services have fixed container names). The override sets CLICKHOUSE_SKIP_USER_SETUP=1: without it, the image restricts the passwordless default user to connections from inside the container.
  • Cluster lane cost. It adds a job of about a minute (54s on GitHub) on pushes to master and on pull requests that change the migrations. Locally it uses ports 9000, 8123 and 8124, so the run.sh stack has to be stopped first.

Left for later

@rita7lopes rita7lopes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, the ruler check and the cluster variant are exactly what #920 asks for. A few small things before I merge:

  1. "Running the migrations again changes nothing" only compares table names. Please compare create_table_query from system.tables too, on every node, so a changed column, TTL or view is caught.
  2. Please publish the ClickHouse ports on 127.0.0.1 in both compose files. They have no password, and today they're open to the contributor's network.
  3. make test-integration-cluster doesn't stop the cluster if up --wait fails. Please make the teardown run in that case too.
  4. Please use the same actions/checkout and actions/setup-go versions as master in the new workflow.

This can be rebased once #1061 and #1062 are updated.

@rita7lopes

Copy link
Copy Markdown
Contributor

One more: please don't copy the ClickHouse image version, I don't want to update it by hand in several places. Reuse the two ClickHouse services from scripts/test/e2e/docker-compose.yml (as a compose override that only adds the ports, healthchecks and CLICKHOUSE_SKIP_USER_SETUP), so the version stays in one place.

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.
@Guess-Who-sec

Copy link
Copy Markdown
Contributor Author

Thanks @rita7lopes, all done in the last commit. The whole M2 stack is rebased onto current master, so it builds on #1127; #1061 and #1062 were only rebased, with no changes.

  1. "Running the migrations again changes nothing" compares create_table_query of every table, on the single node and on every cluster node. Checked with gigapipe changed to add a column to time_series on a rerun: the case now fails on all three nodes, and the previous name-only check passed.
  2. The ClickHouse ports are on 127.0.0.1 in both setups. master's integration compose publishes only 9000 since ci: test on ClickHouse 26.10, written once and updated by Dependabot #1127, so I added 127.0.0.1:8123 there: the migration and ruler tests read ClickHouse over HTTP.
  3. make test-integration-cluster tears down when up --wait fails. Checked with port 8124 taken: the target exits non-zero without running the test and leaves no containers (the previous one left both nodes running).
  4. The new workflow uses checkout@v7 and setup-go@v7. It also runs on changes to scripts/test/**, so a ClickHouse update runs the cluster lane.
  5. No ClickHouse version is copied any more. The cluster lane runs the e2e stack's two ClickHouse services, and test/integration/cluster/docker-compose.yml is an override that only adds the ports, healthchecks and CLICKHOUSE_SKIP_USER_SETUP.

In the same spirit as point 2: the gigapipe processes the migration and ruler tests start run without authentication and listened on every interface, so they now get HOST=127.0.0.1.

Everything passes on ClickHouse 26.10: the whole integration suite through run.sh and the way the CI lane runs it, and the cluster lane.

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.

2 participants