Skip to content

Commit 5fe3d1d

Browse files
authored
Add rolling compatibility checks to CI (#1598)
## Summary - Add a Compatibility workflow that compares the PR merge commit with its base and compares each push to main with the previous branch tip. - Check public and internal Protobuf contracts with checksum-pinned Buf and its FILE rules. Keep generated-code verification in the Proto workflow. - Exercise rolling upgrades, downgrades, reupgrades, and snapshot restarts on three Raft voters. Replace one voter at a time and check quorum, Redis, DynamoDB, S3, and SQS while that voter is offline. ## Validation - Ran ShellCheck, actionlint, and Buf against compatible revisions. - Completed 12 local voter replacements across the four rollout phases and verified the original synthetic data after each rollout. - Stopped two voters in a disposable cluster and confirmed that the smoke test failed on loss of quorum. - Changed the Raft Protobuf package in a disposable checkout and confirmed that Buf rejected the package change and the rolling test rejected the mixed-version cluster. A cluster running the modified binary on all three voters passed the startup and data checks. ## Author bootjp <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit - **品質向上** - プルリクエストと `main` への変更時に、Protobuf スキーマと永続化データの互換性を自動検証するようになりました。 - アップグレード、切り戻し、再アップグレード、スナップショットからの復元を含むテストで、データとサービスの継続性を確認します。 - **ドキュメント** - 互換性チェックの内容やローカルでの実行方法を説明する運用ガイドを追加し、README から参照できるようになりました。 <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 58d79a8 + e011dbd commit 5fe3d1d

7 files changed

Lines changed: 608 additions & 8 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Compatibility
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: compatibility-${{ github.event_name == 'push' && github.run_id || github.ref }}
13+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
14+
15+
jobs:
16+
protobuf:
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
steps:
20+
# actions/checkout v6
21+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
22+
with:
23+
fetch-depth: 0
24+
persist-credentials: false
25+
- name: Install checksum-pinned Buf
26+
run: |
27+
bash deploy/automation/install-buf.sh "$RUNNER_TEMP/buf-bin"
28+
echo "$RUNNER_TEMP/buf-bin" >> "$GITHUB_PATH"
29+
- name: Compare Protobuf contracts
30+
env:
31+
BASELINE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
32+
run: python3 deploy/automation/protobuf_compatibility.py "$BASELINE_SHA" HEAD
33+
persistence:
34+
runs-on: ubuntu-latest
35+
timeout-minutes: 25
36+
env:
37+
GOPROXY: https://golang.flatt.tech
38+
steps:
39+
# actions/checkout v6
40+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
41+
with:
42+
fetch-depth: 0
43+
persist-credentials: false
44+
# actions/setup-go v6
45+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
46+
with:
47+
go-version-file: go.mod
48+
- name: Build baseline and candidate
49+
env:
50+
BASELINE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
51+
run: |
52+
baseline=$(git rev-parse --verify --end-of-options "${BASELINE_SHA}^{commit}")
53+
mkdir "$RUNNER_TEMP/baseline-source"
54+
git archive "$baseline" | tar -x -C "$RUNNER_TEMP/baseline-source"
55+
(cd "$RUNNER_TEMP/baseline-source" && go build -o "$RUNNER_TEMP/elastickv-baseline" .)
56+
go build -o "$RUNNER_TEMP/elastickv-candidate" .
57+
go build -o "$RUNNER_TEMP/raftadmin" ./cmd/raftadmin
58+
- name: Install Redis test client
59+
run: sudo apt-get install -y redis-tools
60+
- name: Check quorum and data through rolling upgrade, downgrade, reupgrade and snapshot restart
61+
run: bash scripts/compatibility-smoke.sh "$RUNNER_TEMP/elastickv-baseline" "$RUNNER_TEMP/elastickv-candidate" "$RUNNER_TEMP/raftadmin"

‎.github/workflows/proto.yml‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ jobs:
3131
# actions/checkout v6
3232
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
3333
with:
34-
fetch-depth: 0
3534
persist-credentials: false
36-
- name: Fetch main for breaking baseline
37-
if: github.ref != 'refs/heads/main'
38-
run: git fetch --no-tags --prune origin +refs/heads/main:refs/heads/buf-breaking-base
3935
# actions/setup-go v6
4036
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
4137
with:
@@ -46,10 +42,6 @@ jobs:
4642
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@${{ env.PROTOC_GEN_GO_VERSION }}
4743
- name: Install protoc-gen-go-grpc
4844
run: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${{ env.PROTOC_GEN_GO_GRPC_VERSION }}
49-
- name: buf breaking (against main)
50-
if: github.ref != 'refs/heads/main'
51-
working-directory: proto
52-
run: buf breaking --against '../.git#subdir=proto,branch=buf-breaking-base'
5345
- name: Clean generated proto outputs
5446
run: find proto -maxdepth 1 -type f \( -name '*.pb.go' -o -name '*_grpc.pb.go' \) -delete
5547
- name: buf generate

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ A single node has no replica redundancy. These unauthenticated local endpoints a
6060
For Docker, persistence checks, S3/SQS setup, and troubleshooting, follow the [Getting started guide](docs/getting_started.md).
6161
For a replicated deployment, choose [Kubernetes](docs/kubernetes.md) or [multiple VMs with Docker](docs/docker_multinode_manual_run.md).
6262

63+
See [Compatibility CI](docs/operations/compatibility-ci.md) for schema and upgrade checks.
64+
6365
## Architecture
6466

6567
Elastickv presents several APIs over a shared sharded KV engine.

‎deploy/automation/install-buf.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
mkdir -p "$1"
5+
curl --fail --silent --show-error --location --retry 3 --max-time 120 \
6+
https://github.com/bufbuild/buf/releases/download/v1.55.1/buf-Linux-x86_64 \
7+
--output "$1/buf"
8+
printf '%s %s\n' 70d46fbf2e1df60b250d0954a2c6ef2cb57baa936b197a55a9c1b8de89d95c1d "$1/buf" | sha256sum --check
9+
chmod 0755 "$1/buf"
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
"""Compare immutable Protobuf trees using a trusted Buf FILE policy."""
2+
3+
import argparse
4+
import json
5+
import os
6+
import pathlib
7+
import subprocess
8+
import tempfile
9+
10+
11+
def write_workspace(directory, sources):
12+
modules = []
13+
has_primary_module = any(path.startswith("proto/") for path in sources)
14+
if has_primary_module:
15+
modules.append({"path": "proto"})
16+
if not sources or any(not path.startswith("proto/") for path in sources):
17+
root_module = {"path": "."}
18+
if has_primary_module:
19+
root_module["excludes"] = ["proto"]
20+
modules.append(root_module)
21+
directory.mkdir()
22+
for path, data in sources.items():
23+
relative = pathlib.PurePosixPath(path)
24+
if (
25+
relative.is_absolute()
26+
or ".." in relative.parts
27+
or relative.as_posix() != path
28+
):
29+
raise ValueError("Invalid Protobuf source path")
30+
target = directory / relative
31+
target.parent.mkdir(parents=True, exist_ok=True)
32+
target.write_bytes(data)
33+
(directory / "buf.yaml").write_text(
34+
json.dumps({"version": "v2", "modules": modules, "breaking": {"use": ["FILE"]}})
35+
)
36+
37+
38+
def breaking_changes(baseline, candidate):
39+
if not baseline:
40+
if not candidate:
41+
return []
42+
# Compile the first schema even though it has no prior contracts.
43+
baseline = candidate
44+
if not candidate:
45+
# Buf needs a non-empty candidate. Choose a distinct path so it
46+
# reports every baseline schema as removed.
47+
marker = "_empty.proto"
48+
while marker in baseline or "proto/" + marker in baseline:
49+
marker = "_" + marker
50+
candidate = {marker: b'syntax = "proto3";\n'}
51+
with tempfile.TemporaryDirectory(prefix="protobuf-compatibility-") as work:
52+
root = pathlib.Path(work)
53+
write_workspace(root / "baseline", baseline)
54+
write_workspace(root / "candidate", candidate)
55+
result = subprocess.run(
56+
[
57+
"buf",
58+
"breaking",
59+
"candidate",
60+
"--against",
61+
"baseline",
62+
"--disable-symlinks",
63+
"--error-format=json",
64+
],
65+
cwd=root,
66+
env={**os.environ, "XDG_CACHE_HOME": str(root / "cache")},
67+
capture_output=True,
68+
text=True,
69+
timeout=30,
70+
)
71+
if result.returncode == 0:
72+
return []
73+
try:
74+
violations = [
75+
json.loads(line)
76+
for line in (*result.stdout.splitlines(), *result.stderr.splitlines())
77+
]
78+
if (
79+
result.returncode == 100
80+
and violations
81+
and all(row.get("type") and row.get("message") for row in violations)
82+
):
83+
return sorted(
84+
(
85+
row.get("path", "protobuf").split("/", 1)[-1],
86+
row["type"],
87+
row["message"],
88+
)
89+
for row in violations
90+
)
91+
except (ValueError, AttributeError):
92+
pass
93+
raise ValueError(
94+
"Buf could not complete the Protobuf check: "
95+
+ (
96+
result.stderr or result.stdout or f"exit status {result.returncode}"
97+
).strip()[:4096]
98+
)
99+
100+
101+
def git_schemas(revision):
102+
commit = subprocess.check_output(
103+
["git", "rev-parse", "--verify", "--end-of-options", revision + "^{commit}"],
104+
text=True,
105+
).strip()
106+
entries = subprocess.check_output(
107+
["git", "ls-tree", "-rz", commit], text=True
108+
).split("\0")
109+
sources = {}
110+
for entry in filter(None, entries):
111+
metadata, path = entry.split("\t", 1)
112+
if path.endswith(".proto"):
113+
mode, kind, blob = metadata.split()
114+
if mode not in ("100644", "100755") or kind != "blob":
115+
raise ValueError("Unsupported Protobuf source mode: " + path)
116+
sources[path] = subprocess.check_output(["git", "cat-file", "blob", blob])
117+
return sources
118+
119+
120+
if __name__ == "__main__":
121+
parser = argparse.ArgumentParser(description=__doc__)
122+
parser.add_argument("baseline")
123+
parser.add_argument("candidate")
124+
args = parser.parse_args()
125+
violations = breaking_changes(
126+
git_schemas(args.baseline), git_schemas(args.candidate)
127+
)
128+
for path, rule, message in violations:
129+
print(f"{path}: {rule}: {message}")
130+
raise SystemExit(bool(violations))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Compatibility CI
2+
3+
The [Compatibility workflow](../../.github/workflows/compatibility.yml) compares
4+
the PR merge result with the PR's base commit. On pushes to `main`, it compares
5+
the new commit with the branch's previous tip.
6+
7+
- **Protobuf** runs Buf's `FILE` rules over the checked-in schemas, including
8+
internal RPCs. The CI supplies the policy to both revisions. Generated code
9+
drift is checked by the separate Proto workflow.
10+
- **Persistence** builds both revisions and starts three loopback Raft voters
11+
with disposable data directories. It replaces one voter at a time during
12+
upgrade, downgrade, reupgrade, and restart. Before downgrade and the final
13+
restart, each voter must persist a snapshot covering a new marker. The test
14+
moves each stopped voter's Pebble state aside, preserves its Raft WAL and
15+
snapshots, and requires a successful full snapshot restore and marker
16+
readback from the recovered voter while it is the leader. During downgrade,
17+
each voter first opens the candidate's intact
18+
Pebble database with the baseline, then verifies that the baseline can also
19+
restore the candidate-generated snapshot.
20+
When the next voter is the leader, the test transfers leadership
21+
first. During each replacement it samples the two remaining voters for a
22+
shared leader and term and tests a committed Redis write and read. While the
23+
voter is stopped, it also writes and reads data through Redis, DynamoDB, S3,
24+
and SQS. It checks the original synthetic data after each rollout.
25+
26+
Both jobs run on GitHub-hosted runners with read-only repository permissions.
27+
The test credentials are disposable and used by the loopback listeners.
28+
The isolated [release qualification](../../deploy/automation/README.md)
29+
covers the deployment image and Kubernetes rollout.
30+
31+
Run the schema check locally from the repository root with Buf 1.55.1:
32+
33+
```sh
34+
python3 deploy/automation/protobuf_compatibility.py origin/main HEAD
35+
```

0 commit comments

Comments
 (0)