Skip to content

Commit cbef761

Browse files
authored
feat: send logs to userspace + revamp (#14)
Update bpf_printk statements to be also sent to userspace so they can be logged alongside events. All log lines are considered errors and should be checked (unless running a debug eBPF binary). Revamps the CO-RE reads that were performed in the eBPF code to use slimmer types and to use BPF helper macros for readability. Adds more tests as well as ebpf benchmarks.
1 parent 3bccbf9 commit cbef761

34 files changed

+3483
-1222
lines changed

.gitattributes

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
bpf/bpf_core_read.h linguist-vendored
2-
bpf/bpf_helper_defs.h linguist-vendored
3-
bpf/bpf_helpers.h linguist-vendored
4-
bpf/handler-bpfeb.o linguist-generated
5-
bpf/handler-bpfel.o linguist-generated
6-
bpf/vmlinux.h linguist-vendored
1+
bpf/bpf_core_read.h linguist-generated=true
2+
bpf/bpf_helper_defs.h linguist-generated=true
3+
bpf/bpf_helpers.h linguist-generated=true
4+
bpf/handler-bpfeb.o linguist-generated=true
5+
bpf/handler-bpfel.o linguist-generated=true
6+
bpf/vmlinux.h linguist-generated=true

.github/workflows/enterprise-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151

5252
- uses: actions/setup-go@v3
5353
with:
54-
go-version: "^1.20.7"
54+
go-version: "^1.21.9"
5555

5656
- name: Build binaries
5757
run: |

.github/workflows/enterprise.yaml

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ concurrency:
2929
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
3030

3131
jobs:
32-
test-go:
33-
name: "test/go"
32+
test-go-enterprise:
33+
name: "test/go-enterprise"
3434
runs-on: ubuntu-latest
3535
timeout-minutes: 20
3636
steps:
3737
- uses: actions/checkout@v3
3838
- uses: actions/setup-go@v3
3939
with:
40-
go-version: "^1.20.7"
40+
go-version: "^1.21.9"
4141

4242
- name: Echo Go Cache Paths
4343
id: go-cache-paths
@@ -57,59 +57,5 @@ jobs:
5757
path: ${{ steps.go-cache-paths.outputs.go-mod }}
5858
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
5959

60-
- name: Install gotestsum
61-
uses: jaxxstorm/[email protected]
62-
env:
63-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64-
with:
65-
repo: gotestyourself/gotestsum
66-
tag: v1.10.1
67-
6860
- name: Test
69-
shell: bash
70-
run: |
71-
set +e
72-
gotestsum \
73-
--junitfile="gotests.xml" \
74-
--jsonfile="gotestsum.json" \
75-
--packages="./..." \
76-
--debug \
77-
-- \
78-
-exec sudo \
79-
-parallel=8 \
80-
-timeout=5m \
81-
-short \
82-
-failfast \
83-
-covermode=atomic \
84-
-coverprofile="gotests.coverage" \
85-
-coverpkg=./...
86-
ret=$?
87-
set -e
88-
if ((ret)); then
89-
# Eternalize test timeout logs because "re-run failed" erases
90-
# artifacts and gotestsum doesn't always capture it:
91-
# https://github.com/gotestyourself/gotestsum/issues/292
92-
# Multiple test packages could've failed, each one may or may
93-
# not run into the edge case. PS. Don't summon ShellCheck here.
94-
for testWithStack in $(grep 'panic: test timed out' gotestsum.json | grep -E -o '("Test":[^,}]*)'); do
95-
if [ -n "$testWithStack" ] && grep -q "${testWithStack}.*PASS" gotestsum.json; then
96-
echo "Conditions met for gotestsum stack trace missing bug, outputting panic trace:"
97-
grep -A 999999 "${testWithStack}.*panic: test timed out" gotestsum.json
98-
fi
99-
done
100-
fi
101-
exit $ret
102-
103-
- uses: actions/upload-artifact@v3
104-
if: success() || failure()
105-
with:
106-
name: gotestsum-debug.json
107-
path: ./gotestsum.json
108-
retention-days: 7
109-
110-
- uses: actions/upload-artifact@v3
111-
if: success() || failure()
112-
with:
113-
name: gotests.xml
114-
path: ./gotests.xml
115-
retention-days: 30
61+
run: make test/go-enterprise

.github/workflows/quality.yml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Install Go
3737
uses: actions/setup-go@v2
3838
with:
39-
go-version: "^1.20.7"
39+
go-version: "^1.21.9"
4040

4141
- name: Run make fmt/go
4242
run: make fmt/go
@@ -75,12 +75,12 @@ jobs:
7575
- name: Install Go
7676
uses: actions/setup-go@v2
7777
with:
78-
go-version: "^1.20.7"
78+
go-version: "^1.21.9"
7979

8080
- name: Install golangci-lint
8181
run: |
8282
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
83-
| sh -s -- -b $(go env GOPATH)/bin v1.53.2
83+
| sh -s -- -b $(go env GOPATH)/bin v1.57.2
8484
8585
# Linting needs to be done on each build variation of GOOS.
8686
- name: Run make lint/go/linux
@@ -90,6 +90,37 @@ jobs:
9090
- name: Run make lint/go/other
9191
run: make lint/go/other
9292

93+
test-go:
94+
name: "test/go"
95+
runs-on: ubuntu-latest
96+
timeout-minutes: 20
97+
steps:
98+
- uses: actions/checkout@v3
99+
- uses: actions/setup-go@v3
100+
with:
101+
go-version: "^1.21.9"
102+
103+
- name: Echo Go Cache Paths
104+
id: go-cache-paths
105+
run: |
106+
echo "::set-output name=go-build::$(go env GOCACHE)"
107+
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
108+
109+
- name: Go Build Cache
110+
uses: actions/cache@v3
111+
with:
112+
path: ${{ steps.go-cache-paths.outputs.go-build }}
113+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }}
114+
115+
- name: Go Mod Cache
116+
uses: actions/cache@v3
117+
with:
118+
path: ${{ steps.go-cache-paths.outputs.go-mod }}
119+
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
120+
121+
- name: Test
122+
run: make test/go
123+
93124
lint-c:
94125
name: lint/c
95126
runs-on: ubuntu-20.04
@@ -100,6 +131,14 @@ jobs:
100131
- name: Run make lint/c
101132
run: make lint/c
102133

