-
Notifications
You must be signed in to change notification settings - Fork 1.2k
141 lines (113 loc) · 5.49 KB
/
serverless-binary-size.yml
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
name: "Serverless Binary Size"
on:
pull_request:
push:
branches:
- mq-working-branch-*
env:
SIZE_ALLOWANCE: fromJSON(1000000) # 1 MB
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Checkout datadog-agent repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
path: go/src/github.com/DataDog/datadog-agent
- name: Checkout datadog-agent base branch
run: |
cd go/src/github.com/DataDog/datadog-agent
git fetch origin $GITHUB_BASE_REF --depth 1
git checkout $GITHUB_BASE_REF
- name: Checkout the datadog-lambda-extension repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
repository: DataDog/datadog-lambda-extension
path: go/src/github.com/DataDog/datadog-lambda-extension
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Previous binary size and dependencies
id: previous
run: |
cd go/src/github.com/DataDog/datadog-lambda-extension
OUTPUT=$(./scripts/visualize_size.sh size)
echo "binary size before merging this pull request is $OUTPUT"
echo "result=$OUTPUT" >> $GITHUB_OUTPUT
echo "deps<<EOF" >> $GITHUB_OUTPUT
./scripts/visualize_size.sh list_symbols | awk '{print $2}' | head -n 100 >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Checkout datadog-agent pr branch
run: |
cd go/src/github.com/DataDog/datadog-agent
git fetch origin $GITHUB_SHA --depth 1
git checkout $GITHUB_SHA
- name: Current binary size and dependencies
id: current
run: |
cd go/src/github.com/DataDog/datadog-lambda-extension
OUTPUT=$(./scripts/visualize_size.sh size)
echo "binary size after merging this pull request will be $OUTPUT"
echo "result=$OUTPUT" >> $GITHUB_OUTPUT
echo "deps<<EOF" >> $GITHUB_OUTPUT
./scripts/visualize_size.sh list_symbols | awk '{print $2}' | head -n 100 >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Compare sizes
id: compare
run: |
OUTPUT=$(( ${{ steps.current.outputs.result }} - ${{ steps.previous.outputs.result }} ))
echo "diff=$OUTPUT" >> $GITHUB_OUTPUT
OUTPUT=$(( $OUTPUT / 100000 ))
echo "coldstart=$OUTPUT" >> $GITHUB_OUTPUT
### Steps below only run if size diff > SIZE_ALLOWANCE ###
- name: Install graphviz
uses: ts-graphviz/setup-graphviz@b1de5da23ed0a6d14e0aeee8ed52fdd87af2363c # v2.0.2
if: steps.compare.outputs.diff > env.SIZE_ALLOWANCE
- name: Install digraph
if: steps.compare.outputs.diff > env.SIZE_ALLOWANCE
run: |
GOPATH=$(pwd)/go go install golang.org/x/tools/cmd/digraph@latest
- name: List new dependencies
id: deps
if: steps.compare.outputs.diff > env.SIZE_ALLOWANCE
run: |
echo "deps<<EOF" >> $GITHUB_OUTPUT
for dep in $(echo "${{ steps.current.outputs.deps }}"); do
if ! echo "${{ steps.previous.outputs.deps }}" | grep -w -q "$dep"; then
echo "$dep" >> $GITHUB_OUTPUT
fi
done
echo "EOF" >> $GITHUB_OUTPUT
- name: Create dependency graphs
if: steps.compare.outputs.diff > env.SIZE_ALLOWANCE
run: |
export PATH=$(pwd)/go/bin:$PATH
cd go/src/github.com/DataDog/datadog-lambda-extension
mkdir graphs
for dep in $(echo "${{ steps.deps.outputs.deps }}"); do
PACKAGE=$dep ./scripts/visualize_size.sh graph
mv .layers/output.svg graphs/$(echo $dep | tr '/' '-').svg
done
- name: Archive dependency graphs
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
if: steps.compare.outputs.diff > env.SIZE_ALLOWANCE
with:
name: dependency-graphs
path: go/src/github.com/DataDog/datadog-lambda-extension/graphs
- name: Post comment
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2.9.0
if: steps.compare.outputs.diff > env.SIZE_ALLOWANCE
with:
hide_and_recreate: true
hide_classify: "RESOLVED"
message: |
:warning::rotating_light: Warning, this pull request increases the binary size of serverless extension by ${{ steps.compare.outputs.diff }} bytes. Each MB of binary size increase means about 10ms of additional cold start time, so this pull request would increase cold start time by ${{ steps.compare.outputs.coldstart }}ms.
If you have questions, we are happy to help, come visit us in the [#serverless](https://dd.slack.com/archives/CBWDFKWV8) slack channel and provide a link to this comment.
<details>
<summary>Debug info</summary>
These dependencies were added to the serverless extension by this pull request:
```
${{ steps.deps.outputs.deps }}
```
View dependency graphs for each added dependency in the [artifacts section](https://github.com/DataDog/datadog-agent/actions/runs/${{ github.run_id }}#artifacts) of the github action.
We suggest you consider adding the `!serverless` build tag to remove any new dependencies not needed in the serverless extension.
</details>