logtail 0.1.21 → 0.1.22

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: b6611815d9d52cb947f7f547e988273c8d51a9663a906e6cebbb182a7df4029b
4
- data.tar.gz: 99a3d5b9d3d6ced5187948f4bdb8f21435d0a7ee7c323431b49eb4944b6e5583
3
+ metadata.gz: 84414eb8a10b295d9bf8629509de491717403874ad1bbef6f4fabdb5b4134fd8
4
+ data.tar.gz: 6837e1d87cfa646cf009c3813523b4c7da902d778983ad3f4cf2687e4c634691
5
5
  SHA512:
6
- metadata.gz: 537aeaf25913ebd410554a3f1b9d8c6e49736d93a6ab180f45b84b88ee64656d4a34ce2193cdf52b3b439da5a02a4a5cad1404cb16c5cdd45156e5e6629071db
7
- data.tar.gz: 83f2a2915f94e1864d078fe10c10f65d2b420ee3610d27f085c3dd7de45d5de6f63db859180b8922563b6d48c1f4be6a2e130689fcea9a0d419adc5352640705
6
+ metadata.gz: ab2d5306bc84875a365f0e47493a8b3597e14e7cf2a370f8dae7fd731d7e643d458029708cfc84070c673ed0286438b294d87905589d94bd1ea14d2f443bfb75
7
+ data.tar.gz: 48c1a7a0aad9f56e9ffe5cbc5a9cd44fd7befdaae602cbabaefd5ae51ef3ea377a1ae014b6ba959b30a68f252d3f6da511f3571dbe8ee38b936c7c0a615c8a3c
@@ -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,293 @@
1
+ name: E2E
2
+
3
+ # Proves that the client still delivers logs to Better Stack. Every job creates its own ruby source through the
4
+ # Telemetry API, warms it up, runs example-project/main.rb (what its README tells customers to run) with that source's
5
+ # token and ingesting host, reads the stored rows back through the testing team's SQL API connection, checks them
6
+ # exactly against e2e/expected.json (nothing missing, extra or duplicated, and the line the example filters out not
7
+ # stored), and deletes the source again, together with sources of earlier runs left behind for more than 3 hours.
8
+ # e2e/plan.rb plans three legs:
9
+ # floor the oldest Ruby, msgpack and logger logtail.gemspec declares (required_ruby_version and the oldest
10
+ # releases its requirements accept)
11
+ # latest the newest stable Ruby with the newest msgpack and logger releases
12
+ # canary ruby-head with the newest msgpack and logger releases
13
+ # The floor leg runs on the oldest Ubuntu image GitHub offers, latest and canary on ubuntu-latest, so a new runner image
14
+ # is covered as well.
15
+ # Every job installs exactly the planned versions and checks, before it creates a source, that the Ruby running, the
16
+ # client (the gem built here, or rubygems.org on the schedule) and the msgpack and logger versions are the planned ones,
17
+ # and writes them into its summary. Pushes to main and pull requests install the gem built from the checkout. The daily
18
+ # schedule installs the newest release from rubygems.org, which is what a customer gets today. A failure on main or on
19
+ # the schedule files a Linear issue (notify_linear_failure.yml), at low priority when only the canary failed.
20
+ # Pull requests from forks run only the plan: they get no secrets, so they cannot create a source.
21
+ #
22
+ # Secrets: TEST_TEAM_TELEMETRY_API, TEST_TEAM_CONNECTION_USERNAME, TEST_TEAM_CONNECTION_PASSWORD (Better Stack's E2E
23
+ # testing team), LINEAR_* (see notify_linear_failure.yml).
24
+ #
25
+ # One leg, or exact versions: Actions → E2E → Run workflow, pick the leg and optionally set ruby-version (e.g. 3.2.6 or
26
+ # head), msgpack-version or logger-version, which replace the planned versions of every leg that runs. That is how a
27
+ # failure is bisected to one release.
28
+
29
+ on:
30
+ push:
31
+ branches: [main]
32
+ pull_request:
33
+ schedule:
34
+ - cron: '45 6 * * *'
35
+ workflow_dispatch:
36
+ inputs:
37
+ leg:
38
+ description: 'Leg to run'
39
+ type: choice
40
+ options: [all, floor, latest, canary]
41
+ default: all
42
+ source:
43
+ 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'
44
+ type: choice
45
+ options: [checkout, rubygems]
46
+ default: checkout
47
+ ruby-version:
48
+ description: 'One Ruby version (e.g. 3.2.6 or head) instead of the planned one'
49
+ type: string
50
+ msgpack-version:
51
+ description: 'One exact msgpack version (e.g. 1.4.2) instead of the planned one'
52
+ type: string
53
+ logger-version:
54
+ description: 'One exact logger version (e.g. 1.5.3) instead of the planned one'
55
+ type: string
56
+
57
+ permissions:
58
+ contents: read
59
+
60
+ defaults:
61
+ run:
62
+ # -eo pipefail: a failed ruby in front of a pipe fails the step.
63
+ shell: bash
64
+
65
+ jobs:
66
+ plan:
67
+ runs-on: ubuntu-24.04
68
+ outputs:
69
+ matrix: ${{ steps.plan.outputs.matrix }}
70
+
71
+ steps:
72
+ - name: "[Setup] Checkout code"
73
+ uses: actions/checkout@v7
74
+
75
+ - name: "[Setup] Ruby"
76
+ uses: ruby/setup-ruby@v1
77
+ with:
78
+ ruby-version: ruby
79
+
80
+ - name: "[Test] plan_test.rb"
81
+ run: ruby e2e/plan_test.rb
82
+
83
+ - name: "[Setup] Plan the legs"
84
+ id: plan
85
+ env:
86
+ LEG: ${{ inputs.leg || 'all' }}
87
+ RUBY: ${{ inputs.ruby-version }}
88
+ MSGPACK: ${{ inputs.msgpack-version }}
89
+ LOGGER: ${{ inputs.logger-version }}
90
+ # The schedule tests what a customer installs today, pushes and pull requests test the checkout.
91
+ CLIENT_FROM: ${{ github.event_name == 'schedule' && 'rubygems' || inputs.source || 'checkout' }}
92
+ run: |
93
+ MATRIX=$(ruby e2e/plan.rb --leg "$LEG" --ruby "$RUBY" --msgpack "$MSGPACK" --logger "$LOGGER" --source "$CLIENT_FROM")
94
+ echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
95
+ jq . <<<"$MATRIX"
96
+
97
+ test:
98
+ needs: plan
99
+ name: ${{ matrix.name }}
100
+ # Forks and Dependabot get no repository secrets, so their pull requests run only the plan.
101
+ if: ${{ github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') }}
102
+ runs-on: ${{ matrix.runner }}
103
+ timeout-minutes: 20
104
+ strategy:
105
+ fail-fast: false
106
+ matrix:
107
+ include: ${{ fromJSON(needs.plan.outputs.matrix) }}
108
+
109
+ env:
110
+ LEG: ${{ matrix.leg }}
111
+ CLIENT_FROM: ${{ matrix.source }}
112
+ CLIENT: ${{ matrix.client }}
113
+ PLANNED_RUBY: ${{ matrix.ruby }}
114
+ PLANNED_MSGPACK: ${{ matrix.msgpack }}
115
+ PLANNED_LOGGER: ${{ matrix.logger }}
116
+
117
+ steps:
118
+ - name: "[Setup] Checkout code"
119
+ uses: actions/checkout@v7
120
+
121
+ - name: "[Setup] Ruby ${{ matrix.ruby }}"
122
+ uses: ruby/setup-ruby@v1
123
+ with:
124
+ ruby-version: ${{ matrix.ruby }}
125
+
126
+ # Exact versions, so that a release that does not support this Ruby fails here and names itself, instead of an
127
+ # older one being installed quietly.
128
+ - name: "[Setup] Install msgpack and logger at the leg's versions"
129
+ run: |
130
+ gem install --no-document msgpack -v "$PLANNED_MSGPACK"
131
+ gem install --no-document logger -v "$PLANNED_LOGGER"
132
+
133
+ - name: "[Setup] Install the client"
134
+ run: |
135
+ if [ "$CLIENT_FROM" = rubygems ]; then
136
+ gem install --no-document logtail -v "$CLIENT"
137
+ else
138
+ # The gem the Release workflow builds and pushes to rubygems.org.
139
+ gem build logtail.gemspec
140
+ gem install --no-document --local "logtail-$CLIENT.gem"
141
+ fi
142
+
143
+ # The example's Gemfile asks for logtail from rubygems.org, as a customer's does. The job pins it in place to
144
+ # the gem installed above, adds msgpack and logger at the leg's versions, and bundles with --local: bundler then
145
+ # resolves from the installed gems only and cannot fetch a release of the same version from rubygems.org.
146
+ - name: "[Setup] Bundle the example with these versions"
147
+ working-directory: example-project
148
+ run: |
149
+ grep -q '^gem "logtail"' Gemfile || { echo '::error::example-project/Gemfile has no gem "logtail" line to pin.'; exit 1; }
150
+ sed -i "s/^gem \"logtail\".*/gem \"logtail\", \"= $CLIENT\"/" Gemfile
151
+ printf 'gem "msgpack", "= %s"\ngem "logger", "= %s"\n' "$PLANNED_MSGPACK" "$PLANNED_LOGGER" >> Gemfile
152
+ cat Gemfile
153
+ bundle install --local
154
+
155
+ # What the example runs with, read through bundler from example-project/, where the checkout's lib/ is not on
156
+ # the load path.
157
+ - name: "[Verify] Installed versions are the planned ones"
158
+ working-directory: example-project
159
+ run: |
160
+ loaded() { bundle exec ruby -e "print $1"; }
161
+ RUBY=$(loaded RUBY_VERSION)
162
+ LOGTAIL=$(loaded 'Gem.loaded_specs.fetch("logtail").version')
163
+ MSGPACK=$(loaded 'Gem.loaded_specs.fetch("msgpack").version')
164
+ LOGGER=$(loaded 'Gem.loaded_specs.fetch("logger").version')
165
+ if [ "$CLIENT_FROM" = checkout ]; then FROM="the gem built here"; else FROM="rubygems.org"; fi
166
+ mkdir -p ../out
167
+ echo "- $(loaded RUBY_DESCRIPTION), logtail $LOGTAIL from $FROM, msgpack $MSGPACK, logger $LOGGER" | tee -a ../out/versions.md "$GITHUB_STEP_SUMMARY"
168
+ FAILED=0
169
+ # The planned Ruby is a minor (2.3), an exact version (4.0.9) or head, which is a development build.
170
+ if [ "$PLANNED_RUBY" = head ]; then
171
+ [ "$(loaded RUBY_PATCHLEVEL)" = -1 ] || { echo "::error::Ruby $RUBY is running, a release, but the $LEG leg plans ruby-head."; FAILED=1; }
172
+ else
173
+ case "$RUBY" in
174
+ "$PLANNED_RUBY" | "$PLANNED_RUBY".*) ;;
175
+ *) echo "::error::Ruby $RUBY is running, but the $LEG leg plans $PLANNED_RUBY."; FAILED=1 ;;
176
+ esac
177
+ fi
178
+ for check in "logtail $LOGTAIL $CLIENT" "msgpack $MSGPACK $PLANNED_MSGPACK" "logger $LOGGER $PLANNED_LOGGER"; do
179
+ read -r name got want <<<"$check"
180
+ if [ "$got" != "$want" ]; then
181
+ echo "::error::$name $got is installed, but the $LEG leg plans $want."
182
+ FAILED=1
183
+ fi
184
+ done
185
+ if [ "$CLIENT_FROM" = checkout ]; then
186
+ # The installed gem is the one built here, byte for byte (rubygems keeps a copy of the .gem it installed),
187
+ # and holds the checkout's lib/, file for file.
188
+ if ! cmp -s "../logtail-$CLIENT.gem" "$(loaded 'Gem.loaded_specs.fetch("logtail").cache_file')"; then
189
+ echo "::error::The installed logtail $LOGTAIL is not the gem built here, logtail-$CLIENT.gem."
190
+ FAILED=1
191
+ fi
192
+ INSTALLED_DIR=$(loaded 'Gem.loaded_specs.fetch("logtail").full_gem_path')
193
+ if ! diff -r ../lib "$INSTALLED_DIR/lib" > ../out/client.diff; then
194
+ head -n 20 ../out/client.diff
195
+ echo "::error::The installed gem's lib/ in $INSTALLED_DIR differs from the checkout's lib/ directory."
196
+ FAILED=1
197
+ fi
198
+ fi
199
+ exit "$FAILED"
200
+
201
+ # Before a source is created: a client that cannot even load with these versions needs no round trip.
202
+ - name: "[Verify] The client loads with these versions"
203
+ working-directory: example-project
204
+ run: |
205
+ if ! bundle exec ruby -e 'require "logtail"; Logtail::Logger.new(Logtail::LogDevices::HTTP.new("e2e"))' 2> ../out/load.log; then
206
+ cat ../out/load.log
207
+ echo "::error::require \"logtail\" failed on Ruby $(ruby -e 'print RUBY_VERSION'): $(head -n 1 ../out/load.log)"
208
+ exit 1
209
+ fi
210
+ # Warnings, if any.
211
+ cat ../out/load.log
212
+
213
+ - name: "[Setup] Create a source"
214
+ id: source
215
+ uses: ./.github/actions/create-source
216
+ with:
217
+ api-token: ${{ secrets.TEST_TEAM_TELEMETRY_API }}
218
+ name: e2e-ruby-gh${{ github.run_id }}a${{ github.run_attempt }}-${{ matrix.leg }}
219
+ platform: ruby
220
+
221
+ # The example closes the logger before it prints "All done", which delivers what is still buffered. The client
222
+ # reports a batch Better Stack rejects with a warning on stderr only, so the job looks for that warning.
223
+ - name: "[Test] Run the example project"
224
+ working-directory: example-project
225
+ env:
226
+ BETTER_STACK_SOURCE_TOKEN: ${{ steps.source.outputs.token }}
227
+ BETTER_STACK_INGESTING_HOST: ${{ steps.source.outputs.ingesting-host }}
228
+ run: |
229
+ if ! bundle exec ruby main.rb 2>&1 | tee ../out/example.log; then
230
+ echo "::error::The example project failed: $(tail -n 1 ../out/example.log)"
231
+ exit 1
232
+ fi
233
+ if grep -q '^Logtail: Better Stack rejected' ../out/example.log; then
234
+ echo "::error::$(grep -m 1 '^Logtail: Better Stack rejected' ../out/example.log)"
235
+ exit 1
236
+ fi
237
+
238
+ - name: "[Verify] Read the rows back"
239
+ uses: ./.github/actions/verify-logs
240
+ with:
241
+ connection-username: ${{ secrets.TEST_TEAM_CONNECTION_USERNAME }}
242
+ connection-password: ${{ secrets.TEST_TEAM_CONNECTION_PASSWORD }}
243
+ connect-host: ${{ steps.source.outputs.connect-host }}
244
+ collection: ${{ steps.source.outputs.collection }}
245
+ expected: e2e/expected.json
246
+
247
+ - name: "[Cleanup] Delete this job's source and stale ones of earlier runs"
248
+ if: ${{ always() }}
249
+ uses: ./.github/actions/cleanup-sources
250
+ with:
251
+ api-token: ${{ secrets.TEST_TEAM_TELEMETRY_API }}
252
+ prefix: e2e-ruby-
253
+ id: ${{ steps.source.outputs.id }}
254
+
255
+ - name: "[Report] Job summary"
256
+ if: ${{ always() }}
257
+ run: |
258
+ if [ -f out/summary.md ]; then
259
+ { echo; cat out/summary.md; } >> "$GITHUB_STEP_SUMMARY"
260
+ # The Linear issue names the job and links the run, so it gets the versions, the read-back and the
261
+ # cleanup only when that left something behind. Without a read-back summary the notifier takes the
262
+ # job's ::error:: lines instead.
263
+ mkdir -p report
264
+ { cat out/versions.md; echo; cat out/summary.md; } > report/summary.md
265
+ if grep -q '❌' out/cleanup.md 2>/dev/null; then { echo; cat out/cleanup.md; } >> report/summary.md; fi
266
+ else
267
+ { echo; echo "❌ Stopped before the rows were read back, see the failed step."; } >> "$GITHUB_STEP_SUMMARY"
268
+ fi
269
+ if [ -f out/cleanup.md ]; then { echo; cat out/cleanup.md; } >> "$GITHUB_STEP_SUMMARY"; fi
270
+
271
+ - name: "[Report] Hand the summary to the Linear issue"
272
+ if: ${{ always() }}
273
+ uses: actions/upload-artifact@v7
274
+ with:
275
+ name: e2e-summary-${{ matrix.name }}
276
+ path: report/summary.md
277
+ if-no-files-found: ignore
278
+ retention-days: 7
279
+ # A re-run attempt uploads under the same name.
280
+ overwrite: true
281
+
282
+ notify-linear:
283
+ if: ${{ failure() && (github.ref == 'refs/heads/main' || github.event_name == 'schedule') }}
284
+ needs: [test]
285
+ # The notifier reads the failed jobs, their summary artifacts and their annotations.
286
+ permissions:
287
+ contents: read
288
+ actions: read
289
+ checks: read
290
+ uses: ./.github/workflows/notify_linear_failure.yml
291
+ with:
292
+ job_summaries: true
293
+ 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"
@@ -0,0 +1,153 @@
1
+ name: "Notify Linear on failure"
2
+
3
+ # Files a Linear issue for a failed run: "E2E failure: <workflow name> (<owner/repo>)" at High priority, listing the
4
+ # failed jobs and steps with their errors, or with their summaries when job_summaries is set. When every failed job's
5
+ # name starts with "canary" (pre-release runtime or dependencies), the title says "E2E canary failure" and the
6
+ # priority is Low. While an issue with the same title is still open, the run is added to it as a comment instead,
7
+ # so a test that keeps failing every day makes one issue, not one per day.
8
+ # Secrets: LINEAR_API_KEY, LINEAR_TEAM_TELEMETRY_ID, LINEAR_STATUS_PLAN_ID, LINEAR_PROJECT_INGESTION_FOR_EVERYTHING_ID,
9
+ # LINEAR_ASSIGNEE_PETR_ID.
10
+ on:
11
+ workflow_call:
12
+ inputs:
13
+ job_summaries:
14
+ description: >-
15
+ Adds each failed job's summary to the issue, or its errors when it has none. A job hands its summary over as
16
+ an artifact named "e2e-summary-<job name>" holding summary.md.
17
+ type: boolean
18
+ default: false
19
+
20
+ jobs:
21
+ create-linear-issue:
22
+ runs-on: ubuntu-latest
23
+ # A caller must grant checks: read as well (the errors come from the annotations), or this job cannot start.
24
+ permissions:
25
+ contents: read
26
+ actions: read
27
+ checks: read
28
+ steps:
29
+ - name: "Gather failure context"
30
+ id: ctx
31
+ env:
32
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33
+ RUN_ID: ${{ github.event.workflow_run.id || github.run_id }}
34
+ RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt || github.run_attempt }}
35
+ JOB_SUMMARIES: ${{ inputs.job_summaries }}
36
+ run: |
37
+ JOBS=$(gh api \
38
+ "repos/${{ github.repository }}/actions/runs/$RUN_ID/attempts/$RUN_ATTEMPT/jobs" \
39
+ --paginate \
40
+ --jq '.jobs[]
41
+ | select(.conclusion == "failure")
42
+ | {id, name, steps: ([.steps[] | select(.conclusion == "failure") | .name] | join(", "))}
43
+ | @json')
44
+
45
+ FAILED=""
46
+ while read -r job; do
47
+ [ -n "$job" ] || continue
48
+ ID=$(jq -r .id <<<"$job")
49
+ NAME=$(jq -r .name <<<"$job")
50
+ STEPS=$(jq -r .steps <<<"$job")
51
+ FAILED="$FAILED### $NAME"$'\n\n'"Failed at **${STEPS}**"$'\n\n'
52
+ # A job's summary already says why it failed. Otherwise, or when the job stopped before writing it, the
53
+ # issue gets its ::error:: lines, without the runner's closing "Process completed with exit code 1."
54
+ SUMMARY_DIR="summaries/$ID"
55
+ if [ "$JOB_SUMMARIES" = true ]; then
56
+ gh run download "$RUN_ID" -R "${{ github.repository }}" -n "e2e-summary-$NAME" -D "$SUMMARY_DIR" >/dev/null 2>&1 || true
57
+ fi
58
+ if [ -f "$SUMMARY_DIR/summary.md" ]; then
59
+ FAILED="$FAILED$(cat "$SUMMARY_DIR/summary.md")"$'\n\n'
60
+ else
61
+ ERRORS=$(gh api "repos/${{ github.repository }}/check-runs/$ID/annotations" \
62
+ --jq '[.[] | select(.annotation_level == "failure" and (.message | startswith("Process completed with exit code") | not)) | .message | gsub("\n"; " ")] | unique | .[] | "- \(.)"') || ERRORS=""
63
+ FAILED="$FAILED${ERRORS:+$ERRORS$'\n\n'}"
64
+ fi
65
+ done <<<"$JOBS"
66
+ # Canary only when there are failed jobs and all of them are canary jobs.
67
+ CANARY=false
68
+ if [ -n "$JOBS" ] && jq -se 'all(.[]; .name | startswith("canary"))' <<<"$JOBS" >/dev/null; then CANARY=true; fi
69
+
70
+ while [[ "$FAILED" == *$'\n' ]]; do FAILED="${FAILED%$'\n'}"; done
71
+ if [ -z "$FAILED" ]; then
72
+ FAILED="_(no failed jobs reported by the API yet)_"
73
+ elif [ "${#FAILED}" -gt 20000 ]; then
74
+ FAILED="${FAILED:0:20000}"$'\n\n'"_(cut at 20,000 characters, the rest is in the run)_"
75
+ fi
76
+ printf '%s\n' "$FAILED" > failed_jobs.md
77
+ echo "canary=$CANARY" >> "$GITHUB_OUTPUT"
78
+
79
+ - name: "Create the Linear issue, or comment on the open one with the same title"
80
+ env:
81
+ LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
82
+ LINEAR_TEAM_ID: ${{ secrets.LINEAR_TEAM_TELEMETRY_ID }}
83
+ LINEAR_STATUS_PLAN_ID: ${{ secrets.LINEAR_STATUS_PLAN_ID }}
84
+ LINEAR_PROJECT_INGESTION_FOR_EVERYTHING_ID: ${{ secrets.LINEAR_PROJECT_INGESTION_FOR_EVERYTHING_ID }}
85
+ LINEAR_ASSIGNEE_PETR_ID: ${{ secrets.LINEAR_ASSIGNEE_PETR_ID }}
86
+ CANARY: ${{ steps.ctx.outputs.canary }}
87
+ REPOSITORY: ${{ github.repository }}
88
+ WORKFLOW: ${{ github.event.workflow_run.name || github.workflow }}
89
+ REF_NAME: ${{ github.event.workflow_run.head_branch || github.ref_name }}
90
+ RUN_URL: ${{ github.event.workflow_run.html_url || format('{0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id) }}
91
+ RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt || github.run_attempt }}
92
+ EVENT_NAME: ${{ github.event.workflow_run.event || github.event_name }}
93
+ SHA: ${{ github.event.workflow_run.head_sha || github.sha }}
94
+ COMMIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message || github.event.head_commit.message }}
95
+ run: |
96
+ if [ "$CANARY" = true ]; then
97
+ TITLE="E2E canary failure: $WORKFLOW ($REPOSITORY)"; PRIORITY=4
98
+ else
99
+ TITLE="E2E failure: $WORKFLOW ($REPOSITORY)"; PRIORITY=2
100
+ fi
101
+
102
+ # head_commit is only populated on push events; skip the subject otherwise
103
+ COMMIT_LINE="**Commit:** \`${SHA:0:7}\`"
104
+ [ -z "$COMMIT_MESSAGE" ] || COMMIT_LINE="$COMMIT_LINE: $(printf '%s' "$COMMIT_MESSAGE" | head -n1)"
105
+ ATTEMPT_NOTE=""
106
+ [ "$RUN_ATTEMPT" = 1 ] || ATTEMPT_NOTE=" (attempt #$RUN_ATTEMPT)"
107
+ {
108
+ echo "**$WORKFLOW** failed on \`$REF_NAME\` via \`$EVENT_NAME\`$ATTEMPT_NOTE"
109
+ echo
110
+ echo "**Failing jobs:**"
111
+ echo
112
+ cat failed_jobs.md
113
+ echo
114
+ echo "$COMMIT_LINE"
115
+ echo
116
+ echo "[View failing run]($RUN_URL)"
117
+ } > description.md
118
+
119
+ linear() {
120
+ curl -sS --fail-with-body -X POST https://api.linear.app/graphql \
121
+ -H "Authorization: $LINEAR_API_KEY" -H 'Content-Type: application/json' -d "$1"
122
+ }
123
+
124
+ # Open means any state but done, canceled or marked as a duplicate. Better a second issue than none: when the
125
+ # lookup fails, a new issue is created.
126
+ FIND=$(jq -nc --arg title "$TITLE" --arg teamId "$LINEAR_TEAM_ID" '{
127
+ query: "query ($title: String!, $teamId: ID!) { issues(filter: {title: {eq: $title}, team: {id: {eq: $teamId}}, state: {type: {nin: [\"completed\", \"canceled\", \"duplicate\"]}}}, first: 1) { nodes { id url } } }",
128
+ variables: {title: $title, teamId: $teamId}
129
+ }')
130
+ FOUND=$(linear "$FIND") || { echo "::warning::looking for an open issue titled \"$TITLE\" failed: $FOUND"; FOUND='{}'; }
131
+ OPEN=$(jq -r '.data.issues.nodes[0] // empty | "\(.id) \(.url)"' <<<"$FOUND")
132
+
133
+ if [ -n "$OPEN" ]; then
134
+ read -r ISSUE_ID ISSUE_URL <<<"$OPEN"
135
+ PAYLOAD=$(jq -nc --arg issueId "$ISSUE_ID" --rawfile body description.md '{
136
+ query: "mutation ($input: CommentCreateInput!) { commentCreate(input: $input) { success } }",
137
+ variables: {input: {issueId: $issueId, body: $body}}
138
+ }')
139
+ RES=$(linear "$PAYLOAD") || true
140
+ jq -e '.data.commentCreate.success' <<<"$RES" >/dev/null || { echo "::error::commenting on $ISSUE_URL failed: $RES"; exit 1; }
141
+ echo "added this run to the open issue $ISSUE_URL"
142
+ else
143
+ PAYLOAD=$(jq -nc --arg title "$TITLE" --rawfile description description.md --arg teamId "$LINEAR_TEAM_ID" \
144
+ --arg assigneeId "$LINEAR_ASSIGNEE_PETR_ID" --arg stateId "$LINEAR_STATUS_PLAN_ID" \
145
+ --arg projectId "$LINEAR_PROJECT_INGESTION_FOR_EVERYTHING_ID" --argjson priority "$PRIORITY" '{
146
+ query: "mutation ($input: IssueCreateInput!) { issueCreate(input: $input) { success issue { url } } }",
147
+ variables: {input: {title: $title, description: $description, teamId: $teamId, assigneeId: $assigneeId,
148
+ stateId: $stateId, projectId: $projectId, priority: $priority}}
149
+ }')
150
+ RES=$(linear "$PAYLOAD") || true
151
+ ISSUE_URL=$(jq -er '.data.issueCreate.issue.url' <<<"$RES") || { echo "::error::creating the issue failed: $RES"; exit 1; }
152
+ echo "created $ISSUE_URL"
153
+ fi
data/e2e/expected.json ADDED
@@ -0,0 +1,27 @@
1
+ [
2
+ {
3
+ "level": "debug",
4
+ "message": "Better Stack is ready!",
5
+ "contains": {"context": {"runtime": {"file": "main.rb", "frame_label": "<main>"}}}
6
+ },
7
+ {
8
+ "level": "info",
9
+ "message": "I am using Better Stack!",
10
+ "contains": {"context": {"runtime": {"file": "main.rb", "frame_label": "<main>"}}}
11
+ },
12
+ {
13
+ "level": "warn",
14
+ "message": "log structured data",
15
+ "contains": {"context": {"runtime": {"file": "main.rb", "frame_label": "<main>"}}, "item": {"url": "https://fictional-store.com/item-123", "price": 100.0}}
16
+ },
17
+ {
18
+ "level": "error",
19
+ "message": "Oops! An error occurred!",
20
+ "contains": {"context": {"runtime": {"file": "main.rb", "frame_label": "<main>"}}}
21
+ },
22
+ {
23
+ "level": "fatal",
24
+ "message": "Application crash! Needs to be fixed ASAP!",
25
+ "contains": {"context": {"runtime": {"file": "main.rb", "frame_label": "<main>"}}, "error": {"class": "ArgumentError", "message": "invalid value for Integer(): \"one hundred\"", "backtrace": ["main.rb:", "<main>"]}}
26
+ }
27
+ ]
data/e2e/plan.rb ADDED
@@ -0,0 +1,161 @@
1
+ # Prints the job matrix of the E2E workflow (.github/workflows/e2e.yml) as JSON.
2
+ #
3
+ # ruby e2e/plan.rb [--leg all|floor|latest|canary] [--ruby <version>] [--msgpack <exact>] [--logger <exact>] [--source checkout|rubygems]
4
+ #
5
+ # floor the oldest versions logtail.gemspec declares: the Ruby of required_ruby_version, and the oldest releases of
6
+ # msgpack and logger on rubygems.org that its requirements accept
7
+ # latest the newest stable Ruby that ruby/setup-ruby can install, with the newest msgpack and logger releases
8
+ # canary ruby-head with the newest msgpack and logger releases. A pre-release newer than those is only reported.
9
+ #
10
+ # --ruby, --msgpack and --logger replace the planned version of every leg with one exact version, which is how a run
11
+ # bisects a failure to one release. --source is copied into every entry: checkout installs the gem built from this
12
+ # checkout, rubygems installs the newest release of logtail from rubygems.org.
13
+ #
14
+ # Standard library only, so the plan job needs nothing but a Ruby.
15
+ require "json"
16
+ require "net/http"
17
+ require "optparse"
18
+ require "rubygems"
19
+
20
+ module Plan
21
+ ROOT = File.expand_path("..", __dir__)
22
+ SETUP_RUBY_VERSIONS_URL = "https://raw.githubusercontent.com/ruby/setup-ruby/v1/ruby-builder-versions.json".freeze
23
+ RUBYGEMS_VERSIONS_URL = "https://rubygems.org/api/v1/versions/%s.json".freeze
24
+ LEGS = %w[floor latest canary].freeze
25
+ DEPENDENCIES = %w[msgpack logger].freeze
26
+ # Job names become artifact names (e2e-summary-<job name>), which must not contain any of these.
27
+ NOT_IN_NAMES = ':"<>|*?/\\'.chars.freeze
28
+
29
+ module_function
30
+
31
+ # The Ruby that required_ruby_version (">= 2.3") names, as setup-ruby takes it: "2.3" installs the newest 2.3.x.
32
+ def ruby_floor(spec)
33
+ requirement = spec.required_ruby_version.requirements
34
+ unless requirement.size == 1 && requirement[0][0] == ">="
35
+ raise ArgumentError, "logtail.gemspec requires Ruby #{spec.required_ruby_version}, the plan reads only >= X.Y"
36
+ end
37
+ requirement[0][1].to_s
38
+ end
39
+
40
+ # The releases of a gem on rubygems.org, without pre-releases and platform builds (java, mingw), oldest first.
41
+ def releases(versions)
42
+ versions.select { |version| version["platform"] == "ruby" && !version["prerelease"] }
43
+ .map { |version| Gem::Version.new(version["number"]) }.sort
44
+ end
45
+
46
+ # The oldest release the gemspec's requirement for the dependency accepts.
47
+ def dependency_floor(spec, name, versions)
48
+ dependency = spec.runtime_dependencies.find { |candidate| candidate.name == name }
49
+ raise ArgumentError, "logtail.gemspec declares no dependency on #{name}" unless dependency
50
+
51
+ floor = releases(versions).find { |version| dependency.requirement.satisfied_by?(version) }
52
+ raise ArgumentError, "no release of #{name} satisfies #{dependency.requirement}" unless floor
53
+
54
+ floor.to_s
55
+ end
56
+
57
+ def newest_release(versions)
58
+ releases(versions).last.to_s
59
+ end
60
+
61
+ # The newest pre-release when it is newer than the newest release (msgpack 2.0.0.rc1 over 1.8.7), or nil.
62
+ def newer_prerelease(versions)
63
+ newest = releases(versions).last
64
+ versions.select { |version| version["platform"] == "ruby" && version["prerelease"] }
65
+ .map { |version| Gem::Version.new(version["number"]) }
66
+ .select { |version| newest.nil? || version > newest }.max&.to_s
67
+ end
68
+
69
+ # The newest X.Y.Z in setup-ruby's list of CRuby builds, which also holds previews, head and debug builds.
70
+ def newest_stable_ruby(builder_versions)
71
+ builder_versions.fetch("ruby").grep(/\A\d+\.\d+\.\d+\z/).max_by { |version| Gem::Version.new(version) }
72
+ end
73
+
74
+ def job_name(leg, ruby, msgpack, logger)
75
+ name = "#{leg} (Ruby #{ruby}, msgpack #{msgpack}, logger #{logger})"
76
+ unless (name.chars & NOT_IN_NAMES).empty?
77
+ raise ArgumentError, "job name #{name.inspect} contains one of #{NOT_IN_NAMES.join}, which artifact names do not allow"
78
+ end
79
+ name
80
+ end
81
+
82
+ def entry(leg, ruby, msgpack, logger, source, client)
83
+ {
84
+ leg: leg,
85
+ name: job_name(leg, ruby, msgpack, logger),
86
+ ruby: ruby,
87
+ msgpack: msgpack,
88
+ logger: logger,
89
+ source: source,
90
+ client: client,
91
+ # The floor runs on the oldest Ubuntu image GitHub offers, the other legs follow ubuntu-latest.
92
+ runner: leg == "floor" ? "ubuntu-24.04" : "ubuntu-latest",
93
+ }
94
+ end
95
+
96
+ # A registry hiccup at schedule time should not file a Linear issue, so the lookup is retried.
97
+ def fetch_json(url, attempts: 3)
98
+ @fetched ||= {}
99
+ @fetched[url] ||= begin
100
+ attempt = 0
101
+ begin
102
+ attempt += 1
103
+ response = Net::HTTP.get_response(URI(url))
104
+ raise "HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess)
105
+ JSON.parse(response.body)
106
+ rescue StandardError => error
107
+ abort "GET #{url} failed #{attempts} times, last: #{error.message}" if attempt == attempts
108
+ sleep 10
109
+ retry
110
+ end
111
+ end
112
+ end
113
+
114
+ def gem_versions(name)
115
+ fetch_json(format(RUBYGEMS_VERSIONS_URL, name))
116
+ end
117
+
118
+ def plan(leg, spec, source, client, ruby: "", msgpack: "", logger: "")
119
+ if leg == "floor"
120
+ ruby = ruby_floor(spec) if ruby.empty?
121
+ msgpack = dependency_floor(spec, "msgpack", gem_versions("msgpack")) if msgpack.empty?
122
+ logger = dependency_floor(spec, "logger", gem_versions("logger")) if logger.empty?
123
+ else
124
+ ruby = (leg == "latest" ? newest_stable_ruby(fetch_json(SETUP_RUBY_VERSIONS_URL)) : "head") if ruby.empty?
125
+ msgpack = newest_release(gem_versions("msgpack")) if msgpack.empty?
126
+ logger = newest_release(gem_versions("logger")) if logger.empty?
127
+ end
128
+ entry(leg, ruby, msgpack, logger, source, client)
129
+ end
130
+
131
+ def main(argv)
132
+ options = { leg: "all", ruby: "", msgpack: "", logger: "", source: "checkout" }
133
+ OptionParser.new do |parser|
134
+ parser.on("--leg LEG", ["all"] + LEGS) { |value| options[:leg] = value }
135
+ parser.on("--ruby VERSION", "one Ruby version for every leg instead of the planned one") { |value| options[:ruby] = value.strip }
136
+ parser.on("--msgpack VERSION", "one exact msgpack version for every leg instead of the planned one") { |value| options[:msgpack] = value.strip }
137
+ parser.on("--logger VERSION", "one exact logger version for every leg instead of the planned one") { |value| options[:logger] = value.strip }
138
+ parser.on("--source SOURCE", %w[checkout rubygems]) { |value| options[:source] = value }
139
+ end.parse!(argv)
140
+
141
+ # The gemspec lists its files with git ls-files, which needs the repository as the working directory.
142
+ spec = Dir.chdir(ROOT) { Gem::Specification.load("logtail.gemspec") } || abort("logtail.gemspec does not load")
143
+ # The checkout's version, or the newest release on rubygems.org, which a customer gets today.
144
+ client = options[:source] == "rubygems" ? newest_release(gem_versions("logtail")) : spec.version.to_s
145
+ legs = options[:leg] == "all" ? LEGS : [options[:leg]]
146
+ include = legs.map do |leg|
147
+ plan(leg, spec, options[:source], client, ruby: options[:ruby], msgpack: options[:msgpack], logger: options[:logger])
148
+ end
149
+ if legs.include?("canary")
150
+ DEPENDENCIES.each do |name|
151
+ prerelease = newer_prerelease(gem_versions(name))
152
+ warn "::notice::#{name} #{prerelease} is newer than its newest release, the canary installs the release" if prerelease
153
+ end
154
+ end
155
+ puts JSON.generate(include)
156
+ rescue ArgumentError, OptionParser::ParseError => error
157
+ abort error.message
158
+ end
159
+ end
160
+
161
+ Plan.main(ARGV) if $PROGRAM_NAME == __FILE__
data/e2e/plan_test.rb ADDED
@@ -0,0 +1,75 @@
1
+ # Tests the version picking of e2e/plan.rb on fixed registry answers: ruby e2e/plan_test.rb
2
+ require "minitest/autorun"
3
+ require_relative "plan"
4
+
5
+ class PlanTest < Minitest::Test
6
+ # As rubygems.org's versions API lists them, newest first, with platform builds and pre-releases.
7
+ MSGPACK = [
8
+ { "number" => "2.0.0.rc1", "platform" => "ruby", "prerelease" => true },
9
+ { "number" => "1.8.7", "platform" => "java", "prerelease" => false },
10
+ { "number" => "1.8.7", "platform" => "ruby", "prerelease" => false },
11
+ { "number" => "1.8.6", "platform" => "ruby", "prerelease" => false },
12
+ { "number" => "1.0.0", "platform" => "x86-mingw32", "prerelease" => false },
13
+ { "number" => "1.0.0", "platform" => "ruby", "prerelease" => false },
14
+ { "number" => "1.0.0.rc1", "platform" => "ruby", "prerelease" => true },
15
+ { "number" => "0.7.6", "platform" => "ruby", "prerelease" => false },
16
+ ].freeze
17
+ # logger never had a 1.0.0: the oldest 1.x on rubygems.org is 1.2.7.1, newer than 1.3.0 only by publication date.
18
+ LOGGER = [
19
+ { "number" => "1.7.0", "platform" => "ruby", "prerelease" => false },
20
+ { "number" => "1.3.0", "platform" => "ruby", "prerelease" => false },
21
+ { "number" => "1.2.8.1", "platform" => "ruby", "prerelease" => false },
22
+ { "number" => "1.2.7.1", "platform" => "ruby", "prerelease" => false },
23
+ ].freeze
24
+
25
+ def spec(required_ruby_version = ">= 2.3")
26
+ Gem::Specification.new do |spec|
27
+ spec.name = "logtail"
28
+ spec.version = "0.1.21"
29
+ spec.required_ruby_version = required_ruby_version
30
+ spec.add_dependency("msgpack", "~> 1.0")
31
+ spec.add_dependency("logger", "~> 1.0")
32
+ end
33
+ end
34
+
35
+ def test_ruby_floor_is_the_version_of_required_ruby_version
36
+ assert_equal "2.3", Plan.ruby_floor(spec)
37
+ end
38
+
39
+ def test_ruby_floor_refuses_anything_but_a_lower_bound
40
+ assert_raises(ArgumentError) { Plan.ruby_floor(spec([">= 2.3", "< 4"])) }
41
+ end
42
+
43
+ def test_dependency_floor_is_the_oldest_release_the_requirement_accepts
44
+ assert_equal "1.0.0", Plan.dependency_floor(spec, "msgpack", MSGPACK)
45
+ assert_equal "1.2.7.1", Plan.dependency_floor(spec, "logger", LOGGER)
46
+ end
47
+
48
+ def test_newest_release_skips_pre_releases_and_platform_builds
49
+ assert_equal "1.8.7", Plan.newest_release(MSGPACK)
50
+ assert_equal "1.7.0", Plan.newest_release(LOGGER)
51
+ end
52
+
53
+ def test_newer_prerelease_only_above_the_newest_release
54
+ assert_equal "2.0.0.rc1", Plan.newer_prerelease(MSGPACK)
55
+ assert_nil Plan.newer_prerelease(LOGGER)
56
+ end
57
+
58
+ def test_newest_stable_ruby_skips_previews_and_head
59
+ builder_versions = { "ruby" => ["3.4.9", "4.0.8", "4.0.9", "4.1.0-preview1", "head", "debug"] }
60
+ assert_equal "4.0.9", Plan.newest_stable_ruby(builder_versions)
61
+ end
62
+
63
+ def test_entry
64
+ assert_equal(
65
+ { leg: "floor", name: "floor (Ruby 2.3, msgpack 1.0.0, logger 1.2.7.1)", ruby: "2.3", msgpack: "1.0.0",
66
+ logger: "1.2.7.1", source: "checkout", client: "0.1.21", runner: "ubuntu-24.04" },
67
+ Plan.entry("floor", "2.3", "1.0.0", "1.2.7.1", "checkout", "0.1.21")
68
+ )
69
+ assert_equal "ubuntu-latest", Plan.entry("canary", "head", "1.8.7", "1.7.0", "rubygems", "0.1.21")[:runner]
70
+ end
71
+
72
+ def test_job_names_refuse_what_artifact_names_do_not_allow
73
+ assert_raises(ArgumentError) { Plan.job_name("latest", "4.0.9", "1.8.7", "1.7.0 / 2.0") }
74
+ end
75
+ end
@@ -10,7 +10,7 @@ You can download the example project from GitHub directly or you can clone it to
10
10
  bundle install
