logtail-rack 0.2.8 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 491ec5e9eed4646a543ceda9f205b64687c5cc86299940ad23b920e83097bd69
4
- data.tar.gz: 3063069043ec64c72e74c52ea00a0d033a21590bdc89369e984b75ff580fc83c
3
+ metadata.gz: 2a02b2c34943570924a1f8acc7c8d2d3b381bf0e2a4aa66686cd6fd03274de82
4
+ data.tar.gz: 63e437edb3fa98f4ea13320645a52c09c1b8df1be347ca2e624a5805d53b17bd
5
5
  SHA512:
6
- metadata.gz: ac332a52ed1a822b42e23fe852736276a87ae828f54ddc6c281b54a249a9a21c8e768b0553df688654644c414ae1db51cab4b4c8e1657d88535e32a9a78ecabf
7
- data.tar.gz: 0e336672e86b16a1c85b62feb34939c4d241417e7e31af02b18ef36a29f0d63882c53bb91c2751b6fb12ee61841057b4e092877ee026948a75d1c746874d7a8f
6
+ metadata.gz: 925783dc2e859c201acd9db0d9c623f9411c54e0901a70af8aef089b48e22d83db6553588e76e63e9d315bcc5de4ea05f8f6b7d4d22470b73087a2030a0d9144
7
+ data.tar.gz: 8bde77cae1e1cbb502263d8837b17ea444537ea6a10fdd2168d3e51325c6a674718aa35c2e4012360c3b46cf1e5f1a036e26806a187a81c2ceb0fe97871f144f
@@ -0,0 +1,33 @@
1
+ # Deletes the run's source and stale sources of earlier runs of the same test, and never fails the job.
2
+ # The logic is in run.sh, which reads only environment variables, so it runs the same way outside of Actions.
3
+ name: "Clean up Better Stack sources"
4
+ description: "Deletes this run's source and sources of earlier runs, named with the same prefix, that are older than stale-hours"
5
+
6
+ inputs:
7
+ api-token:
8
+ description: "Telemetry API token of the team the sources are in"
9
+ required: true
10
+ prefix:
11
+ description: "Name prefix of this test's sources, only those are swept"
12
+ required: true
13
+ id:
14
+ description: "Id of this run's source, deleted whatever its age"
15
+ default: ""
16
+ stale-hours:
17
+ description: "Sources with the prefix older than this many hours are left over from earlier runs"
18
+ default: "3"
19
+ out:
20
+ description: "Directory for cleanup.md"
21
+ default: out
22
+
23
+ runs:
24
+ using: composite
25
+ steps:
26
+ - shell: bash
27
+ env:
28
+ INPUT_API_TOKEN: ${{ inputs.api-token }}
29
+ INPUT_PREFIX: ${{ inputs.prefix }}
30
+ INPUT_ID: ${{ inputs.id }}
31
+ INPUT_STALE_HOURS: ${{ inputs.stale-hours }}
32
+ INPUT_OUT: ${{ inputs.out }}
33
+ run: bash "${{ github.action_path }}/run.sh"
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env bash
2
+ # Deletes this run's source, then what earlier runs of the same test left behind (a cancelled job never reaches its
3
+ # cleanup): every source whose name starts with the prefix and that is older than stale-hours. Younger sources may
4
+ # belong to a run still in progress and stay. Writes <out>/cleanup.md, one line per deletion, and always exits 0:
5
+ # a failed deletion shows in the report, but never hides the test result.
6
+ # Env: INPUT_API_TOKEN, INPUT_PREFIX, INPUT_ID (optional), INPUT_STALE_HOURS (default 3), INPUT_OUT (default out).
7
+ set -euo pipefail
8
+ # A native jq.exe, as on Windows runners, ends its output lines with CRLF unless given -b.
9
+ if [ "${OS:-}" = Windows_NT ]; then jq() { command jq -b "$@"; }; fi
10
+
11
+ API=https://telemetry.betterstack.com
12
+ OUT=${INPUT_OUT:-out}
13
+ mkdir -p "$OUT"
14
+ : > "$OUT/cleanup.md"
15
+ say() { echo "$1"; echo "$1" >> "$OUT/cleanup.md"; }
16
+ trap 'status=$?; [ "$status" = 0 ] || say "- ❌ cleanup stopped on an error, see the log of this step"; exit 0' EXIT
17
+
18
+ delete() {
19
+ local code
20
+ code=$(curl -sS -m 60 -o /dev/null -w '%{http_code}' -X DELETE "$API/api/v1/sources/$1" -H "Authorization: Bearer $INPUT_API_TOKEN") || code=000
21
+ case "$code" in
22
+ 204) say "- deleted $2" ;;
23
+ 404) say "- $2 was already gone" ;;
24
+ *) say "- ❌ could not delete $2 (HTTP $code)" ;;
25
+ esac
26
+ }
27
+
28
+ say "### Cleanup"
29
+ say ""
30
+ [ -z "${INPUT_ID:-}" ] || delete "$INPUT_ID" "this run's source $INPUT_ID"
31
+
32
+ # An empty prefix would sweep every source of the team.
33
+ [ -n "$INPUT_PREFIX" ] || { say "- ❌ no prefix given, so stale sources were not looked for"; exit 0; }
34
+ # The name filter matches anywhere in the name, so the prefix is checked again. The next-page link the API returns
35
+ # drops the filter, so pages are counted here instead of following it.
36
+ STALE=""
37
+ for ((page = 1; ; page++)); do
38
+ RES=$(curl -sS -m 60 -G "$API/api/v1/sources" --data-urlencode "name=$INPUT_PREFIX" -d per_page=250 -d "page=$page" -H "Authorization: Bearer $INPUT_API_TOKEN") || RES=""
39
+ jq -e '.data | type == "array"' <<<"$RES" >/dev/null 2>&1 || { say "- ❌ could not list sources, so stale ones were not deleted: $(head -c 300 <<<"${RES:-no response}")"; STALE=""; break; }
40
+ STALE+=$(jq -r --arg prefix "$INPUT_PREFIX" --arg id "${INPUT_ID:-}" --argjson hours "${INPUT_STALE_HOURS:-3}" '.data[]
41
+ | select((.attributes.name | startswith($prefix)) and .id != $id)
42
+ | select((.attributes.created_at | sub("\\.[0-9]+"; "") | fromdateiso8601) < now - $hours * 3600)
43
+ | "\(.id) \(.attributes.created_at) \(.attributes.name)"' <<<"$RES")$'\n'
44
+ [ "$(jq -r '.pagination.next' <<<"$RES")" != null ] || break
45
+ done
46
+ while read -r id created_at name; do
47
+ [ -n "$id" ] || continue
48
+ delete "$id" "stale source $id \`$name\` (created $created_at)"
49
+ done <<<"$STALE"
50
+
51
+ [ "$(wc -l < "$OUT/cleanup.md")" -gt 2 ] || say "- nothing to delete"
@@ -0,0 +1,46 @@
1
+ # Creates a Better Stack source through the Telemetry API and waits until ingest reliably accepts its token.
2
+ # The logic is in run.sh, which reads only environment variables, so it runs the same way outside of Actions.
3
+ name: "Create a Better Stack source"
4
+ description: "Creates a source, warms it up until ingest accepts its token and outputs where to send and read logs"
5
+
6
+ inputs:
7
+ api-token:
8
+ description: "Telemetry API token of the team the source is created in"
9
+ required: true
10
+ name:
11
+ description: "Name of the new source"
12
+ required: true
13
+ platform:
14
+ description: "Platform of the new source, as the Telemetry API names it"
15
+ required: true
16
+
17
+ outputs:
18
+ id:
19
+ description: "Source id"
20
+ value: ${{ steps.run.outputs.id }}
21
+ token:
22
+ description: "Source token for ingest (masked in the logs)"
23
+ value: ${{ steps.run.outputs.token }}
24
+ ingesting-host:
25
+ description: "Host to send logs to"
26
+ value: ${{ steps.run.outputs.ingesting-host }}
27
+ data-region:
28
+ description: "Data region the source stores its logs in"
29
+ value: ${{ steps.run.outputs.data-region }}
30
+ collection:
31
+ description: "Collection name for the SQL API, t<team id>_<table name>"
32
+ value: ${{ steps.run.outputs.collection }}
33
+ connect-host:
34
+ description: "SQL API host that reads this source"
35
+ value: ${{ steps.run.outputs.connect-host }}
36
+
37
+ runs:
38
+ using: composite
39
+ steps:
40
+ - id: run
41
+ shell: bash
42
+ env:
43
+ INPUT_API_TOKEN: ${{ inputs.api-token }}
44
+ INPUT_NAME: ${{ inputs.name }}
45
+ INPUT_PLATFORM: ${{ inputs.platform }}
46
+ run: bash "${{ github.action_path }}/run.sh"
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+ # Creates a source and warms it up. A fresh source drops what it receives in its first seconds, and every ingest
3
+ # process picks up a new token on its own schedule, so one accepted line proves nothing: the source counts as ready
4
+ # after 20 probe lines in a row were accepted, plus a short pause to settle. Probe lines carry the message
5
+ # "e2e warm-up <source name>", which verify-logs ignores.
6
+ # Env: INPUT_API_TOKEN, INPUT_NAME, INPUT_PLATFORM, GITHUB_OUTPUT.
7
+ set -euo pipefail
8
+ # A native jq.exe, as on Windows runners, ends its output lines with CRLF unless given -b.
9
+ if [ "${OS:-}" = Windows_NT ]; then jq() { command jq -b "$@"; }; fi
10
+
11
+ API=https://telemetry.betterstack.com
12
+
13
+ BODY=$(jq -nc --arg name "$INPUT_NAME" --arg platform "$INPUT_PLATFORM" '{name: $name, platform: $platform}')
14
+ RES=$(curl -sS -m 60 -X POST "$API/api/v1/sources" -H "Authorization: Bearer $INPUT_API_TOKEN" -H 'Content-Type: application/json' -d "$BODY") || true
15
+ ID=$(jq -er '.data.id' <<<"$RES" 2>/dev/null) || { echo "::error::creating source $INPUT_NAME failed: ${RES:-no response}"; exit 1; }
16
+ TOKEN=$(jq -r '.data.attributes.token' <<<"$RES")
17
+ INGESTING_HOST=$(jq -r '.data.attributes.ingesting_host' <<<"$RES")
18
+ DATA_REGION=$(jq -r '.data.attributes.data_region' <<<"$RES")
19
+ echo "::add-mask::$TOKEN"
20
+ {
21
+ echo "id=$ID"
22
+ echo "token=$TOKEN"
23
+ echo "ingesting-host=$INGESTING_HOST"
24
+ echo "data-region=$DATA_REGION"
25
+ echo "collection=t$(jq -r '.data.attributes.team_id' <<<"$RES")_$(jq -r '.data.attributes.table_name' <<<"$RES")"
26
+ echo "connect-host=$DATA_REGION-connect.betterstackdata.com"
27
+ } >> "$GITHUB_OUTPUT"
28
+ echo "created source $ID \`$INPUT_NAME\` in data region $DATA_REGION"
29
+
30
+ PROBE=$(jq -nc --arg message "e2e warm-up $INPUT_NAME" '{message: $message}')
31
+ STREAK=0
32
+ DEADLINE=$((SECONDS + 300))
33
+ while [ "$STREAK" -lt 20 ]; do
34
+ CODE=$(curl -sS -m 10 -o /dev/null -w '%{http_code}' -X POST "https://$INGESTING_HOST/" -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d "$PROBE") || true
35
+ if [ "$CODE" = 202 ]; then STREAK=$((STREAK + 1)); else echo "ingest answered HTTP $CODE after $STREAK accepted in a row"; STREAK=0; fi
36
+ [ "$SECONDS" -lt "$DEADLINE" ] || { echo "::error::ingest did not accept the token of source $ID 20 times in a row within 5 min"; exit 1; }
37
+ sleep 1
38
+ done
39
+ sleep 15
40
+ echo "ingest accepted 20 probe lines in a row, source $ID is ready"
@@ -0,0 +1,47 @@
1
+ # Reads a source's logs back through the team's SQL API connection and checks them exactly against an expected file.
2
+ # The logic is in run.sh, which reads only environment variables, so it runs the same way outside of Actions.
3
+ name: "Verify stored logs"
4
+ description: "Polls a source's stored logs until the expected rows arrive, then checks each one is stored exactly once"
5
+
6
+ inputs:
7
+ connection-username:
8
+ description: "Username of the team's SQL API connection"
9
+ required: true
10
+ connection-password:
11
+ description: "Password of the team's SQL API connection"
12
+ required: true
13
+ connect-host:
14
+ description: "SQL API host, the connect-host output of create-source"
15
+ required: true
16
+ collection:
17
+ description: "Collection to read, the collection output of create-source"
18
+ required: true
19
+ expected:
20
+ description: >-
21
+ Path to a JSON array of the rows that must be stored, each {"level": ..., "message": ...} or
22
+ {"level": ..., "message_prefix": ...}, optionally with "contains": an object the stored row must contain
23
+ required: true
24
+ out:
25
+ description: "Directory for rows.json and summary.md"
26
+ default: out
27
+ deadline-seconds:
28
+ description: "How long to wait for the expected number of rows"
29
+ default: "300"
30
+ ignore-message-prefix:
31
+ description: "Rows whose message starts with this are not counted (the warm-up lines of create-source)"
32
+ default: "e2e warm-up"
33
+
34
+ runs:
35
+ using: composite
36
+ steps:
37
+ - shell: bash
38
+ env:
39
+ INPUT_CONNECTION_USERNAME: ${{ inputs.connection-username }}
40
+ INPUT_CONNECTION_PASSWORD: ${{ inputs.connection-password }}
41
+ INPUT_CONNECT_HOST: ${{ inputs.connect-host }}
42
+ INPUT_COLLECTION: ${{ inputs.collection }}
43
+ INPUT_EXPECTED: ${{ inputs.expected }}
44
+ INPUT_OUT: ${{ inputs.out }}
45
+ INPUT_DEADLINE_SECONDS: ${{ inputs.deadline-seconds }}
46
+ INPUT_IGNORE_MESSAGE_PREFIX: ${{ inputs.ignore-message-prefix }}
47
+ run: bash "${{ github.action_path }}/run.sh"
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env bash
2
+ # Reads a source's logs back through the team's SQL API connection and checks them against an expected file: as
3
+ # many rows as expected, each expected entry matched by exactly one row, no row left unmatched. Rows land in hot
4
+ # storage first and are copied to cold storage later, so both are read and a cold row counts only when hot storage
5
+ # lacks it. Once enough rows arrived it reads again 30 s later, so a duplicate delivery fails instead of slipping
6
+ # through. Writes <out>/rows.json and <out>/summary.md on every exit path: the summary is what a failure report shows.
7
+ # Env: INPUT_CONNECTION_USERNAME, INPUT_CONNECTION_PASSWORD, INPUT_CONNECT_HOST, INPUT_COLLECTION, INPUT_EXPECTED,
8
+ # INPUT_OUT (default out), INPUT_DEADLINE_SECONDS (default 300), INPUT_IGNORE_MESSAGE_PREFIX (default "e2e warm-up").
9
+ set -euo pipefail
10
+ # A native jq.exe, as on Windows runners, ends its output lines with CRLF unless given -b.
11
+ if [ "${OS:-}" = Windows_NT ]; then jq() { command jq -b "$@"; }; fi
12
+
13
+ OUT=${INPUT_OUT:-out}
14
+ IGNORE=${INPUT_IGNORE_MESSAGE_PREFIX-e2e warm-up}
15
+ # jq: the warm-up lines of create-source, rows whose message starts with the ignore prefix.
16
+ IGNORED='def ignored: $ignore != "" and (.raw.message | type) == "string" and (.raw.message | startswith($ignore));'
17
+ CHECKS=""
18
+ FAILURE=""
19
+ COUNTS=""
20
+ mkdir -p "$OUT"
21
+ echo '[]' > "$OUT/rows.json"
22
+
23
+ fail() { FAILURE="$1"; echo "::error::$1"; exit 1; }
24
+
25
+ summarize() {
26
+ local status=$?
27
+ {
28
+ echo "Read back through \`$INPUT_CONNECT_HOST\` from \`$INPUT_COLLECTION\`${COUNTS:+: $COUNTS}"
29
+ echo
30
+ if [ -n "$CHECKS" ]; then printf '%s' "$CHECKS"; else echo "- ❌ ${FAILURE:-stopped on an error, see the log of this step}"; fi
31
+ if [ "$(jq length "$OUT/rows.json")" -gt 0 ]; then
32
+ echo
33
+ echo "<details><summary>One stored row</summary>"
34
+ echo
35
+ echo '```json'
36
+ jq --arg ignore "$IGNORE" "$IGNORED"' (map(select(ignored | not)) | max_by(.raw | keys | length)) // .[0]' "$OUT/rows.json"
37
+ echo '```'
38
+ echo
39
+ echo "</details>"
40
+ fi
41
+ } > "$OUT/summary.md"
42
+ exit "$status"
43
+ }
44
+ trap summarize EXIT
45
+
46
+ jq -e 'type == "array" and length > 0 and all(.[]; type == "object" and has("level") and (has("message") or has("message_prefix")))' "$INPUT_EXPECTED" >/dev/null 2>&1 \
47
+ || fail "$INPUT_EXPECTED is not a JSON array of {\"level\", \"message\" or \"message_prefix\", optional \"contains\"} objects"
48
+ WANT=$(jq length "$INPUT_EXPECTED")
49
+
50
+ # Writes the rows as JSONEachRow into $2, or nothing while the collection does not exist: it is created with the
51
+ # source's first stored row.
52
+ sql() {
53
+ local code
54
+ code=$(curl -sS -m 60 -o "$2" -w '%{http_code}' -u "$INPUT_CONNECTION_USERNAME:$INPUT_CONNECTION_PASSWORD" \
55
+ -H 'Content-Type: plain/text' --data-binary "$1 FORMAT JSONEachRow" "https://$INPUT_CONNECT_HOST/") || code=000
56
+ if [ "$code" = 500 ] && grep -qE 'CLUSTER_DOESNT_EXIST|NAMED_COLLECTION_DOESNT_EXIST|UNKNOWN_TABLE' "$2"; then : > "$2"; return; fi
57
+ [ "$code" = 200 ] || fail "the SQL API on $INPUT_CONNECT_HOST answered HTTP $code: $(head -c 300 "$2" 2>/dev/null)"
58
+ }
59
+
60
+ read_rows() {
61
+ sql "SELECT dt, raw FROM remote(${INPUT_COLLECTION}_logs)" "$OUT/hot.ndjson"
62
+ sql "SELECT dt, raw FROM s3Cluster(primary, ${INPUT_COLLECTION}_s3) WHERE _row_type = 1" "$OUT/cold.ndjson"
63
+ jq -n --slurpfile hot "$OUT/hot.ndjson" --slurpfile cold "$OUT/cold.ndjson" \
64
+ '($hot | map({dt, raw})) as $h | $h + ($cold | map({dt, raw}) | map(select(IN($h[]) | not))) | map(.raw |= fromjson) | sort_by(.dt)' > "$OUT/rows.json"
65
+ local all hot
66
+ all=$(jq length "$OUT/rows.json")
67
+ hot=$(jq -s length "$OUT/hot.ndjson")
68
+ GOT=$(jq --arg ignore "$IGNORE" "$IGNORED"' map(select(ignored | not)) | length' "$OUT/rows.json")
69
+ COUNTS="$hot rows in hot storage, $((all - hot)) more in cold storage, $((all - GOT)) of them ignored as \"$IGNORE\" lines"
70
+ }
71
+
72
+ DEADLINE=$((SECONDS + ${INPUT_DEADLINE_SECONDS:-300}))
73
+ while :; do
74
+ read_rows
75
+ [ "$GOT" -lt "$WANT" ] || break
76
+ [ "$SECONDS" -lt "$DEADLINE" ] || { echo "deadline passed with $GOT of $WANT rows"; break; }
77
+ echo "$GOT of $WANT rows so far, reading again in 10 s"
78
+ sleep 10
79
+ done
80
+ echo "$GOT of $WANT rows, reading once more in 30 s to catch duplicate delivery"
81
+ sleep 30
82
+ read_rows
83
+
84
+ # One check per line: the row count, each expected entry (exactly one row matches it), each row no entry matches.
85
+ # "contains" is jq's contains: objects and arrays may hold more than expected, strings match as substrings.
86
+ RESULT=$(jq -c --arg ignore "$IGNORE" --slurpfile expected "$INPUT_EXPECTED" "$IGNORED"'
87
+ def text: tostring | gsub("\\s+"; " ") | if length > 100 then .[0:100] + "..." else . end;
88
+ def message_matches($e): (.message | type) == "string" and if $e | has("message") then .message == $e.message else .message | startswith($e.message_prefix) end;
89
+ def matches($e): .level == $e.level and message_matches($e) and (($e | has("contains") | not) or contains($e.contains));
90
+ def describe: "`\(.level)` " + (if has("message") then "\"\(.message | text)\"" else "message starting with \"\(.message_prefix | text)\"" end)
91
+ + (if has("contains") then " containing `\(.contains | tojson | text)`" else "" end);
92
+ def near($e): [.[] | select(message_matches($e)) | if .level != $e.level then "a row with this message has level `\(.level)`" else "a row with this message lacks part of what it should contain" end] | unique;
93
+ map(select(ignored | not) | .raw) as $rows | $expected[0] as $expected
94
+ | [{ok: (($rows | length) == ($expected | length)), text: "\($rows | length) rows stored, \($expected | length) expected"}]
95
+ + [$expected[] as $e | ([$rows[] | select(matches($e))] | length) as $n | ($rows | near($e)) as $near
96
+ | {ok: ($n == 1), text: (($e | describe) + if $n == 1 then " stored once" elif $n > 1 then " stored \($n) times"
97
+ elif $near == [] then " missing" else " missing (\($near | join(", ")))" end)}]
98
+ + [$rows[] | select(. as $r | any($expected[]; . as $e | $r | matches($e)) | not) | {ok: false, text: "unexpected row: `\(.level)` \"\(.message | text)\""}]
99
+ ' "$OUT/rows.json")
100
+ CHECKS=$(jq -r '.[] | "- \(if .ok then "✅" else "❌" end) \(.text)"' <<<"$RESULT")$'\n'
101
+ printf '%s' "$CHECKS"
102
+ PROBLEMS=$(jq -r 'map(select(.ok | not) | .text) | join("; ")' <<<"$RESULT")
103
+ [ -z "$PROBLEMS" ] || fail "the stored rows differ from $INPUT_EXPECTED: $PROBLEMS"
104
+ echo "every expected row is stored exactly once"
@@ -0,0 +1,292 @@
1
+ name: E2E
2
+
3
+ # Proves that the middlewares still deliver logs to Better Stack. Every job creates its own ruby source through the
4
+ # Telemetry API, warms it up, starts example-project/ with `bundle exec rackup` (what its README tells customers to
5
+ # run) with that source's token and ingesting host, visits / and /error and stops the server, reads the stored rows
6
+ # back through the testing team's SQL API connection, checks them exactly against e2e/expected.json (the app's three
7
+ # lines, the request, response and error events, nothing missing, extra or duplicated), and deletes the source
8
+ # again, together with sources of earlier runs left behind for more than 3 hours. e2e/plan.rb plans four legs:
9
+ # floor Ruby 2.7 with Rack 1.2.0 and logtail 0.1.15, the oldest releases the gemspec allows
10
+ # rack2 Ruby 3.2 with the newest Rack 2 and the newest logtail
11
+ # latest the newest stable Ruby with the newest rack and logtail releases; Bundler failing to install them, say a
12
+ # Rack 4 that the gemspec's "< 4.0" excludes, fails the job
13
+ # canary ruby-head with rack's main branch and the newest logtail
14
+ # The floor and rack2 legs run on the oldest Ubuntu image GitHub offers, latest and canary on ubuntu-latest, so a new
15
+ # runner image is covered as well.
16
+ # Every job checks, before it creates a source, that the Ruby running, the client (the gem built here, or the
17
+ # rubygems.org release on the schedule) and the rack and logtail versions are the planned ones, and writes them into
18
+ # its summary. Pushes to main and pull requests install the gem built from the checkout, as the Release workflow
19
+ # builds it. The daily schedule installs the newest release from rubygems.org instead, which is what a customer gets
20
+ # today. A failure on main or on the schedule files a Linear issue (notify_linear_failure.yml), at low priority when
21
+ # only the canary failed. Pull requests from forks run only the plan: they get no secrets, so they cannot create a
22
+ # source.
23
+ #
24
+ # Secrets: TEST_TEAM_TELEMETRY_API, TEST_TEAM_CONNECTION_USERNAME, TEST_TEAM_CONNECTION_PASSWORD (Better Stack's E2E
25
+ # testing team), LINEAR_* (see notify_linear_failure.yml).
26
+ #
27
+ # One leg, or exact versions: Actions → E2E → Run workflow, pick the leg and optionally set ruby-version (e.g. 3.3.6
28
+ # or head), rack-version (e.g. 3.1.9) or logtail-version (e.g. 0.1.17), which replace the planned versions of every
29
+ # leg that runs. That is how a failure is bisected to one release.
30
+
31
+ on:
32
+ push:
33
+ branches: [main]
34
+ pull_request:
35
+ schedule:
36
+ - cron: '0 7 * * *'
37
+ workflow_dispatch:
38
+ inputs:
39
+ leg:
40
+ description: 'Leg to run'
41
+ type: choice
42
+ options: [all, floor, rack2, latest, canary]
43
+ default: all
44
+ source:
45
+ description: 'checkout: the gem built from this checkout, as the Release workflow builds it. rubygems: its newest release on rubygems.org, what a customer installs'
46
+ type: choice
47
+ options: [checkout, rubygems]
48
+ default: checkout
49
+ ruby-version:
50
+ description: 'One exact Ruby version (e.g. 3.3.6 or head) instead of the planned one'
51
+ type: string
52
+ rack-version:
53
+ description: 'One exact rack version (e.g. 3.1.9) instead of the planned one'
54
+ type: string
55
+ logtail-version:
56
+ description: 'One exact logtail version (e.g. 0.1.17) instead of the planned one'
57
+ type: string
58
+
59
+ permissions:
60
+ contents: read
61
+
62
+ jobs:
63
+ plan:
64
+ runs-on: ubuntu-24.04
65
+ outputs:
66
+ matrix: ${{ steps.plan.outputs.matrix }}
67
+
68
+ steps:
69
+ - name: "[Setup] Checkout code"
70
+ uses: actions/checkout@v7
71
+
72
+ - name: "[Setup] Ruby"
73
+ uses: ruby/setup-ruby@v1
74
+ with:
75
+ ruby-version: ruby
76
+
77
+ - name: "[Setup] Plan the legs"
78
+ id: plan
79
+ env:
80
+ LEG: ${{ inputs.leg || 'all' }}
81
+ WANT_RUBY: ${{ inputs.ruby-version }}
82
+ WANT_RACK: ${{ inputs.rack-version }}
83
+ WANT_LOGTAIL: ${{ inputs.logtail-version }}
84
+ # The schedule tests what a customer installs today, pushes and pull requests test the checkout.
85
+ CLIENT_FROM: ${{ github.event_name == 'schedule' && 'rubygems' || inputs.source || 'checkout' }}
86
+ run: |
87
+ MATRIX=$(ruby e2e/plan.rb --leg "$LEG" --ruby "$WANT_RUBY" --rack "$WANT_RACK" --logtail "$WANT_LOGTAIL" --source "$CLIENT_FROM")
88
+ echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
89
+ jq . <<<"$MATRIX"
90
+
91
+ test:
92
+ needs: plan
93
+ name: ${{ matrix.name }}
94
+ # Forks and Dependabot get no repository secrets, so their pull requests run only the plan.
95
+ if: ${{ github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') }}
96
+ runs-on: ${{ matrix.runner }}
97
+ timeout-minutes: 20
98
+ strategy:
99
+ fail-fast: false
100
+ matrix:
101
+ include: ${{ fromJSON(needs.plan.outputs.matrix) }}
102
+
103
+ env:
104
+ LEG: ${{ matrix.leg }}
105
+ CLIENT_FROM: ${{ matrix.source }}
106
+ CLIENT: ${{ matrix.client }}
107
+ PLANNED_RUBY: ${{ matrix.ruby }}
108
+ PLANNED_RACK: ${{ matrix.rack }}
109
+ PLANNED_LOGTAIL: ${{ matrix.logtail }}
110
+
111
+ steps:
112
+ - name: "[Setup] Checkout code"
113
+ uses: actions/checkout@v7
114
+
115
+ - name: "[Setup] Ruby ${{ matrix.ruby }}"
116
+ uses: ruby/setup-ruby@v1
117
+ with:
118
+ ruby-version: ${{ matrix.ruby }}
119
+
120
+ - name: "[Setup] Build and install the client"
121
+ run: |
122
+ if [ "$CLIENT_FROM" = rubygems ]; then
123
+ echo "The example takes logtail-rack $CLIENT, the newest release, from rubygems.org."
124
+ else
125
+ # The gem the Release workflow builds and pushes to rubygems.org. Installed from this file only
126
+ # (--local), its dependencies come with the example's bundle.
127
+ gem build logtail-ruby-rack.gemspec
128
+ gem install --local --ignore-dependencies "logtail-rack-$CLIENT.gem"
129
+ fi
130
+
131
+ # The example's Gemfile asks for any Rack 3 and logtail-rack 0.2, as a customer's does. The job pins the
132
+ # client, rack and logtail to the leg's versions in place, so that Bundler cannot quietly resolve older
133
+ # releases: it fails and names the conflict instead. On a checkout run, logtail-rack is pinned to the version
134
+ # just installed from the built gem, and Bundler uses that installed gem.
135
+ - name: "[Setup] Install the example's gems at the leg's versions"
136
+ working-directory: example-project
137
+ run: |
138
+ if [ "$PLANNED_RACK" = main ]; then RACK_GEM='gem "rack", github: "rack/rack", branch: "main"'; else RACK_GEM="gem \"rack\", \"$PLANNED_RACK\""; fi
139
+ sed -i -e "s|^gem \"rack\", .*|$RACK_GEM|" -e "s|^gem \"logtail-rack\", .*|gem \"logtail-rack\", \"$CLIENT\"|" Gemfile
140
+ echo "gem \"logtail\", \"$PLANNED_LOGTAIL\"" >> Gemfile
141
+ for line in "$RACK_GEM" "gem \"logtail-rack\", \"$CLIENT\""; do
142
+ grep -qxF "$line" Gemfile || { echo "::error::Gemfile has no line to pin, it should get: $line"; exit 1; }
143
+ done
144
+ git diff Gemfile
145
+ set -o pipefail
146
+ mkdir -p ../out
147
+ if ! bundle install 2>&1 | tee ../out/bundle.log; then
148
+ # On the latest leg, most likely a new major that the gemspec (or this Ruby) excludes: support it and
149
+ # widen the constraint.
150
+ echo "::error::bundle install failed for rack $PLANNED_RACK, logtail $PLANNED_LOGTAIL and logtail-rack $CLIENT on Ruby $PLANNED_RUBY: $(grep -m 1 -iE 'could not|conflict|error' ../out/bundle.log || tail -n 1 ../out/bundle.log)"
151
+ exit 1
152
+ fi
153
+
154
+ - name: "[Verify] Installed versions are the planned ones"
155
+ working-directory: example-project
156
+ run: |
157
+ mkdir -p ../out
158
+ bundle exec ruby -rjson -e '
159
+ specs = Gem.loaded_specs
160
+ puts JSON.generate(
161
+ ruby: RUBY_VERSION, description: RUBY_DESCRIPTION, patchlevel: RUBY_PATCHLEVEL,
162
+ gems: %w[logtail-rack logtail rack rackup webrick msgpack].to_h { |name| [name, specs[name] && specs[name].version.to_s] },
163
+ client_path: specs["logtail-rack"].full_gem_path, client_cache: specs["logtail-rack"].cache_file)' > ../out/installed.json
164
+ installed() { jq -r --arg name "$1" '.gems[$name] // "none"' ../out/installed.json; }
165
+ RUBY=$(jq -r .ruby ../out/installed.json)
166
+ RACK=$(installed rack)
167
+ LOGTAIL=$(installed logtail)
168
+ # rack's main branch: the commit Bundler checked out.
169
+ RACK_REVISION=$(sed -n 's/^ revision: //p' Gemfile.lock)
170
+ if [ "$CLIENT_FROM" = checkout ]; then FROM="the gem built here"; else FROM="rubygems.org"; fi
171
+ echo "- $(jq -r .description ../out/installed.json), logtail-rack $(installed logtail-rack) from $FROM, rack $RACK${RACK_REVISION:+ from main at ${RACK_REVISION:0:7}}, logtail $LOGTAIL, rackup $(installed rackup), webrick $(installed webrick), msgpack $(installed msgpack)" | tee -a ../out/versions.md "$GITHUB_STEP_SUMMARY"
172
+ FAILED=0
173
+ # The planned Ruby is a minor (2.7), an exact version (4.0.9), a pre-release (4.1.0-preview1, which calls
174
+ # itself 4.1.0) or head, a development build.
175
+ case "$PLANNED_RUBY" in
176
+ head) WANT=$RUBY; [ "$(jq -r .patchlevel ../out/installed.json)" = -1 ] || WANT="a development build" ;;
177
+ *) WANT=${PLANNED_RUBY%%-*} ;;
178
+ esac
179
+ case "$RUBY" in
180
+ "$WANT" | "$WANT".*) ;;
181
+ *) echo "::error::Ruby $RUBY is running, but the $LEG leg plans $PLANNED_RUBY."; FAILED=1 ;;
182
+ esac
183
+ if [ "$(installed logtail-rack)" != "$CLIENT" ]; then
184
+ echo "::error::logtail-rack $(installed logtail-rack) is installed, but the $LEG leg plans $CLIENT."
185
+ FAILED=1
186
+ fi
187
+ if [ "$CLIENT_FROM" = checkout ]; then
188
+ # The gem Bundler loads is the one built here, byte for byte, not the rubygems.org release of the same
189
+ # version, and its lib/ is the checkout's, file for file.
190
+ if ! cmp -s "../logtail-rack-$CLIENT.gem" "$(jq -r .client_cache ../out/installed.json)"; then
191
+ echo "::error::Bundler loads logtail-rack $CLIENT from $(jq -r .client_cache ../out/installed.json), which is not the gem built here."
192
+ FAILED=1
193
+ fi
194
+ if ! diff -r ../lib "$(jq -r .client_path ../out/installed.json)/lib" > ../out/client.diff; then
195
+ head -n 20 ../out/client.diff
196
+ echo "::error::The installed logtail-rack's lib/ in $(jq -r .client_path ../out/installed.json) differs from the checkout's lib/."
197
+ FAILED=1
198
+ fi
199
+ fi
200
+ # The canary takes rack's main branch and only reports what that is.
201
+ if [ "$PLANNED_RACK" != main ] && [ "$RACK" != "$PLANNED_RACK" ]; then
202
+ echo "::error::rack $RACK is installed, but the $LEG leg plans $PLANNED_RACK."
203
+ FAILED=1
204
+ fi
205
+ if [ "$LOGTAIL" != "$PLANNED_LOGTAIL" ]; then
206
+ echo "::error::logtail $LOGTAIL is installed, but the $LEG leg plans $PLANNED_LOGTAIL."
207
+ FAILED=1
208
+ fi
209
+ exit "$FAILED"
210
+
211
+ # Before a source is created: middlewares that cannot even load with these versions need no round trip.
212
+ - name: "[Verify] The middlewares load with these versions"
213
+ working-directory: example-project
214
+ run: |
215
+ if ! bundle exec ruby -e 'require "logtail-rack"; Logtail::Integrations::Rack::HTTPEvents' > ../out/load.log 2>&1; then
216
+ cat ../out/load.log
217
+ echo "::error::require \"logtail-rack\" failed on $(ruby -v): $(grep -m 1 'Error' ../out/load.log || tail -n 1 ../out/load.log)"
218
+ exit 1
219
+ fi
220
+ # Warnings, if any.
221
+ cat ../out/load.log
222
+
223
+ - name: "[Setup] Create a source"
224
+ id: source
225
+ uses: ./.github/actions/create-source
226
+ with:
227
+ api-token: ${{ secrets.TEST_TEAM_TELEMETRY_API }}
228
+ name: e2e-rack-gh${{ github.run_id }}a${{ github.run_attempt }}-${{ matrix.leg }}
229
+ platform: ruby
230
+
231
+ - name: "[Test] Run the example project"
232
+ env:
233
+ BETTER_STACK_SOURCE_TOKEN: ${{ steps.source.outputs.token }}
234
+ BETTER_STACK_INGESTING_HOST: ${{ steps.source.outputs.ingesting-host }}
235
+ run: bash e2e/example.sh
236
+
237
+ - name: "[Verify] Read the rows back"
238
+ uses: ./.github/actions/verify-logs
239
+ with:
240
+ connection-username: ${{ secrets.TEST_TEAM_CONNECTION_USERNAME }}
241
+ connection-password: ${{ secrets.TEST_TEAM_CONNECTION_PASSWORD }}
242
+ connect-host: ${{ steps.source.outputs.connect-host }}
243
+ collection: ${{ steps.source.outputs.collection }}
244
+ expected: e2e/expected.json
245
+
246
+ - name: "[Cleanup] Delete this job's source and stale ones of earlier runs"
247
+ if: ${{ always() }}
248
+ uses: ./.github/actions/cleanup-sources
249
+ with:
250
+ api-token: ${{ secrets.TEST_TEAM_TELEMETRY_API }}
251
+ prefix: e2e-rack-
252
+ id: ${{ steps.source.outputs.id }}
253
+
254
+ - name: "[Report] Job summary"
255
+ if: ${{ always() }}
256
+ run: |
257
+ if [ -f out/summary.md ]; then
258
+ { echo; cat out/summary.md; } >> "$GITHUB_STEP_SUMMARY"
259
+ # The Linear issue names the job and links the run, so it gets the versions, the read-back and the
260
+ # cleanup only when that left something behind. Without a read-back summary the notifier takes the
261
+ # job's ::error:: lines instead.
262
+ mkdir -p report
263
+ { cat out/versions.md; echo; cat out/summary.md; } > report/summary.md
264
+ if grep -q '❌' out/cleanup.md 2>/dev/null; then { echo; cat out/cleanup.md; } >> report/summary.md; fi
265
+ else
266
+ { echo; echo "❌ Stopped before the rows were read back, see the failed step."; } >> "$GITHUB_STEP_SUMMARY"
267
+ fi
268
+ if [ -f out/cleanup.md ]; then { echo; cat out/cleanup.md; } >> "$GITHUB_STEP_SUMMARY"; fi
269
+
270
+ - name: "[Report] Hand the summary to the Linear issue"
271
+ if: ${{ always() }}
272
+ uses: actions/upload-artifact@v7
273
+ with:
274
+ name: e2e-summary-${{ matrix.name }}
275
+ path: report/summary.md
276
+ if-no-files-found: ignore
277
+ retention-days: 7
278
+ # A re-run attempt uploads under the same name.
279
+ overwrite: true
280
+
281
+ notify-linear:
282
+ if: ${{ failure() && (github.ref == 'refs/heads/main' || github.event_name == 'schedule') }}
283
+ needs: [test]
284
+ # The notifier reads the failed jobs, their summary artifacts and their annotations.
285
+ permissions:
286
+ contents: read
287
+ actions: read
288
+ checks: read
289
+ uses: ./.github/workflows/notify_linear_failure.yml
290
+ with:
291
+ job_summaries: true
292
+ secrets: inherit
@@ -4,8 +4,6 @@ on:
4
4
  push:
5
5
  branches: [main]
6
6
  pull_request:
7
- schedule:
8
- - cron: '20 5 * * 1'
9
7
  workflow_dispatch:
10
8
 
11
9
  jobs:
@@ -18,7 +16,6 @@ jobs:
18
16
  matrix:
19
17
  ruby-version:
20
18
  - "4.0"
21
- - "3"
22
19
  - "3.4"
23
20
  - "3.3"
24
21
  - "3.2"