-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathMakefile
236 lines (192 loc) · 7.63 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Copyright (c) 2023 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0
THRIFT_VER?=0.19
THRIFT_IMG?=jaegertracing/thrift:$(THRIFT_VER)
THRIFT=docker run --rm -u $(shell id -u) -v "${PWD}:/data" $(THRIFT_IMG) thrift
SWAGGER_VER=0.31.0
SWAGGER_IMAGE=quay.io/goswagger/swagger:$(SWAGGER_VER)
SWAGGER=docker run --rm -u ${shell id -u} -v "${PWD}:/go/src/${PROJECT_ROOT}" -w /go/src/${PROJECT_ROOT} $(SWAGGER_IMAGE)
PROTOTOOL_VER=1.8.0
PROTOTOOL_IMAGE=uber/prototool:$(PROTOTOOL_VER)
PROTOTOOL=docker run --rm -u ${shell id -u} -v "${PWD}:/go/src/${PROJECT_ROOT}" -w /go/src/${PROJECT_ROOT} $(PROTOTOOL_IMAGE)
PROTOC_VER=0.5.0
PROTOC_IMAGE=jaegertracing/protobuf:$(PROTOC_VER)
PROTOC=docker run --rm -u ${shell id -u} -v "${PWD}:${PWD}" -w ${PWD} ${PROTOC_IMAGE} --proto_path=${PWD}
THRIFT_GO_ARGS=thrift_import="github.com/apache/thrift/lib/go/thrift"
THRIFT_PY_ARGS=new_style,tornado
THRIFT_JAVA_ARGS=private-members
THRIFT_PHP_ARGS=psr4
THRIFT_GEN=--gen lua --gen go:$(THRIFT_GO_ARGS) --gen py:$(THRIFT_PY_ARGS) --gen java:$(THRIFT_JAVA_ARGS) --gen js:node --gen cpp --gen php:$(THRIFT_PHP_ARGS)
THRIFT_CMD=$(THRIFT) -o /data $(THRIFT_GEN)
THRIFT_FILES=agent.thrift jaeger.thrift sampling.thrift zipkincore.thrift crossdock/tracetest.thrift \
baggage.thrift dependency.thrift aggregation_validator.thrift
.PHONY: test-code-gen
test-code-gen: thrift swagger-validate protocompile proto proto-zipkin
git diff --exit-code ./swagger/api_v3/query_service.swagger.json
.PHONY: swagger-validate
swagger-validate:
$(SWAGGER) validate ./swagger/zipkin2-api.yaml
.PHONY: clean
clean:
rm -rf *gen-* || true
rm -rf .*gen-* || true
.PHONY: thrift
thrift: thrift-image clean $(THRIFT_FILES)
$(THRIFT_FILES):
@echo Compiling $@
$(THRIFT_CMD) /data/thrift/$@
.PHONY: thrift-image
thrift-image:
docker pull $(THRIFT_IMG)
$(THRIFT) -version
.PHONY: protocompile
protocompile:
$(PROTOTOOL) prototool compile proto --dry-run
PROTO_INCLUDES := \
-Iproto/api_v2 \
-Iproto \
-I/usr/include/github.com/gogo/protobuf \
-Iopentelemetry-proto
# Remapping of std types to gogo types (must not contain spaces)
PROTO_GOGO_MAPPINGS := $(shell echo \
Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/types, \
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types, \
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types, \
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types, \
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api, \
Mmodel.proto=github.com/jaegertracing/jaeger-idl/model/v1 \
| sed 's/ //g')
PROTO_GEN_GO_DIR ?= proto-gen
POLYGLOT_DIR_ROOT ?= .proto-gen-polyglot
PROTO_GEN_GO_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-go
PROTO_GEN_PYTHON_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-python
PROTO_GEN_JAVA_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-java
PROTO_GEN_JS_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-js
PROTO_GEN_CPP_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-cpp
PROTO_GEN_CSHARP_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-csharp
API_V2_PATH ?= api_v2
# The jaegertracing/protobuf container image does not
# include Java/C#/C++ plugins for Apple Silicon (arm64).
PROTOC_WITHOUT_GRPC_common := $(PROTOC) \
$(PROTO_INCLUDES) \
--gogo_out=plugins=grpc,$(PROTO_GOGO_MAPPINGS):$(PWD)/${PROTO_GEN_GO_DIR_POLYGLOT} \
--python_out=${PROTO_GEN_PYTHON_DIR_POLYGLOT} \
--js_out=${PROTO_GEN_JS_DIR_POLYGLOT}
ifeq ($(shell uname -m),arm64)
PROTOC_WITHOUT_GRPC := $(PROTOC_WITHOUT_GRPC_common)
else
PROTOC_WITHOUT_GRPC := $(PROTOC_WITHOUT_GRPC_common) \
--java_out=${PROTO_GEN_JAVA_DIR_POLYGLOT} \
--cpp_out=${PROTO_GEN_CPP_DIR_POLYGLOT} \
--csharp_out=base_namespace:${PROTO_GEN_CSHARP_DIR_POLYGLOT}
endif
PROTOC_WITH_GRPC_common := $(PROTOC_WITHOUT_GRPC) \
--grpc-python_out=${PROTO_GEN_PYTHON_DIR_POLYGLOT} \
--grpc-js_out=${PROTO_GEN_JS_DIR_POLYGLOT}
ifeq ($(shell uname -m),arm64)
PROTOC_WITH_GRPC := $(PROTOC_WITH_GRPC_common)
else
PROTOC_WITH_GRPC := $(PROTOC_WITH_GRPC_common) \
--grpc-java_out=${PROTO_GEN_JAVA_DIR_POLYGLOT} \
--grpc-cpp_out=${PROTO_GEN_CPP_DIR_POLYGLOT} \
--grpc-csharp_out=${PROTO_GEN_CSHARP_DIR_POLYGLOT}
endif
PROTOC_INTERNAL := $(PROTOC) \
$(PROTO_INCLUDES) \
--csharp_out=internal_access,base_namespace:${PROTO_GEN_CSHARP_DIR_POLYGLOT} \
--python_out=${PROTO_GEN_PYTHON_DIR_POLYGLOT}
GO=go
GOOS ?= $(shell $(GO) env GOOS)
GOARCH ?= $(shell $(GO) env GOARCH)
# sed on Mac does not support the same syntax for in-place updates as sed on Linux
# When running on MacOS it's best to install gsed and run Makefile with SED=gsed
ifeq ($(GOOS),darwin)
SED=gsed
else
SED=sed
endif
# DO NOT DELETE EMPTY LINE at the end of the macro, it's required to separate commands.
define print_caption
@echo "🏗️ "
@echo "🏗️ " $1
@echo "🏗️ "
endef
# Macro to compile Protobuf $(2) into directory $(1). $(3) can provide additional flags.
# DO NOT DELETE EMPTY LINE at the end of the macro, it's required to separate commands.
# Arguments:
# $(1) - output directory
# $(2) - path to the .proto file
# $(3) - additional flags to pass to protoc, e.g. extra -Ixxx
# $(4) - additional options to pass to gogo plugin
define proto_compile
$(call print_caption, "Processing $(2) --> $(1)")
$(PROTOC) \
$(PROTO_INCLUDES) \
--gogo_out=plugins=grpc,$(strip $(4)),$(PROTO_GOGO_MAPPINGS):$(PWD)/$(strip $(1)) \
$(3) $(2)
endef
.PHONY: test-ci
test-ci:
go test -v -coverprofile=coverage.txt ./...
# proto target is used to generate source code that is released as part of this library
proto: proto-prepare proto-api-v2 proto-prototest
# proto-all target is used to generate code for all languages as a validation step.
proto-all: proto-prepare-all proto-api-v2-all proto-api-v3-all
.PHONY: proto-prepare-all
proto-prepare-all:
mkdir -p ${PROTO_GEN_GO_DIR_POLYGLOT} \
${PROTO_GEN_JAVA_DIR_POLYGLOT} \
${PROTO_GEN_PYTHON_DIR_POLYGLOT} \
${PROTO_GEN_JS_DIR_POLYGLOT} \
${PROTO_GEN_CPP_DIR_POLYGLOT} \
${PROTO_GEN_CSHARP_DIR_POLYGLOT}
.PHONY: proto-prepare
proto-prepare:
mkdir -p ${PROTO_GEN_GO_DIR}
.PHONY: proto-prototest
proto-prototest:
$(PROTOC) -Imodel/proto --go_out=$(PWD)/model/v1/ model/v1/prototest/model_test.proto
.PHONY: proto-api-v2
proto-api-v2:
mkdir -p ${PROTO_GEN_GO_DIR}/${API_V2_PATH}
$(call proto_compile, model/v1, proto/api_v2/model.proto)
$(call proto_compile, ${PROTO_GEN_GO_DIR}/${API_V2_PATH}, proto/api_v2/query.proto)
$(call proto_compile, ${PROTO_GEN_GO_DIR}/${API_V2_PATH}, proto/api_v2/collector.proto)
$(call proto_compile, ${PROTO_GEN_GO_DIR}/${API_V2_PATH}, proto/api_v2/sampling.proto)
.PHONY: proto-api-v2-all
proto-api-v2-all:
$(PROTOC_WITHOUT_GRPC) \
proto/api_v2/model.proto
$(PROTOC_WITH_GRPC) \
proto/api_v2/query.proto \
proto/api_v2/collector.proto \
proto/api_v2/sampling.proto
.PHONY: proto-api-v3-all
proto-api-v3-all:
# API v3
$(PROTOC_WITH_GRPC) \
proto/api_v3/query_service.proto
# GRPC gateway
$(PROTOC) \
$(PROTO_INCLUDES) \
--grpc-gateway_out=logtostderr=true,grpc_api_configuration=proto/api_v3/query_service_http.yaml,$(PROTO_GOGO_MAPPINGS):${PROTO_GEN_GO_DIR_POLYGLOT} \
proto/api_v3/query_service.proto
# Swagger
$(PROTOC) \
$(PROTO_INCLUDES) \
--swagger_out=disable_default_errors=true,logtostderr=true,grpc_api_configuration=proto/api_v3/query_service_http.yaml:./swagger \
proto/api_v3/query_service.proto
$(PROTOC_INTERNAL) \
google/api/annotations.proto \
google/api/http.proto \
protoc-gen-swagger/options/annotations.proto \
protoc-gen-swagger/options/openapiv2.proto \
gogoproto/gogo.proto
.PHONY: proto-zipkin
proto-zipkin: proto-prepare-all
$(PROTOC_WITHOUT_GRPC) \
proto/zipkin.proto
.PHONY: init-submodule
init-submodule:
git submodule init
git submodule update --recursive