11
11
  ```
12
12
 
13
- This will install all dependencies listed in the `Gemfile.lock` file.
13
+ This will install the `logtail` gem the `Gemfile` asks for, with its dependencies.
14
14
 
15
15
  Alternatively, add `gem "logtail"` to your `Gemfile` manually and then run `bundle install`.
16
16
 
@@ -18,13 +18,13 @@ Alternatively, add `gem "logtail"` to your `Gemfile` manually and then run `bund
18
18
 
19
19
  _Don't forget to replace `<source_token>` and `<ingesting_host>` with your actual source token and ingesting host which you can find by going to **[Sources](https://telemetry.betterstack.com/team/0/sources) -> Configure** in Better Stack._
20
20
 
21
- To run the example application, run the following command adding your source token:
21
+ To run the example application, run the following command adding your source token and ingesting host:
22
22
 
23
23
  ```bash
24
- bundle exec ruby main.rb <source_token> <ingesting_host>
24
+ BETTER_STACK_SOURCE_TOKEN=<source_token> BETTER_STACK_INGESTING_HOST=<ingesting_host> bundle exec ruby main.rb
25
25
  ```
26
26
 
27
- This will create a total of 5 different logs, each corresponding to a different log level. You can review these logs in Logtail.
27
+ This will create a total of 5 different logs, each corresponding to a different log level, and skip one more that is filtered out. You can review these logs in Logtail.
28
28
 
