forked from cloudflare/ebpf_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
100 lines (78 loc) · 3.05 KB
/
Makefile
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
.DEFAULT_GOAL := build
BUILD_VAR_PREFIX := github.com/prometheus/common/version
BUILD_USER := $(shell id -u -n)@$(shell hostname)
BUILD_DATE := $(shell date --iso-8601=seconds)
ifeq (yes,$(shell which git > /dev/null && test -e .git && echo yes))
BUILD_VERSION := $(shell git describe --tags)
BUILD_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
BUILD_REVISION := $(shell git rev-parse --short HEAD)
else
BUILD_VERSION := unknown
BUILD_BRANCH := unknown
BUILD_REVISION := unknown
endif
GO_LDFLAGS_VARS := -X $(BUILD_VAR_PREFIX).Version=$(BUILD_VERSION) \
-X $(BUILD_VAR_PREFIX).Branch=$(BUILD_BRANCH) \
-X $(BUILD_VAR_PREFIX).Revision=$(BUILD_REVISION) \
-X $(BUILD_VAR_PREFIX).BuildUser=$(BUILD_USER) \
-X $(BUILD_VAR_PREFIX).BuildDate=$(BUILD_DATE)
CLANG_FORMAT_FILES = ${wildcard examples/*.c examples/*.h benchmark/probes/*.c benchmark/probes/*.h}
# * cachestat-pre-kernel-5.16 fails to attach in newer kernels (see code)
# * kfree_skb doesn't load in ci, possibly due to older verifier
# * llcstat requires real hardware to attach perf events, which is not present in ci
# * pci doesn't load in ci, possibly due to older verifier
# * unix-socket-backlog requires a newer kernel than we have in ci
CONFIGS_TO_IGNORE_IN_CHECK := cachestat-pre-kernel-5.16 kfree_skb llcstat pci unix-socket-backlog
CONFIGS_TO_CHECK := $(filter-out $(CONFIGS_TO_IGNORE_IN_CHECK), ${patsubst examples/%.yaml, %, ${wildcard examples/*.yaml}})
CGO_LDFLAGS := -l bpf
include Makefile.libbpf
GO_TEST_ARGS = -v
# On aarch64 it's unavailable: FATAL: ThreadSanitizer: unsupported VMA range
ifneq ($(shell uname -m),aarch64)
GO_TEST_ARGS += -race
endif
.PHONY: lint
lint:
go mod verify
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" golangci-lint run ./...
.PHONY: jsonschema
jsonschema:
./scripts/jsonschema.sh
.PHONY: clang-format-check
clang-format-check:
./scripts/clang-format-check.sh $(CLANG_FORMAT_FILES)
.PHONY: test
test: $(LIBBPF_DEPS)
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go test -ldflags='-extldflags "-static"' $(GO_TEST_ARGS) ./...
.PHONY: test-privileged
test-privileged:
sudo go test $(GO_TEST_ARGS) ./cgroup
.PHONY: config-check
config-check:
sudo ./ebpf_exporter --capabilities.keep=none --config.check --config.strict --config.dir=examples --config.names=$(shell echo $(CONFIGS_TO_CHECK) | tr ' ' ',')
.PHONY: build
build: build-static
.PHONY: build-static
build-static:
$(MAKE) build-binary GO_BUILD_ARGS="-tags netgo,osusergo" GO_LDFLAGS='-extldflags "-static"'
.PHONY: build-dynamic
build-dynamic:
$(MAKE) build-binary
.PHONY: build-binary
build-binary: $(LIBBPF_DEPS)
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build $(GO_BUILD_ARGS) -o ebpf_exporter -v -ldflags="$(GO_LDFLAGS) $(GO_LDFLAGS_VARS)" ./cmd/ebpf_exporter
.PHONY: examples
examples:
$(MAKE) -C examples
.PHONY: tracing-demos
tracing-demos:
$(MAKE) -C tracing/demos
.PHONY: syscalls
syscalls:
go run ./scripts/mksyscalls --strace.version v6.8
.PHONY: clean
clean:
rm -rf ebpf_exporter libbpf
$(MAKE) -C tracing/demos clean
$(MAKE) -C examples clean
$(MAKE) -C benchmark clean