Skip to content

eBPF-based security platform

testing: verify OTLP exports in ClickHouse

John Fastabend57e8d4a5f9e7
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index e34e75db..7a5e9c61 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -458,13 +458,13 @@ signed config image.
- The DNS packet builders the matrix test uses
* - ``t9101-kernel-obs``
- ``kernel-obs`` with eight serializers, records from real events,
- draining exports and matching OTLP collector snapshots
+ draining exports and matching OTLP and ClickHouse snapshots
* - ``t9102-kernel-obs-net``
- - Socket families and matching OTLP collector snapshots
+ - Socket families and matching OTLP and ClickHouse snapshots
* - ``t9103-kernel-obs-priv``
- - Privilege and executable-mapping records in maps and OTLP
+ - Privilege and executable-mapping records in maps, OTLP and ClickHouse
* - ``t9104-kernel-obs-dns-matrix``
- - DNS over loopback in maps and OTLP
+ - DNS over loopback in maps, OTLP and ClickHouse
* - ``t9105-delivery``
- Registry, tree sync, load, export and attestation end to end
* - ``t9106-policy-exec-graph``
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index 18f979e3..971021a2 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -522,25 +522,29 @@ Run the end-to-end tests
``make -C testing end2end`` runs ``t9001`` on the host, then
:src:`testing/end2end/host.sh` plays the operator around one VM. It starts
-an OCI registry and an OpenTelemetry Collector in Docker containers,
-pinned by digest and behind a throwaway CA. It builds ``kernel-obs``
-into a package with ``bpm build``, pushes it with ``bpm push`` and
-appends it to a signed upatch tree with ``bpm tree append``. The target
+an OCI registry, an OpenTelemetry Collector and ClickHouse in Docker
+containers pinned by digest. The registry and collector use a throwaway
+CA. It builds ``kernel-obs`` into a package with ``bpm build``, pushes
+it with ``bpm push`` and appends it to a signed upatch tree with
+``bpm tree append``. The target
activates a signed config that points at the tree and the collector,
and its units pull, verify, load and export. The host then verifies the
target's TPM evidence with ``attest verify`` and checks that the
collector holds the package's records. The earlier ``kernel-obs`` tests
export each map snapshot as local JSON and OTLP from one read; the host
-compares the snapshots with the collector's JSON output. The comparison
-uses event times relative to each map's interval start and ignores the
-metric export time, which the two decoder calls sample independently.
+compares the snapshots with the collector's JSON output and queries the
+ClickHouse log and sum metric tables to check that both collector exports
+hold the same data. The comparison uses event times relative to each
+map's interval start and ignores the metric export time, which the two
+decoder calls sample independently.
.. code-block:: console
# make -C testing end2end
The host side writes to ``build/test-vm/end2end/``. The guest reaches
-the containers through QEMU's address for the host.
+the registry and collector through QEMU's address for the host. ClickHouse
+is available to the collector on the test's Docker network.
Write a test
------------
diff --git a/testing/end2end/check-otlp.py b/testing/end2end/check-otlp.py
index 27852038..d37b07eb 100644
--- a/testing/end2end/check-otlp.py
+++ b/testing/end2end/check-otlp.py
@@ -7,6 +7,8 @@ import glob
import json
import os
import sys
+import time
+import urllib.request
def value(item):
@@ -106,6 +108,80 @@ def check(want, got, signal):
raise AssertionError(f"missing {count} {signal} export(s): {sample[:500]}")
+def metric_points(metrics):
+ points = collections.Counter()
+ for encoded, count in metrics.items():
+ metric = json.loads(encoded)
+ total = metric["sum"]
+ for point in total["dataPoints"]:
+ attrs = {entry["key"]: value(entry["value"])
+ for entry in point.get("attributes", [])}
+ number = point.get("asInt", point.get("asDouble"))
+ item = (metric["name"], metric["description"], metric["unit"],
+ attrs["outcome"], int(point["startTimeUnixNano"]) // 10**9,
+ float(number), total["aggregationTemporality"],
+ total["isMonotonic"])
+ points[key(item)] += count
+ return points
+
+
+def query(endpoint, sql):
+ request = urllib.request.Request(endpoint, data=sql.encode("utf-8"))
+ with urllib.request.urlopen(request, timeout=5) as response:
+ return [json.loads(line) for line in response]
+
+
+def clickhouse(endpoint):
+ logs = collections.Counter()
+ metrics = collections.Counter()
+ rows = query(endpoint, """
+SELECT LogAttributes['shirudo.map.name'] AS map_name, Body AS body
+FROM shirudo.otel_logs
+WHERE ServiceName = 'shirudo'
+ AND EventName = 'shirudo.bpf.map.snapshot'
+ AND LogAttributes['shirudo.upatch.name'] = 'kernel-obs'
+FORMAT JSONEachRow
+""")
+ for row in rows:
+ logs[key((row["map_name"], log_body(json.loads(row["body"]))))] += 1
+ rows = query(endpoint, """
+SELECT MetricName AS name, MetricDescription AS description,
+ MetricUnit AS unit, Attributes['outcome'] AS outcome,
+ toUnixTimestamp(StartTimeUnix) AS start_time,
+ Value AS value, AggregationTemporality AS temporality,
+ IsMonotonic AS monotonic
+FROM shirudo.otel_metrics_sum
+WHERE ServiceName = 'shirudo' AND MetricName = 'kernel_obs.watch_attempts'
+FORMAT JSONEachRow
+""")
+ for row in rows:
+ item = (row["name"], row["description"], row["unit"],
+ row["outcome"], row["start_time"], float(row["value"]),
+ row["temporality"], bool(row["monotonic"]))
+ metrics[key(item)] += 1
+ return logs, metrics
+
+
+def check_clickhouse(endpoint, want_logs, want_metrics, got_logs, got_metrics):
+ want_points = metric_points(want_metrics)
+ got_points = metric_points(got_metrics)
+ deadline = time.monotonic() + 20
+ while True:
+ db_logs, db_points = clickhouse(endpoint)
+ if db_logs == got_logs and db_points == got_points:
+ check(want_logs, db_logs, "ClickHouse log")
+ check(want_points, db_points, "ClickHouse metric point")
+ print(f"verified {sum(db_logs.values())} logs and "
+ f"{sum(db_points.values())} metric points in ClickHouse")
+ return
+ if time.monotonic() >= deadline:
+ check(got_logs, db_logs, "ClickHouse log")
+ check(got_points, db_points, "ClickHouse metric point")
+ check(db_logs, got_logs, "collector log")
+ check(db_points, got_points, "collector metric point")
+ time.sleep(0.5)
+
+
def main():
want_logs, want_metrics = expected(sys.argv[1])
got_logs, got_metrics = collected(sys.argv[2])
@@ -113,6 +189,9 @@ def main():
check(want_metrics, got_metrics, "metric")
print(f"verified {sum(want_logs.values())} map logs and "
f"{sum(want_metrics.values())} metrics in the collector")
+ if len(sys.argv) > 3:
+ check_clickhouse(sys.argv[3], want_logs, want_metrics,
+ got_logs, got_metrics)
if __name__ == "__main__":
diff --git a/testing/end2end/host.sh b/testing/end2end/host.sh
index cb3bc4c2..84c86e9e 100755
--- a/testing/end2end/host.sh
+++ b/testing/end2end/host.sh
@@ -1,14 +1,7 @@
#!/bin/sh
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
-#
-# testing/end2end/host.sh <command>... -- the operator's side of the
-# end-to-end test, around <command>, which boots the end2end VM. An OCI
-# registry and an OpenTelemetry Collector run in containers behind a
-# throwaway CA; the operator builds kernel-obs into a package, pushes it
-# and appends it to a signed upatch tree. After the VM, the TPM-signed
-# evidence the target left must verify and record the published operation
-# and payload, and the collector must hold what the package observed.
+# testing/end2end/host.sh -- run the operator side of the end-to-end VM test.
set -eu
@@ -21,10 +14,12 @@ W=$REPO/build/test-vm/end2end
TLS_DIR=$HOST_PRIVATE_DIR/end2end-tls
REGISTRY=127.0.0.1:15443
COLLECTOR=127.0.0.1:14318
+CLICKHOUSE=127.0.0.1:18123
# registry 3.1.2 and opentelemetry-collector-contrib 0.164.0, both built
# with a Go that offers the hybrid ML-KEM group shirudo requires.
REGISTRY_IMAGE=docker.io/library/registry@sha256:d4032d4cc323c1731c707931ecada07a53076eac38e3b61ae57533f170f2c6c3
COLLECTOR_IMAGE=docker.io/otel/opentelemetry-collector-contrib@sha256:340c9ca6a36617084c6661bdc4f0fe92b7cda5a805d61673ec8db375fddc522b
+CLICKHOUSE_IMAGE=docker.io/clickhouse/clickhouse-server@sha256:d426d2f612e1e189c90f9a3f8dcd85a03c6851273833817a296bb327e63aa7a7
S=$REPO/shirudo
export SHIRUDO_BUILD="$REPO/tools/shirudo-build/shirudo-build"
export BPM_OCI_CA_FILE="$W/ca.pem"
@@ -38,8 +33,11 @@ die() { printf 'end2end: %s\n' "$*" >&2; exit 1; }
down() {
docker logs shirudo-end2end-collector >"$W/collector.log" 2>&1 || true
+ docker logs shirudo-end2end-clickhouse >"$W/clickhouse.log" 2>&1 || true
docker rm -f shirudo-end2end-registry shirudo-end2end-collector \
+ shirudo-end2end-clickhouse \
>/dev/null 2>&1 || true
+ docker network rm shirudo-end2end >/dev/null 2>&1 || true
rm -rf -- "$TLS_DIR"
}
@@ -88,11 +86,23 @@ rm -f -- "$TLS_DIR/ca.key" "$TLS_DIR/server.csr" \
chmod 0644 "$TLS_DIR/server.key"
openssl rand -hex 16 >"$W/nonce"
-say "the registry and the collector"
+say "the registry, collector and ClickHouse"
+docker network create shirudo-end2end >/dev/null
+docker run -d --name shirudo-end2end-clickhouse \
+ --network shirudo-end2end --network-alias clickhouse \
+ -p "$CLICKHOUSE:8123" -e CLICKHOUSE_SKIP_USER_SETUP=1 \
+ "$CLICKHOUSE_IMAGE" >/dev/null
+i=0
+until curl -fsS --data-binary 'SELECT 1' "http://$CLICKHOUSE/" >/dev/null 2>&1; do
+ i=$((i + 1))
+ [ "$i" -lt 150 ] || die "ClickHouse did not come up"
+ sleep 0.2
+done
docker run -d --name shirudo-end2end-registry -p "$REGISTRY:5000" \
-v "$TLS_DIR:/certs:ro" -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server.pem \
-e REGISTRY_HTTP_TLS_KEY=/certs/server.key "$REGISTRY_IMAGE" >/dev/null
docker run -d --name shirudo-end2end-collector -p "$COLLECTOR:4318" \
+ --network shirudo-end2end \
-v "$TLS_DIR:/certs:ro" -v "$W/out:/out" \
-v "$REPO/testing/end2end/otelcol.yaml:/etc/otelcol-contrib/config.yaml:ro" \
"$COLLECTOR_IMAGE" >/dev/null
@@ -181,7 +191,8 @@ PY
say "the collector holds what kernel-obs observed"
python3 "$REPO/testing/end2end/check-otlp.py" \
"$REPO/build/test-vm/vms/$VM_NAME-end2end/result/end2end/otel" \
- "$W/out/otlp.json" || die "the collector snapshots differ from the map exports"
+ "$W/out/otlp.json" "http://$CLICKHOUSE/" || \
+ die "the collector or ClickHouse snapshots differ from the map exports"
python3 - "$W/out/otlp.json" <<'PY' || die "the collector did not get the export"
import json, sys
diff --git a/testing/end2end/otelcol.yaml b/testing/end2end/otelcol.yaml
index 58acdf2c..b280c877 100644
--- a/testing/end2end/otelcol.yaml
+++ b/testing/end2end/otelcol.yaml
@@ -2,7 +2,7 @@
# Copyright (c) 2026 Authors of shirudo
#
# The collector of the end-to-end test: OTLP over HTTPS in, every request
-# written to a file the host then checks.
+# written to a file and ClickHouse for the host to compare.
receivers:
otlp:
protocols:
@@ -14,11 +14,15 @@ receivers:
exporters:
file:
path: /out/otlp.json
+ clickhouse:
+ endpoint: tcp://clickhouse:9000
+ database: shirudo
+ create_schema: true
service:
pipelines:
logs:
receivers: [otlp]
- exporters: [file]
+ exporters: [file, clickhouse]
metrics:
receivers: [otlp]
- exporters: [file]
+ exporters: [file, clickhouse]