29
29
  # Logging
30
30
 
@@ -6,13 +6,16 @@
6
6
  # Include logtail library
7
7
  require "logtail"
8
8
 
9
- # Check for program arguments
10
- if ARGV.length != 2
11
- puts "Program needs source token and ingesting host to run. Run the program as followed\nbundle exec ruby main.rb <source_token> <ingesting_host>"
12
- exit
9
+ # Read the source token and ingesting host from the environment
10
+ source_token = ENV["BETTER_STACK_SOURCE_TOKEN"].to_s
11
+ ingesting_host = ENV["BETTER_STACK_INGESTING_HOST"].to_s
12
+ if source_token.empty? || ingesting_host.empty?
13
+ puts "Program needs source token and ingesting host to run. Run the program as followed\nBETTER_STACK_SOURCE_TOKEN=<source_token> BETTER_STACK_INGESTING_HOST=<ingesting_host> bundle exec ruby main.rb"
14
+ exit 1
13
15
  end
16
+
14
17
  # Create logger
15
- http_device = Logtail::LogDevices::HTTP.new(ARGV[0], ingesting_host: ARGV[1])
18
+ http_device = Logtail::LogDevices::HTTP.new(source_token, ingesting_host: ingesting_host)
16
19
  logger = Logtail::Logger.new(http_device)
