forked from kubewharf/kelemetry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
206 lines (171 loc) · 6.69 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
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
default: run
SHELL := /usr/bin/env bash
RUN_ID := $(shell head /dev/urandom | cksum | md5sum | head -c8)
NUM_PARTITIONS ?= 5
PARTITIONS ?= $(shell seq -s, 0 $$(($(NUM_PARTITIONS) - 1)) | sed 's/,$$//')
KUBECONFIG ?= ~/.kube/config
CLUSTER_NAME ?= tracetest
KUBECONFIGS ?= $(CLUSTER_NAME)=$(KUBECONFIG)
PORT ?= 8080
LOG_LEVEL ?= info
KLOG_VERBOSITY ?= 3
RACE_ARG := -race
ifdef SKIP_DETECT_RACE
RACE_ARG :=
endif
DUMP_FILE ?= dump.json
ifneq ($(DUMP_FILE),)
DUMP_ARG := --audit-dump-file="$(DUMP_FILE)"
DUMP_ROTATE_DEP := dump-rotate
endif
DUMP_ROTATE ?= 5
ifdef LOG_FILE
LOG_FILE_ARG ?= --log-file="$(LOG_FILE)"
else
LOG_FILE_ARG ?=
endif
LINKER_WORKER_COUNT ?= 1
CONTROLLERS ?= audit-consumer,audit-producer,audit-webhook,event-informer,annotation-linker,owner-linker,resource-object-tag,resource-event-tag,diff-decorator,diff-controller,diff-api,pprof,jaeger-storage-plugin,jaeger-redirect-server,kelemetrix
ifeq ($(CONTROLLERS),)
ENABLE_ARGS ?=
else
ENABLE_ARGS ?= --$(shell echo $(CONTROLLERS) | sed -e 's/,/-enable --/g')-enable
endif
ifdef ENABLE_TLS
TLS_ARGS := --http-tls-cert=hack/cert --http-tls-key=hack/key
else
TLS_ARGS :=
endif
OTEL_EXPORTER_OTLP_ENDPOINT ?= 127.0.0.1:4317
INTEGRATION_ARG :=
ifdef INTEGRATION
INTEGRATION_ARG := -tags=integration
endif
ETCD_OR_LOCAL := local
ifdef USE_ETCD
ETCD_OR_LOCAL := etcd
endif
OS_NAME ?= $(shell uname -s)
ifeq ($(OS_NAME), Darwin)
TAG := $(shell git describe --always --dirty --tags)
else
TAG := $(shell git describe --always)-$(shell git diff --exit-code >/dev/null && echo clean || (echo dirty- && git ls-files | xargs cat --show-all | crc32 /dev/stdin))
endif
.PHONY: run dump-rotate test usage dot kind stack pre-commit fmt local-docker-build e2e
run: output/kelemetry $(DUMP_ROTATE_DEP)
GIN_MODE=debug \
$(RUN_PREFIX) ./output/kelemetry $(RUN_SUFFIX) \
--mq=local \
--audit-consumer-partition=$(PARTITIONS) \
--http-address=0.0.0.0 \
--http-port=$(PORT) \
$(DUMP_ARG) \
$(TLS_ARGS) \
--kube-target-cluster=$(CLUSTER_NAME) \
--kube-target-rest-burst=100 \
--kube-target-rest-qps=100 \
--kube-config-paths $(KUBECONFIGS) \
--klog-v=$(KLOG_VERBOSITY) \
--log-level=$(LOG_LEVEL) \
--log-file=$(LOG_FILE) \
--aggregator-pseudo-span-global-tags=runId=$(RUN_ID) \
--aggregator-event-span-global-tags=run=$(RUN_ID) \
--linker-worker-count=$(LINKER_WORKER_COUNT) \
--pprof-addr=:6030 \
--diff-cache=$(ETCD_OR_LOCAL) \
--diff-cache-etcd-endpoints=127.0.0.1:2379 \
--diff-cache-wrapper-enable \
--diff-controller-leader-election-enable=false \
--event-informer-leader-election-enable=false \
--span-cache=$(ETCD_OR_LOCAL) \
--span-cache-etcd-endpoints=127.0.0.1:2379 \
--tracer-otel-endpoint=$(OTEL_EXPORTER_OTLP_ENDPOINT) \
--tracer-otel-insecure \
--object-cache-size=16777216 \
--jaeger-cluster-names=$(CLUSTER_NAME) \
--jaeger-storage-plugin-address=0.0.0.0:17271 \
--jaeger-backend=jaeger-storage \
--jaeger-trace-cache=$(ETCD_OR_LOCAL) \
--jaeger-trace-cache-etcd-endpoints=127.0.0.1:2379 \
--jaeger-storage.span-storage.type=grpc-plugin \
--jaeger-storage.grpc-storage.server=127.0.0.1:17272 \
$(ENABLE_ARGS) \
$(REST_ARGS)
dump-rotate:
for i in $(shell seq 1 $(DUMP_ROTATE) | tac); do \
if [ -f dump$$i.json ]; then \
mv dump$$i.json dump$$(( i + 1 )).json; \
fi; \
done
[ ! -f dump.json ] || mv dump.json dump1.json
test:
go test -v -race -coverpkg=./pkg/... -coverprofile=coverage.out $(INTEGRATION_ARG) $(BUILD_ARGS) ./pkg/...
usage: output/kelemetry
$(RUN_PREFIX) ./output/kelemetry $(RUN_SUFFIX) --usage=USAGE.txt
dot: output/kelemetry
$(RUN_PREFIX) ./output/kelemetry $(RUN_SUFFIX) --dot=depgraph.dot
dot -Tpng depgraph.dot >depgraph.png
dot -Tsvg depgraph.dot >depgraph.svg
FIND_PATH =
ifeq ($(OS_NAME), Darwin)
FIND_PATH = .
endif
output/kelemetry: go.mod go.sum $(shell find $(FIND_PATH) -type f -name "*.go")
go build -v $(RACE_ARG) -gcflags=$(GCFLAGS) -ldflags=$(LDFLAGS) -o $@ $(BUILD_ARGS) .
kind:
kind delete cluster --name tracetest
docker network create kind || true # create if not exist; if fail, next step will fail anyway
sed "s/host.docker.internal/$$( \
docker network inspect kind -f '{{(index .IPAM.Config 0).Gateway}}' \
)/g" hack/audit-kubeconfig.yaml >hack/audit-kubeconfig.local.yaml
sed "s/host.docker.internal/$$( \
docker network inspect kind -f '{{(index .IPAM.Config 0).Gateway}}' \
)/g" hack/tracing-config.yaml >hack/tracing-config.local.yaml
cd hack && kind create cluster --config kind-cluster.yaml
COMPOSE_COMMAND ?= up --build -d --remove-orphans
stack:
docker compose -f dev.docker-compose.yaml up --no-recreate --no-start # create network only
docker compose \
-f dev.docker-compose.yaml \
-f <(jq -n \
--arg GATEWAY_ADDR $$(docker network inspect kelemetry_default -f '{{(index .IPAM.Config 0).Gateway}}') \
'.version = "2.2" | .services["jaeger-query"].environment.GRPC_STORAGE_SERVER = $$GATEWAY_ADDR + ":17271"' \
) \
$(COMPOSE_COMMAND)
define QUICKSTART_JQ_PATCH
.version = "2.2" |
if $$KELEMETRY_IMAGE == "" then .services.kelemetry.build = "." else . end |
if $$KELEMETRY_IMAGE != "" then .services.kelemetry.image = $$KELEMETRY_IMAGE else . end
endef
SED_I_FLAG =
ifeq ($(OS_NAME), Darwin)
SED_I_FLAG = ''
endif
export QUICKSTART_JQ_PATCH
quickstart:
echo $(COMPOSE_COMMAND)
docker compose -f quickstart.docker-compose.yaml \
-f <(jq -n --arg KELEMETRY_IMAGE "$(KELEMETRY_IMAGE)" "$$QUICKSTART_JQ_PATCH") \
up --no-recreate --no-start
kubectl config view --raw --minify --flatten --merge >hack/client-kubeconfig.local.yaml
sed -i $(SED_I_FLAG) "s/0\.0\.0\.0/$$(docker network inspect kelemetry_default -f '{{(index .IPAM.Config 0).Gateway}}')/g" hack/client-kubeconfig.local.yaml
sed -i $(SED_I_FLAG) 's/certificate-authority-data: .*$$/insecure-skip-tls-verify: true/' hack/client-kubeconfig.local.yaml
docker compose -f quickstart.docker-compose.yaml \
-f <(jq -n --arg KELEMETRY_IMAGE "$(KELEMETRY_IMAGE)" "$$QUICKSTART_JQ_PATCH") \
$(COMPOSE_COMMAND)
pre-commit: dot usage test
golangci-lint run --new-from-rev=main
fmt:
git add -A
go run mvdan.cc/gofumpt -l -w .
go run github.com/segmentio/golines -m140 --base-formatter=gofumpt -w .
go run golang.org/x/tools/cmd/goimports -l -w .
go run github.com/daixiang0/gci write -s standard -s default -s 'prefix(github.com/kubewharf/kelemetry)' .
local-docker-build:
make output/kelemetry
cp hack/tfconfig.yaml output
docker build --build-arg BIN_FILE=kelemetry --build-arg TFCONFIG=tfconfig.yaml -f ./hack/local.Dockerfile -t kelemetry:local output
e2e: local-docker-build
make quickstart COMPOSE_COMMAND='down --remove-orphans --volumes' KELEMETRY_IMAGE=kelemetry:local
make quickstart COMPOSE_COMMAND='up --build -d --remove-orphans' KELEMETRY_IMAGE=kelemetry:local
bash e2e/run-all.sh