134+
- name: Ensure DEBUG is disabled
135+
run: |
136+
# look for uncommented "#define DEBUG" in bpf/handler.c
137+
if grep -q "^#define DEBUG" bpf/handler.c; then
138+
echo "DEBUG is enabled in bpf/handler.c"
139+
exit 1
140+
fi
141+
103142
lint-shellcheck:
104143
name: lint/shellcheck
105144
runs-on: ubuntu-20.04

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ build
3333
*.tfplan
3434
*.lock.hcl
3535
.terraform/
36+
37+
/exectrace

.golangci.yaml

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,30 @@ linters-settings:
2020
enabled-checks:
2121
# - appendAssign
2222
# - appendCombine
23-
- argOrder
23+
#- argOrder
2424
# - assignOp
2525
# - badCall
26-
- badCond
26+
#- badCond
2727
- badLock
2828
- badRegexp
2929
- boolExprSimplify
3030
# - builtinShadow
3131
- builtinShadowDecl
32-
- captLocal
33-
- caseOrder
34-
- codegenComment
32+
#- captLocal
33+
#- caseOrder
34+
#- codegenComment
3535
# - commentedOutCode
3636
- commentedOutImport
37-
- commentFormatting
38-
- defaultCaseOrder
37+
#- commentFormatting
38+
#- defaultCaseOrder
3939
- deferUnlambda
4040
# - deprecatedComment
4141
# - docStub
42-
- dupArg
43-
- dupBranchBody
44-
- dupCase
42+
#- dupArg
43+
#- dupBranchBody
44+
#- dupCase
4545
- dupImport
46-
- dupSubExpr
46+
#- dupSubExpr
4747
# - elseif
4848
- emptyFallthrough
4949
# - emptyStringTest
@@ -52,56 +52,56 @@ linters-settings:
5252
# - exitAfterDefer
5353
# - exposedSyncMutex
5454
# - filepathJoin
55-
- flagDeref
56-
- flagName
55+
#- flagDeref
56+
#- flagName
5757
- hexLiteral
5858
# - httpNoBody
5959
# - hugeParam
6060
# - ifElseChain
6161
# - importShadow
6262
- indexAlloc
6363
- initClause
64-
- mapKey
64+
#- mapKey
6565
- methodExprCall
6666
# - nestingReduce
67-
- newDeref
67+
#- newDeref
6868
- nilValReturn
6969
# - octalLiteral
70-
- offBy1
70+
#- offBy1
7171
# - paramTypeCombine
7272
# - preferStringWriter
7373
# - preferWriteByte
7474
# - ptrToRefParam
7575
# - rangeExprCopy
7676
# - rangeValCopy
77-
- regexpMust
77+
#- regexpMust
7878
- regexpPattern
7979
# - regexpSimplify
8080
#- ruleguard
81-
- singleCaseSwitch
82-
- sloppyLen
81+
#- singleCaseSwitch
82+
#- sloppyLen
8383
# - sloppyReassign
84-
- sloppyTypeAssert
84+
#- sloppyTypeAssert
8585
- sortSlice
8686
- sprintfQuotedString
8787
- sqlQuery
8888
# - stringConcatSimplify
8989
# - stringXbytes
9090
# - suspiciousSorting
91-
- switchTrue
91+
#- switchTrue
9292
- truncateCmp
9393
- typeAssertChain
9494
# - typeDefFirst
95-
- typeSwitchVar
95+
#- typeSwitchVar
9696
# - typeUnparen
97-
- underef
97+
#- underef
9898
# - unlabelStmt
9999
# - unlambda
100100
# - unnamedResult
101101
# - unnecessaryBlock
102102
# - unnecessaryDefer
103103
# - unslice
104-
- valSwap
104+
#- valSwap
105105
- weakCond
106106
# - whyNoLint
107107
# - wrapperFunc
@@ -207,15 +207,17 @@ issues:
207207
linters:
208208
- exhaustruct
209209