17
20
 
18
21
  # Filter logs that shouldn't be sent to Better Stack, see {Logtail::LogEntry} for available attributes
@@ -43,6 +46,21 @@ logger.info("This message will not be sent to Better Stack because it contains '
43
46
  logger.error("Oops! An error occurred!")
44
47
 
45
48
  # Send messages about fatal events that caused the app to crash using the fatal() method
46
- logger.fatal("Application crash! Needs to be fixed ASAP!")
49
+ # Log a rescued exception with its class, message and backtrace as structured data
50
+ begin
51
+ Integer("one hundred")
52
+ rescue ArgumentError => exception
53
+ logger.fatal(
54
+ "Application crash! Needs to be fixed ASAP!",
55
+ error: {
56
+ class: exception.class.name,
57
+ message: exception.message,
58
+ backtrace: exception.backtrace
59
+ }
60
+ )
61
+ end
62
+
63
+ # Close the logger to send the remaining logs to Better Stack before the program ends
64
+ logger.close
47
65
 
48
66
  puts "All done! You can check your logs now."
@@ -286,7 +286,8 @@ Logtail::Config.instance.debug_logger = ::Logger.new(STDOUT)
286
286
  # Entries are encoded one at a time, so one that can't be encoded doesn't lose the batch.
287
287
  packer = MessagePack::DefaultFactory.packer
288
288
  uncompressed = packer.write_array_header(msgs.size).to_s
289
- packer.reset
289
+ # #clear, not #reset: msgpack before 1.4.5, which the gemspec allows, has only #clear
290
+ packer.clear
290
291
  msgs.each { |msg| uncompressed << encode_log_entry(msg, packer) }
291
292
  req.body = Zlib::Deflate.deflate(uncompressed, Zlib::BEST_SPEED)
292
293
  req
@@ -307,7 +308,7 @@ Logtail::Config.instance.debug_logger = ::Logger.new(STDOUT)
307
308
  message: message.byteslice(0, LogEntry::MESSAGE_MAX_BYTES).scrub(""),
308
309
  }.to_msgpack
