Skip to content

Commit 5a2582e

Browse files
committed
test(observability-proxy): preserve JSON seed request bodies
Send JSON seeds with their content type so VictoriaLogs does not consume log records while parsing form parameters before ingestion. Fixes: ebb5a9c ("test(observability-proxy): cover the namespace logs scope end to end") Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 59cbf4b commit 5a2582e

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎hack/e2e-chainsaw/observability-proxy/lib.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ forward() {
2525
ingest() {
2626
printf '{"kubernetes_namespace_name":"%s","log":"%s"}\n' "$1" "$2" |
2727
timeout 15 curl --silent --show-error --fail --data-binary @- \
28-
--header "AccountID: ${3:-0}" --header "ProjectID: 0" \
28+
--header 'Content-Type: application/json' --header "AccountID: ${3:-0}" --header "ProjectID: 0" \
2929
"$STORE/insert/jsonline?_stream_fields=kubernetes_namespace_name&_msg_field=log"
3030
}
3131

‎hack/observability-proxy-seed.bats‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bats
2+
3+
load test_helper
4+
5+
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
6+
7+
setup() {
8+
strict_setup
9+
mkdir -p "$BATS_TEST_TMPDIR/bin"
10+
export SEED_CAPTURE="$BATS_TEST_TMPDIR/seed"
11+
export TMPDIR="$BATS_TEST_TMPDIR"
12+
export PATH="$BATS_TEST_TMPDIR/bin:$PATH"
13+
cat > "$BATS_TEST_TMPDIR/bin/curl" <<'EOF'
14+
#!/usr/bin/env bash
15+
set -eu
16+
printf '%s\n' "$@" > "$SEED_CAPTURE.args"
17+
cat > "$SEED_CAPTURE.body"
18+
if ! grep --fixed-strings --line-regexp --quiet 'Content-Type: application/json' "$SEED_CAPTURE.args"; then
19+
echo 'seed request is missing its JSON content type' >&2
20+
exit 22
21+
fi
22+
EOF
23+
chmod +x "$BATS_TEST_TMPDIR/bin/curl"
24+
}
25+
26+
assert_seed_request() {
27+
local account=$1
28+
# shellcheck source=e2e-chainsaw/observability-proxy/lib.sh
29+
. "$REPO_ROOT/hack/e2e-chainsaw/observability-proxy/lib.sh"
30+
if [ "$account" = 0 ]; then
31+
ingest tenant-test-logsa e2e-marker-a
32+
else
33+
ingest tenant-test-logsa e2e-marker-a "$account"
34+
fi
35+
grep --fixed-strings --line-regexp --quiet "AccountID: $account" "$SEED_CAPTURE.args"
36+
grep --fixed-strings --line-regexp --quiet 'ProjectID: 0' "$SEED_CAPTURE.args"
37+
grep --fixed-strings --line-regexp --quiet 'http://localhost:19471/insert/jsonline?_stream_fields=kubernetes_namespace_name&_msg_field=log' "$SEED_CAPTURE.args"
38+
grep --fixed-strings --line-regexp --quiet -- '--data-binary' "$SEED_CAPTURE.args"
39+
grep --fixed-strings --line-regexp --quiet '@-' "$SEED_CAPTURE.args"
40+
printf '%s\n' '{"kubernetes_namespace_name":"tenant-test-logsa","log":"e2e-marker-a"}' > "$SEED_CAPTURE.expected"
41+
cmp "$SEED_CAPTURE.expected" "$SEED_CAPTURE.body"
42+
rm "$body"
43+
}
44+
45+
@test "observability seeds send JSON without consuming the body as form data" {
46+
assert_seed_request 0
47+
}
48+
49+
@test "observability seeds preserve an explicit VictoriaLogs account" {
50+
assert_seed_request 7
51+
}

0 commit comments

Comments
 (0)