Skip to content

[EBPF] Backport KMT platform files to 6.53.x #60175

[EBPF] Backport KMT platform files to 6.53.x

[EBPF] Backport KMT platform files to 6.53.x #60175

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@v4
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@v4
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@v3
- 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@v1
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@v4
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@v2.5.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>