309
310
  ensure
310
- packer.reset
311
+ packer.clear
311
312
  end
312
313
 
313
314
  # Converts what msgpack can't encode, recursively, mostly into strings, and passes strings
@@ -1,3 +1,3 @@
1
1
  module Logtail
2
- VERSION = "0.1.21"
2
+ VERSION = "0.1.22"
3
3
  end
@@ -398,6 +398,20 @@ describe Logtail::LogDevices::HTTP do
398
398
  expect(delivered_entries[0]["value"]).to eq(value)
399
399
  end
400
400
 
401
+ # logtail.gemspec accepts msgpack 1.0.0. Its packers empty themselves with #clear, the name #reset came in 1.4.5.
402
+ it "delivers with a msgpack packer that has no #reset, as before msgpack 1.4.5" do
403
+ packer = MessagePack::DefaultFactory.packer
404
+ packer.singleton_class.send(:undef_method, :reset)
405
+ allow(MessagePack::DefaultFactory).to receive(:packer).and_return(packer)
406
+
407
+ logger.info("line one")
408
+ logger.info("line two", value: 2)
409
+
410
+ entries = delivered_entries
411
+ expect(entries.map { |entry| entry["message"] }).to eq(["line one", "line two"])
412
+ expect(entries[1]["value"]).to eq(2)
413
+ end
414
+
401
415
  it "delivers strings written to the device as info lines" do