210+
exclude-files:
211+
- scripts/rules.go
212+
213+
exclude-dirs:
214+
- node_modules
215+
210216
fix: true
211217
max-issues-per-linter: 0
212218
max-same-issues: 0
213219

214220
run:
215-
skip-dirs:
216-
- node_modules
217-
skip-files:
218-
- scripts/rules.go
219221
timeout: 10m
220222

221223
# Over time, add more and more linters from

Makefile

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ handlers: bpf/handler-bpfeb.o bpf/handler-bpfel.o
2424
clean: clean-enterprise
2525
rm -rf bpf/handler-bpfeb.o bpf/handler-bpfel.o
2626

27-
ci/.clang-image: ci/images/clang-13/Dockerfile
27+
ci/.clang-image: ci/images/clang-13/Dockerfile ci/scripts/clang_image.sh
2828
./ci/scripts/clang_image.sh
2929
touch ci/.clang-image
3030

3131
# bpfeb is big endian, bpfel is little endian.
32-
bpf/handler-bpfeb.o bpf/handler-bpfel.o: bpf/*.h bpf/*.c ci/.clang-image
32+
bpf/handler-bpfeb.o bpf/handler-bpfel.o: bpf/*.h bpf/*.c ci/.clang-image ci/scripts/build_handler.sh
3333
./ci/scripts/build_handler.sh "$(@F)"
3434

3535
.PHONY: fmt
@@ -76,22 +76,20 @@ lint/shellcheck:
7676
./ci/scripts/shellcheck.sh
7777

7878
.PHONY: test
79-
test: test/go
79+
test: test/go test/go-enterprise
8080

8181
.PHONY: test/go
8282
test/go:
83-
go clean -testcache
84-
gotestsum --debug -- -v -short ./...
83+
go test -exec sudo -v -count 1 ./...
84+
85+
.PHONY: test/go-enterprise
86+
test/go-enterprise:
8587
cd enterprise
86-
gotestsum --debug -- -v -short ./...
88+
go test -exec sudo -v -count 1 ./...
8789

88-
# test/go-sudo is equivalent to test/go but runs the test binary using sudo.
89-
# Some tests are skipped if not running as root.
90-
.PHONY: test/go-sudo
91-
test/go-sudo:
90+
.PHONY: bench
91+
bench:
9292
go clean -testcache
93-
gotestsum --debug -- -exec sudo -v -short ./...
94-
cd enterprise
95-
gotestsum --debug -- -exec sudo -v -short ./...
93+
COUNT=10000 ./bench/bench.sh
9694

9795
include Makefile.enterprise

0 commit comments

Comments
 (0)