logtail-rack 0.2.9 → 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 +4 -4
- data/.github/actions/cleanup-sources/action.yml +33 -0
- data/.github/actions/cleanup-sources/run.sh +51 -0
- data/.github/actions/create-source/action.yml +46 -0
- data/.github/actions/create-source/run.sh +40 -0
- data/.github/actions/verify-logs/action.yml +47 -0
- data/.github/actions/verify-logs/run.sh +104 -0
- data/.github/workflows/e2e.yml +292 -0
- data/.github/workflows/main.yml +0 -3
- data/.github/workflows/notify_linear_failure.yml +153 -0
- data/.gitignore +0 -1
- data/e2e/example.sh +66 -0
- data/e2e/expected.json +42 -0
- data/e2e/plan.rb +130 -0
- data/example-project/Gemfile +6 -1
- data/example-project/README.md +9 -13
- data/example-project/config.ru +12 -6
- data/example-project/logging_app.rb +10 -3
- data/lib/logtail-rack/version.rb +1 -1
- data/logtail-ruby-rack.gemspec +1 -1
- metadata +18 -2
- data/example-project/Gemfile.lock +0 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2a02b2c34943570924a1f8acc7c8d2d3b381bf0e2a4aa66686cd6fd03274de82
|
|
4
|
+
data.tar.gz: 63e437edb3fa98f4ea13320645a52c09c1b8df1be347ca2e624a5805d53b17bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/.github/workflows/main.yml
CHANGED
|
@@ -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/.gitignore
CHANGED
data/e2e/example.sh
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Runs the example project the way its README tells a customer to: `bundle exec rackup` in example-project/, a visit
|
|
3
|
+
# to / (the app logs three lines, the middlewares the request and the response) and one to /error (the app raises, the
|
|
4
|
+
# middlewares log the error and a 500 response), then Ctrl+C. The example sends what is still buffered when the
|
|
5
|
+
# server stops, so the server is stopped right after the second request. The server's output goes to out/example.log,
|
|
6
|
+
# and a failure ends with one ::error:: line.
|
|
7
|
+
# Env: BETTER_STACK_SOURCE_TOKEN, BETTER_STACK_INGESTING_HOST, and example-project/Gemfile's gems installed.
|
|
8
|
+
set -euo pipefail
|
|
9
|
+
|
|
10
|
+
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
|
11
|
+
OUT=$ROOT/out
|
|
12
|
+
LOG=$OUT/example.log
|
|
13
|
+
# rackup's default port. Rack 1 listens on 0.0.0.0, newer ones on localhost, so the requests go to localhost.
|
|
14
|
+
URL=http://localhost:9292
|
|
15
|
+
mkdir -p "$OUT"
|
|
16
|
+
|
|
17
|
+
# The server's output, then the error, if any.
|
|
18
|
+
SERVER=""
|
|
19
|
+
ERROR=""
|
|
20
|
+
fail() {
|
|
21
|
+
ERROR=$1
|
|
22
|
+
exit 1
|
|
23
|
+
}
|
|
24
|
+
finish() {
|
|
25
|
+
[ -z "$SERVER" ] || kill -KILL "$SERVER" 2> /dev/null || true
|
|
26
|
+
cat "$LOG"
|
|
27
|
+
[ -z "$ERROR" ] || echo "::error::$ERROR"
|
|
28
|
+
}
|
|
29
|
+
trap finish EXIT
|
|
30
|
+
|
|
31
|
+
cd "$ROOT/example-project"
|
|
32
|
+
bundle exec rackup > "$LOG" 2>&1 &
|
|
33
|
+
SERVER=$!
|
|
34
|
+
|
|
35
|
+
# Ready once the port takes a connection. A request would be logged and stored as a row of its own.
|
|
36
|
+
for ((second = 0; ; second++)); do
|
|
37
|
+
if (exec 3<> /dev/tcp/localhost/9292) 2> /dev/null; then break; fi
|
|
38
|
+
kill -0 "$SERVER" 2> /dev/null || fail "The example project exited before it listened: $(tail -n 1 "$LOG")"
|
|
39
|
+
[ "$second" -lt 60 ] || fail "The example project did not listen on $URL within 60 s"
|
|
40
|
+
sleep 1
|
|
41
|
+
done
|
|
42
|
+
|
|
43
|
+
request() {
|
|
44
|
+
local status
|
|
45
|
+
status=$(curl -sS -m 30 -o "$OUT/response.txt" -w '%{http_code}' "$URL$1") || status=000
|
|
46
|
+
echo "GET $1 answered HTTP $status"
|
|
47
|
+
[ "$status" = "$2" ] || fail "GET $1 answered HTTP $status instead of $2: $(head -c 300 "$OUT/response.txt" 2> /dev/null)"
|
|
48
|
+
}
|
|
49
|
+
request / 200
|
|
50
|
+
request /error 500
|
|
51
|
+
|
|
52
|
+
# Ctrl+C. rackup traps SIGINT and shuts the server down, then Ruby runs the at_exit hooks.
|
|
53
|
+
kill -INT "$SERVER"
|
|
54
|
+
for ((second = 0; ; second++)); do
|
|
55
|
+
kill -0 "$SERVER" 2> /dev/null || break
|
|
56
|
+
[ "$second" -lt 30 ] || fail "The example project did not stop within 30 s of SIGINT"
|
|
57
|
+
sleep 1
|
|
58
|
+
done
|
|
59
|
+
STATUS=0
|
|
60
|
+
wait "$SERVER" || STATUS=$?
|
|
61
|
+
[ "$STATUS" = 0 ] || fail "The example project exited with status $STATUS: $(tail -n 1 "$LOG")"
|
|
62
|
+
|
|
63
|
+
# logtail 0.1.21 and newer warn about a batch Better Stack rejected, older releases drop it silently.
|
|
64
|
+
if grep -q 'Better Stack rejected' "$LOG"; then
|
|
65
|
+
fail "$(grep -m 1 'Better Stack rejected' "$LOG")"
|
|
66
|
+
fi
|
data/e2e/expected.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"level": "info",
|
|
4
|
+
"message": "Started GET \"/\"",
|
|
5
|
+
"contains": {"event": {"http_request_received": {"method": "GET", "path": "/", "host": "localhost", "port": 9292, "scheme": "http", "headers_json": {"Host": "localhost:9292"}}}, "context": {"runtime": {"file": "lib/logtail-rack/http_events.rb"}, "http": {"method": "GET", "path": "/", "host": "localhost"}}}
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"level": "info",
|
|
9
|
+
"message": "I am using Better Stack! 🚀",
|
|
10
|
+
"contains": {"context": {"runtime": {"file": "logging_app.rb"}, "http": {"method": "GET", "path": "/", "host": "localhost"}}}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"level": "debug",
|
|
14
|
+
"message": "Logging structured data...",
|
|
15
|
+
"contains": {"name": {"first": "John", "last": "Smith"}, "id": 123456, "context": {"runtime": {"file": "logging_app.rb"}, "http": {"method": "GET", "path": "/", "host": "localhost"}}}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"level": "warn",
|
|
19
|
+
"message": "Log structured data",
|
|
20
|
+
"contains": {"item": {"url": "https://fictional-store.com/item-123", "price": 100.0}, "context": {"runtime": {"file": "logging_app.rb"}, "http": {"method": "GET", "path": "/", "host": "localhost"}}}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"level": "info",
|
|
24
|
+
"message_prefix": "Completed 200 OK in ",
|
|
25
|
+
"contains": {"event": {"http_response_sent": {"status": 200, "headers_json": {"content-type": "text/plain"}}}, "context": {"runtime": {"file": "lib/logtail-rack/http_events.rb"}, "http": {"method": "GET", "path": "/", "host": "localhost"}}}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"level": "info",
|
|
29
|
+
"message": "Started GET \"/error\"",
|
|
30
|
+
"contains": {"event": {"http_request_received": {"method": "GET", "path": "/error", "host": "localhost", "port": 9292, "scheme": "http", "headers_json": {"Host": "localhost:9292"}}}, "context": {"runtime": {"file": "lib/logtail-rack/http_events.rb"}, "http": {"method": "GET", "path": "/error", "host": "localhost"}}}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"level": "fatal",
|
|
34
|
+
"message": "RuntimeError (Visiting /error raises an error. You should see it in Better Stack.)",
|
|
35
|
+
"contains": {"error": {"name": "RuntimeError", "message": "Visiting /error raises an error. You should see it in Better Stack.", "backtrace_json": ["example-project/logging_app.rb:9:in "]}, "context": {"runtime": {"file": "lib/logtail-rack/error_event.rb"}, "http": {"method": "GET", "path": "/error", "host": "localhost"}}}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"level": "info",
|
|
39
|
+
"message_prefix": "Completed 500 Internal Server Error in ",
|
|
40
|
+
"contains": {"event": {"http_response_sent": {"status": 500}}, "context": {"runtime": {"file": "lib/logtail-rack/http_events.rb"}, "http": {"method": "GET", "path": "/error", "host": "localhost"}}}
|
|
41
|
+
}
|
|
42
|
+
]
|
data/e2e/plan.rb
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Prints the job matrix of the E2E workflow (.github/workflows/e2e.yml) as JSON.
|
|
2
|
+
#
|
|
3
|
+
# ruby e2e/plan.rb [--leg all|floor|rack2|latest|canary] [--ruby <version>] [--rack <version>] [--logtail <version>] [--source checkout|rubygems]
|
|
4
|
+
#
|
|
5
|
+
# floor Ruby 2.7 with the oldest rack and logtail releases the gemspec allows that run the example (see FLOOR_*)
|
|
6
|
+
# rack2 Ruby 3.2 with the newest Rack 2 and the newest logtail release
|
|
7
|
+
# latest the newest stable Ruby that ruby/setup-ruby installs, with the newest rack and logtail releases. Bundler
|
|
8
|
+
# failing to install them, say a Rack 4 that the gemspec's "< 4.0" excludes, fails the job.
|
|
9
|
+
# canary ruby-head with rack's main branch and the newest logtail release
|
|
10
|
+
#
|
|
11
|
+
# --ruby, --rack and --logtail replace the planned version of every leg that runs with one exact version, which is
|
|
12
|
+
# how a run bisects a failure to one release. --source is copied into every entry: checkout installs the gem built
|
|
13
|
+
# from this checkout, rubygems the newest logtail-rack release, which is then the client version planned.
|
|
14
|
+
#
|
|
15
|
+
# Standard library only, so the plan job needs nothing but a Ruby.
|
|
16
|
+
require "json"
|
|
17
|
+
require "net/http"
|
|
18
|
+
require "optparse"
|
|
19
|
+
require "rubygems"
|
|
20
|
+
|
|
21
|
+
ROOT = File.expand_path("..", __dir__)
|
|
22
|
+
GEMSPEC = File.join(ROOT, "logtail-ruby-rack.gemspec")
|
|
23
|
+
# What the ruby/setup-ruby@v1 that the test job uses can install.
|
|
24
|
+
SETUP_RUBY_VERSIONS_URL = "https://raw.githubusercontent.com/ruby/setup-ruby/v1/ruby-builder-versions.json"
|
|
25
|
+
RUBYGEMS_VERSIONS_URL = "https://rubygems.org/api/v1/versions/%s.json"
|
|
26
|
+
LEGS = %w[floor rack2 latest canary].freeze
|
|
27
|
+
# Job names become artifact names (e2e-summary-<job name>), which must not contain any of these.
|
|
28
|
+
NOT_IN_NAMES = ':"<>|*?/\\'.chars.freeze
|
|
29
|
+
|
|
30
|
+
# The gemspec allows Ruby 2.3, but main.yml tests Rack 1, the oldest the gemspec allows, on Ruby 2.7 only.
|
|
31
|
+
FLOOR_RUBY = "2.7".freeze
|
|
32
|
+
# The gemspec requires logtail 0.1.15 or newer, and the floor leg runs that floor: releases before 0.1.14 have no
|
|
33
|
+
# ingesting_host option, which the example and the README pass, and 0.1.14 calls Rails' String#present? and fails
|
|
34
|
+
# without Rails.
|
|
35
|
+
FLOOR_LOGTAIL = Gem::Version.new("0.1.15")
|
|
36
|
+
# The other Ruby main.yml tests the Rack pins on.
|
|
37
|
+
RACK2_RUBY = "3.2".freeze
|
|
38
|
+
|
|
39
|
+
def fetch_json(url, attempts: 3)
|
|
40
|
+
error = nil
|
|
41
|
+
attempts.times do |attempt|
|
|
42
|
+
# A registry hiccup at schedule time should not file a Linear issue, so the lookup is retried.
|
|
43
|
+
sleep 10 if attempt > 0
|
|
44
|
+
begin
|
|
45
|
+
response = Net::HTTP.get_response(URI(url))
|
|
46
|
+
return JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess)
|
|
47
|
+
|
|
48
|
+
error = "HTTP #{response.code}"
|
|
49
|
+
rescue StandardError => e
|
|
50
|
+
error = e.message
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
abort "GET #{url} failed #{attempts} times, last: #{error}"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Every release of a gem on rubygems.org, without pre-releases, oldest first.
|
|
57
|
+
def releases(name)
|
|
58
|
+
@releases ||= {}
|
|
59
|
+
@releases[name] ||= fetch_json(format(RUBYGEMS_VERSIONS_URL, name))
|
|
60
|
+
.reject { |version| version["prerelease"] }
|
|
61
|
+
.map { |version| Gem::Version.new(version["number"]) }
|
|
62
|
+
.uniq.sort
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def newest_release(name, requirement = Gem::Requirement.default)
|
|
66
|
+
releases(name).select { |version| requirement.satisfied_by?(version) }.max ||
|
|
67
|
+
abort("rubygems.org lists no #{name} release matching #{requirement}")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def lowest_release(name, requirement)
|
|
71
|
+
releases(name).find { |version| requirement.satisfied_by?(version) } ||
|
|
72
|
+
abort("rubygems.org lists no #{name} release matching #{requirement}")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def newest_stable_ruby
|
|
76
|
+
fetch_json(SETUP_RUBY_VERSIONS_URL).fetch("ruby")
|
|
77
|
+
.grep(/\A\d+\.\d+\.\d+\z/)
|
|
78
|
+
.max_by { |version| Gem::Version.new(version) }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def dependency(spec, name)
|
|
82
|
+
spec.runtime_dependencies.find { |dependency| dependency.name == name } ||
|
|
83
|
+
abort("#{File.basename(GEMSPEC)} declares no #{name} dependency")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def plan(leg, spec, ruby: nil, rack: nil, logtail: nil)
|
|
87
|
+
case leg
|
|
88
|
+
when "floor"
|
|
89
|
+
ruby ||= FLOOR_RUBY
|
|
90
|
+
rack ||= lowest_release("rack", dependency(spec, "rack").requirement).to_s
|
|
91
|
+
logtail ||= [lowest_release("logtail", dependency(spec, "logtail").requirement), FLOOR_LOGTAIL].max.to_s
|
|
92
|
+
when "rack2"
|
|
93
|
+
ruby ||= RACK2_RUBY
|
|
94
|
+
rack ||= newest_release("rack", Gem::Requirement.new("~> 2.0")).to_s
|
|
95
|
+
when "latest"
|
|
96
|
+
ruby ||= newest_stable_ruby
|
|
97
|
+
rack ||= newest_release("rack").to_s
|
|
98
|
+
when "canary"
|
|
99
|
+
ruby ||= "head"
|
|
100
|
+
rack ||= "main"
|
|
101
|
+
end
|
|
102
|
+
logtail ||= newest_release("logtail").to_s
|
|
103
|
+
|
|
104
|
+
name = "#{leg} (Ruby #{ruby}, Rack #{rack}, logtail #{logtail})"
|
|
105
|
+
abort "job name #{name.inspect} contains one of #{NOT_IN_NAMES.join}, which artifact names do not allow" if (name.chars & NOT_IN_NAMES).any?
|
|
106
|
+
{
|
|
107
|
+
leg: leg,
|
|
108
|
+
name: name,
|
|
109
|
+
ruby: ruby,
|
|
110
|
+
rack: rack,
|
|
111
|
+
logtail: logtail,
|
|
112
|
+
# The floor and rack2 run on the oldest Ubuntu image GitHub offers, the other legs follow ubuntu-latest.
|
|
113
|
+
runner: %w[floor rack2].include?(leg) ? "ubuntu-24.04" : "ubuntu-latest",
|
|
114
|
+
}
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
options = { leg: "all", source: "checkout" }
|
|
118
|
+
OptionParser.new do |parser|
|
|
119
|
+
parser.on("--leg LEG", ["all", *LEGS])
|
|
120
|
+
parser.on("--ruby VERSION")
|
|
121
|
+
parser.on("--rack VERSION")
|
|
122
|
+
parser.on("--logtail VERSION")
|
|
123
|
+
parser.on("--source SOURCE", %w[checkout rubygems])
|
|
124
|
+
end.parse!(into: options)
|
|
125
|
+
overrides = options.slice(:ruby, :rack, :logtail).transform_values(&:strip).reject { |_name, version| version.empty? }
|
|
126
|
+
|
|
127
|
+
spec = Gem::Specification.load(GEMSPEC) || abort("could not load #{GEMSPEC}")
|
|
128
|
+
client = options[:source] == "rubygems" ? newest_release("logtail-rack").to_s : spec.version.to_s
|
|
129
|
+
legs = options[:leg] == "all" ? LEGS : [options[:leg]]
|
|
130
|
+
puts JSON.generate(legs.map { |leg| plan(leg, spec, **overrides).merge(source: options[:source], client: client) })
|
data/example-project/Gemfile
CHANGED
|
@@ -2,6 +2,11 @@ source "https://rubygems.org"
|
|
|
2
2
|
|
|
3
3
|
gem "rack", "~> 3.0"
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# The rackup command, its own gem since Rack 3. With an older Rack this resolves to an empty release
|
|
6
|
+
# and the rackup command of the rack gem starts the app.
|
|
7
|
+
gem "rackup"
|
|
8
|
+
|
|
9
|
+
# The web server rackup starts, no longer part of Ruby since 3.0
|
|
10
|
+
gem "webrick"
|
|
6
11
|
|
|
7
12
|
gem "logtail-rack", "~> 0.2.6"
|
data/example-project/README.md
CHANGED
|
@@ -10,31 +10,27 @@ You can download the [example project](https://github.com/logtail/logtail-ruby-r
|
|
|
10
10
|
bundle install
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
This will install all dependencies listed in the `Gemfile
|
|
14
|
-
|
|
15
|
-
Then replace `<source_token>` and `<ingesting_host>` in `config.ru` with your actual source token and ingesting host which you can find by going to [Better Stack Telemetry](https://teleemetry.betterstack.com/dashboard) -> Source -> Configure.
|
|
16
|
-
|
|
17
|
-
```ruby
|
|
18
|
-
http_io_device = Logtail::LogDevices::HTTP.new("<source_token>", ingesting_host: "<ingesting_host>")
|
|
19
|
-
```
|
|
13
|
+
This will install all dependencies listed in the `Gemfile`.
|
|
20
14
|
|
|
21
15
|
## Run the example project
|
|
22
16
|
|
|
23
|
-
To run the example application,
|
|
17
|
+
To run the example application, set your source token and ingesting host, which you can find by going to [Better Stack Telemetry](https://telemetry.betterstack.com/dashboard) -> Source -> Configure, and start the server:
|
|
24
18
|
|
|
25
19
|
```bash
|
|
26
|
-
rackup
|
|
20
|
+
BETTER_STACK_SOURCE_TOKEN=<source_token> BETTER_STACK_INGESTING_HOST=<ingesting_host> bundle exec rackup
|
|
27
21
|
```
|
|
28
22
|
|
|
29
|
-
This will start a local server and you visit [http://
|
|
23
|
+
This will start a local server, and you can visit [http://localhost:9292](http://localhost:9292) in your browser.
|
|
30
24
|
|
|
31
25
|
You should see the following output:
|
|
32
26
|
|
|
33
27
|
```bash
|
|
34
28
|
All done!
|
|
35
|
-
Log into your
|
|
29
|
+
Log into your Better Stack account to check your logs.
|
|
36
30
|
```
|
|
37
31
|
|
|
38
|
-
This will create a total of
|
|
32
|
+
This will create a total of 5 different logs: the request, an info, a debug and a warning line from the app, and the response. You can review these logs in Better Stack.
|
|
33
|
+
|
|
34
|
+
You can visit any path on the server to see the request path being logged in context. Visit [/error](http://localhost:9292/error) to see an example exception being logged.
|
|
39
35
|
|
|
40
|
-
|
|
36
|
+
Stop the server with Ctrl+C. The logs still buffered are sent before it exits.
|
data/example-project/config.ru
CHANGED
|
@@ -6,8 +6,17 @@ use Logtail::Integrations::Rack::HTTPContext
|
|
|
6
6
|
use Logtail::Integrations::Rack::HTTPEvents
|
|
7
7
|
use Logtail::Integrations::Rack::ErrorEvent
|
|
8
8
|
|
|
9
|
-
# HTTP IO device sends logs to Better Stack,
|
|
10
|
-
|
|
9
|
+
# HTTP IO device sends logs to Better Stack, to the source whose token and ingesting host are in
|
|
10
|
+
# the BETTER_STACK_SOURCE_TOKEN and BETTER_STACK_INGESTING_HOST environment variables
|
|
11
|
+
source_token = ENV["BETTER_STACK_SOURCE_TOKEN"].to_s
|
|
12
|
+
ingesting_host = ENV["BETTER_STACK_INGESTING_HOST"].to_s
|
|
13
|
+
if source_token.empty? || ingesting_host.empty?
|
|
14
|
+
abort "Usage: BETTER_STACK_SOURCE_TOKEN=<source_token> BETTER_STACK_INGESTING_HOST=<ingesting_host> bundle exec rackup"
|
|
15
|
+
end
|
|
16
|
+
http_io_device = Logtail::LogDevices::HTTP.new(source_token, ingesting_host: ingesting_host)
|
|
17
|
+
|
|
18
|
+
# Sends the logs still buffered when the server stops
|
|
19
|
+
at_exit { http_io_device.close }
|
|
11
20
|
|
|
12
21
|
# STDOUT IO device sends logs to console output
|
|
13
22
|
stdout_io_device = STDOUT
|
|
@@ -17,7 +26,4 @@ logger = Logtail::Logger.new(http_io_device, stdout_io_device)
|
|
|
17
26
|
Logtail::Config.instance.logger = logger
|
|
18
27
|
|
|
19
28
|
# App initialization
|
|
20
|
-
|
|
21
|
-
run do |env|
|
|
22
|
-
logging_app.run(env)
|
|
23
|
-
end
|
|
29
|
+
run LoggingApp.new(logger)
|
|
@@ -5,7 +5,9 @@ class LoggingApp
|
|
|
5
5
|
@logger = logger
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
def
|
|
8
|
+
def call(env)
|
|
9
|
+
raise RuntimeError.new("Visiting /error raises an error. You should see it in Better Stack.") if env["PATH_INFO"].start_with?("/error")
|
|
10
|
+
|
|
9
11
|
@logger.info("I am using Better Stack! 🚀")
|
|
10
12
|
|
|
11
13
|
# You can also provide additional information when logging
|
|
@@ -17,8 +19,13 @@ class LoggingApp
|
|
|
17
19
|
id: 123456
|
|
18
20
|
)
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
@logger.warn("Log structured data",
|
|
23
|
+
item: {
|
|
24
|
+
url: "https://fictional-store.com/item-123",
|
|
25
|
+
price: 100.00
|
|
26
|
+
}
|
|
27
|
+
)
|
|
21
28
|
|
|
22
|
-
[200, {}, ["All done!\nLog into your
|
|
29
|
+
[200, { "content-type" => "text/plain" }, ["All done!\nLog into your Better Stack account to check your logs.\n"]]
|
|
23
30
|
end
|
|
24
31
|
end
|
data/lib/logtail-rack/version.rb
CHANGED
data/logtail-ruby-rack.gemspec
CHANGED
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
28
|
spec.require_paths = ["lib"]
|
|
29
29
|
|
|
30
|
-
spec.add_dependency "logtail", "~> 0.1"
|
|
30
|
+
spec.add_dependency "logtail", "~> 0.1", ">= 0.1.15"
|
|
31
31
|
spec.add_runtime_dependency "rack", ">= 1.2", "< 4.0"
|
|
32
32
|
|
|
33
33
|
spec.add_development_dependency "bundler", ">= 0.0"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: logtail-rack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Better Stack
|
|
@@ -16,6 +16,9 @@ dependencies:
|
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
18
|
version: '0.1'
|
|
19
|
+
- - ">="
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.1.15
|
|
19
22
|
type: :runtime
|
|
20
23
|
prerelease: false
|
|
21
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -23,6 +26,9 @@ dependencies:
|
|
|
23
26
|
- - "~>"
|
|
24
27
|
- !ruby/object:Gem::Version
|
|
25
28
|
version: '0.1'
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: 0.1.15
|
|
26
32
|
- !ruby/object:Gem::Dependency
|
|
27
33
|
name: rack
|
|
28
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -91,8 +97,16 @@ executables: []
|
|
|
91
97
|
extensions: []
|
|
92
98
|
extra_rdoc_files: []
|
|
93
99
|
files:
|
|
100
|
+
- ".github/actions/cleanup-sources/action.yml"
|
|
101
|
+
- ".github/actions/cleanup-sources/run.sh"
|
|
102
|
+
- ".github/actions/create-source/action.yml"
|
|
103
|
+
- ".github/actions/create-source/run.sh"
|
|
104
|
+
- ".github/actions/verify-logs/action.yml"
|
|
105
|
+
- ".github/actions/verify-logs/run.sh"
|
|
106
|
+
- ".github/workflows/e2e.yml"
|
|
94
107
|
- ".github/workflows/main.yml"
|
|
95
108
|
- ".github/workflows/no-closing-keywords.yml"
|
|
109
|
+
- ".github/workflows/notify_linear_failure.yml"
|
|
96
110
|
- ".github/workflows/release.yml"
|
|
97
111
|
- ".gitignore"
|
|
98
112
|
- ".rspec"
|
|
@@ -100,8 +114,10 @@ files:
|
|
|
100
114
|
- LICENSE.md
|
|
101
115
|
- README.md
|
|
102
116
|
- Rakefile
|
|
117
|
+
- e2e/example.sh
|
|
118
|
+
- e2e/expected.json
|
|
119
|
+
- e2e/plan.rb
|
|
103
120
|
- example-project/Gemfile
|
|
104
|
-
- example-project/Gemfile.lock
|
|
105
121
|
- example-project/README.md
|
|
106
122
|
- example-project/config.ru
|
|
107
123
|
- example-project/logging_app.rb
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
GEM
|
|
2
|
-
remote: https://rubygems.org/
|
|
3
|
-
specs:
|
|
4
|
-
logtail (0.1.15)
|
|
5
|
-
msgpack (~> 1.0)
|
|
6
|
-
logtail-rack (0.2.6)
|
|
7
|
-
logtail (~> 0.1)
|
|
8
|
-
rack (>= 1.2, < 4.0)
|
|
9
|
-
msgpack (1.8.0)
|
|
10
|
-
rack (3.1.9)
|
|
11
|
-
rackup (2.2.1)
|
|
12
|
-
rack (>= 3)
|
|
13
|
-
|
|
14
|
-
PLATFORMS
|
|
15
|
-
arm64-darwin-22
|
|
16
|
-
|
|
17
|
-
DEPENDENCIES
|
|
18
|
-
logtail-rack (~> 0.2.6)
|
|
19
|
-
rack (~> 3.0)
|
|
20
|
-
rackup (~> 2.1)
|
|
21
|
-
|
|
22
|
-
BUNDLED WITH
|
|
23
|
-
2.3.14
|