402
416
  http.write("written to the device\n")
403
417
  ::Logger.new(http).warn("logged by a plain Ruby logger")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logtail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Better Stack
@@ -141,8 +141,16 @@ executables: []
141
141
  extensions: []
142
142
  extra_rdoc_files: []
143
143
  files:
144
+ - ".github/actions/cleanup-sources/action.yml"
145
+ - ".github/actions/cleanup-sources/run.sh"
146
+ - ".github/actions/create-source/action.yml"
147
+ - ".github/actions/create-source/run.sh"
148
+ - ".github/actions/verify-logs/action.yml"
149
+ - ".github/actions/verify-logs/run.sh"
150
+ - ".github/workflows/e2e.yml"
144
151
  - ".github/workflows/main.yml"
145
152
  - ".github/workflows/no-closing-keywords.yml"
153
+ - ".github/workflows/notify_linear_failure.yml"
146
154
  - ".github/workflows/release.yml"
147
155
  - ".gitignore"
148
156
  - ".rspec"
@@ -150,8 +158,10 @@ files:
150
158
  - LICENSE.md
151
159
  - README.md
152
160
  - Rakefile
161
+ - e2e/expected.json
162
+ - e2e/plan.rb
163
+ - e2e/plan_test.rb
153
164
  - example-project/Gemfile
154
- - example-project/Gemfile.lock
155
165
  - example-project/README.md
156
166
  - example-project/main.rb
157
167
  - lib/logtail.rb
@@ -1,15 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- logtail (0.1.17)
5
- msgpack (~> 1.0)
6
- msgpack (1.8.0)
7
-
8
- PLATFORMS
9
- ruby
10
-
11
- DEPENDENCIES
12
- logtail (~> 0.1.17)
13
-
14
- BUNDLED WITH
15
- 2.1.4