-
Notifications
You must be signed in to change notification settings - Fork 4
272 lines (257 loc) · 12 KB
/
publish_main.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: Publish
on:
push:
branches: main
paths: 'VERSION'
workflow_dispatch:
jobs:
_test:
uses: ./.github/workflows/test.yaml
publish:
needs: [_test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "version=$(cat VERSION)" >> "$GITHUB_OUTPUT"
id: version
- uses: actions/download-artifact@v4
with:
name: package.deb
- uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.version }}
release_name: Release v${{ steps.version.outputs.version }}
draft: false
prerelease: false
- uses: actions/upload-release-asset@v1
id: upload-release-asset
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./package.deb
asset_name: opentelemetry-shell_${{ steps.version.outputs.version }}.deb
asset_content_type: application/octet-stream
demo-prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.demos.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- run: |
cd demos && echo */ | tr ' ' '\n' | tr -d / | jq -nR '{"include": [inputs | select(length > 0) | {demo_directory: .}]}' | tr -d '\n' | xargs -0 -I {} echo 'matrix={}' >> "$GITHUB_OUTPUT"
id: demos
demo-generate:
needs: [ demo-prepare, publish ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.demo-prepare.outputs.matrix) }}
steps:
- uses: actions/download-artifact@v4
with:
name: package.deb
- run: sudo apt-get update && sudo apt-get install -y ./package.deb && rm ./package.deb
- uses: actions/checkout@v4
- id: demo
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
run: |
set +o pipefail
cd demos/${{ matrix.demo_directory }}
echo "
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
batch:
exporters:
file:
path: /etc/otelcol/otlp.json
service:
pipelines:
metrics:
receivers: [otlp]
exporters: [file]
processors: [batch]
logs:
receivers: [otlp]
exporters: [file]
processors: [batch]
traces:
receivers: [otlp]
exporters: [file]
processors: [batch]
" > config.yaml
rm otlp.json || true
touch otlp.json && chmod 0666 otlp.json
sudo docker create --rm --mount type=bind,source=$(pwd)/config.yaml,target=/etc/otelcol/config.yaml --mount type=bind,source=$(pwd)/otlp.json,target=/etc/otelcol/otlp.json --network=host --name=collector otel/opentelemetry-collector:latest
sudo docker start collector
sleep 10
cat meta.json | jq -r .setup | (grep -v '^null$' || true) | sh
bash -e demo.sh 1> output.stdout 2> output.stderr || true
sleep 15
sudo docker stop collector
rm config.yaml
sed -i s/$GITHUB_TOKEN/***/g otlp.json
- env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
run: |
set +o pipefail
cd demos/${{ matrix.demo_directory }}
spans() {
jq '. | select(.resourceSpans != null) | .resourceSpans[].scopeSpans[].spans[]' < otlp.json
}
convert_span_id_to_name() {
spans | jq -r '. | select(.spanId == "'"$1"'") | .name'
}
get_root_span_id() {
spans | jq -r '. | select(.name != null) | select(.parentSpanId == "") | .spanId'
}
get_child_span_ids() {
spans | jq -r '. | select(.name != null) | select(.parentSpanId == "'"$1"'") | .spanId'
}
print_span_name_tree() {
local span_id="$1"
local indent="$2"
printf '%s' "$indent"; convert_span_id_to_name "$span_id"
get_child_span_ids "$span_id" | while read -r child_span_id; do
print_span_name_tree "$child_span_id" "$indent "
done
}
pretty_print_attributes() {
attributes="$(jq .[] 2> /dev/null)"
if [ -z "$attributes" ]; then echo "{}"; return 0; fi
printf '%s' "$attributes" | jq -r .key | while read -r key; do
value="$(printf '%s' "$attributes" | jq 'select(.key == "'"$key"'")' | jq .value)"
if printf '%s' "$value" | grep -q arrayValue; then
if printf '%s' "$value" | grep -q stringValue; then
value="$(printf '%s' "$value" | jq .arrayValue.values[].stringValue | tr '\n' ',')"
elif printf '%s' "$value" | grep -q intValue; then
value="$(printf '%s', "$value" | jq -r .arrayValue.values[].intValue | tr '\n' ',')"
else
value=","
fi
value="[${value::-1}]"
elif printf '%s' "$value" | grep -q stringValue; then
value="$(printf '%s' "$value" | jq .stringValue)"
elif printf '%s' "$value" | grep -q intValue; then
value="$(printf '%s' "$value" | jq -r .intValue)"
else
value=null
fi
jq -n --argjson "$key" "$value" '$ARGS.named'
done | jq -s add
}
pretty_print_events() {
events="$(cat)"
if [ -z "$events" ] || [ "$events" = null ]; then echo "[]"; return 0; fi
printf '%s' "$events" | jq .[].name | wc -l | xargs seq 1 | while read -r index; do echo "$((index-1))"; done | while read -r index; do
event="$(printf '%s' "$events" | jq ".[$index]")"
jq -n \
--argjson name "$(printf '%s' "$event" | jq .name)" \
--argjson time "$(printf '%s' "$event" | jq -r .timeUnixNano)" \
--argjson attributes "$(printf '%s' "$event" | jq .attributes | pretty_print_attributes)" \
'$ARGS.named'
done | jq -s .
}
pretty_print_links() {
links="$(cat)"
if [ -z "$links" ] || [ "$links" = null ]; then echo "[]"; return 0; fi
printf '%s' "$links" | jq .[].traceId | wc -l | xargs seq 1 | while read -r index; do echo "$((index-1))"; done | while read -r index; do
link="$(printf '%s' "$links" | jq ".[$index]")"
jq -n \
--argjson trace_id "$(printf '%s' "$link" | jq .traceId)" \
--argjson span_id "$(printf '%s' "$link" | jq .spanId)" \
--argjson attributes "$(printf '%s' "$link" | jq .attributes | pretty_print_attributes)" \
'$ARGS.named'
done | jq -s .
}
pretty_print_trace() {
cat otlp.json | jq -r '. | select(.resourceSpans != null) | .resourceSpans[].scopeSpans[].spans[].spanId' | while read -r span_id; do
span="$(jq '. | select(.resourceSpans != null) | .resourceSpans[].scopeSpans[].spans[] | select(.spanId == "'$span_id'")' < otlp.json)"
resource_attributes="$(jq '. | select(.resourceSpans != null) | .resourceSpans[] | select(.scopeSpans[].spans[].spanId == "'$span_id'")' < otlp.json | jq .resource.attributes)"
jq -n \
--argjson trace_id "$(printf '%s' "$span" | jq .traceId)" \
--argjson span_id "$(printf '%s' "$span" | jq .spanId)" \
--argjson parent_span_id "$(printf '%s' "$span" | jq .parentSpanId)" \
--argjson name "$(printf '%s' "$span" | jq .name)" \
--argjson kind "$(printf '%s' "$span" | jq .kind)" \
--argjson status "$(printf '%s' "$span" | jq -r .status.code)" \
--argjson time_start "$(printf '%s' "$span" | jq -r .startTimeUnixNano)" \
--argjson time_end "$(printf '%s' "$span" | jq -r .endTimeUnixNano)" \
--argjson attributes "$(printf '%s' "$span" | jq .attributes | pretty_print_attributes)" \
--argjson resource_attributes "$(printf '%s' "$resource_attributes" | pretty_print_attributes)" \
--argjson links "$(printf '%s' "$span" | jq .links | pretty_print_links)" \
--argjson events "$(printf '%s' "$span" | jq .events | pretty_print_events)" \
'$ARGS.named'
done \
| jq 'with_entries(if .key == "kind" and .value == 1 then .value = "INTERNAL" else . end)' \
| jq 'with_entries(if .key == "kind" and .value == 2 then .value = "SERVER" else . end)' \
| jq 'with_entries(if .key == "kind" and .value == 3 then .value = "CLIENT" else . end)' \
| jq 'with_entries(if .key == "kind" and .value == 4 then .value = "PRODUCER" else . end)' \
| jq 'with_entries(if .key == "kind" and .value == 5 then .value = "CONSUMER" else . end)' \
| jq 'with_entries(if .key == "status" and .value == null then .value = "UNSET" else . end)' \
| jq 'with_entries(if .key == "status" and .value == 0 then .value = "UNSET" else . end)' \
| jq 'with_entries(if .key == "status" and .value == 1 then .value = "OK" else . end)' \
| jq 'with_entries(if .key == "status" and .value == 2 then .value = "ERROR" else . end)' \
| jq .
}
{
echo '# Demo "'"$(cat ./meta.json | jq -r .title)"'"'
cat meta.json | jq -r .description
echo '## Script'
echo '```sh'
cat demo.sh
echo '```'
echo '## Trace Structure Overview'
echo '```'
get_root_span_id | while read -r root_span_id; do print_span_name_tree "$root_span_id" ""; done
echo '```'
echo '## Full Trace'
echo '```'
pretty_print_trace
echo '```'
} > README.md
mv otlp.json otlp.json.minimized
jq . < otlp.json.minimized > otlp.json
rm otlp.json.minimized
- run: cat demos/${{ matrix.demo_directory }}/README.md
- run: |
cd demos/${{ matrix.demo_directory }}
git add --intent-to-add README.md output.stdout output.stderr otlp.json
git diff
git diff README.md | grep -v '^+++' | grep -v '^---' | grep -v Id | grep -v _id | grep -v .id | grep -v Time | grep -v time | grep -v timestamp | grep -v github. | grep -v .version | grep -v .port | grep -v process.pid | grep -v process.parent_pid | grep -q '^+' && echo dirty=true >> "$GITHUB_OUTPUT" || true
id: diff
- name: "Resolve Reviewers"
if: steps.diff.outputs.dirty
id: reviewers
run: |
if ! [ -f .github/renovate.json ]; then exit 0; fi
echo "reviewers=$(cat .github/renovate.json | jq -r '.reviewers | join(",")')" >> "$GITHUB_OUTPUT"
- name: "Open Pull Request"
if: steps.diff.outputs.dirty
id: open-pr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
commit-message: "Update demo"
branch: "demos/${{ matrix.demo_directory }}"
title: "Update Demo ${{ matrix.demo_directory }}"
body: |
(this PR is automatically generated)
reviewers: ${{ steps.reviewers.outputs.reviewers }}
delete-branch: true
- uses: peter-evans/enable-pull-request-automerge@v3
if: steps.open-pr.outputs.pull-request-number != null
with:
token: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
pull-request-number: ${{ steps.open-pr.outputs.pull-request-number }}
merge-method: squash