]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | #!/bin/bash |
2 | ||
3 | # Copyright The OpenTelemetry Authors | |
4 | # SPDX-License-Identifier: Apache-2.0 | |
5 | ||
6 | set -e | |
7 | ||
8 | function install_prometheus_cpp_client | |
9 | { | |
10 | pushd third_party/prometheus-cpp | |
11 | git submodule update --recursive --init | |
12 | [[ -d _build ]] && rm -rf ./_build | |
13 | mkdir _build && cd _build | |
14 | cmake .. -DBUILD_SHARED_LIBS=ON -DUSE_THIRDPARTY_LIBRARIES=ON | |
15 | make -j 4 | |
16 | sudo make install | |
17 | popd | |
18 | } | |
19 | ||
20 | function run_benchmarks | |
21 | { | |
22 | docker run -d --rm -it -p 4317:4317 -p 4318:4318 -v \ | |
23 | $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.38.0 \ | |
24 | --config=/cfg/opentelemetry-collector-config/config.dev.yaml | |
25 | ||
26 | [ -z "${BENCHMARK_DIR}" ] && export BENCHMARK_DIR=$HOME/benchmark | |
27 | mkdir -p $BENCHMARK_DIR | |
28 | bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS -c opt -- \ | |
29 | $(bazel query 'attr("tags", "benchmark_result", ...)') | |
30 | echo "" | |
31 | echo "Benchmark results in $BENCHMARK_DIR:" | |
32 | ( | |
33 | cd bazel-bin | |
34 | find . -name \*_result.json -exec bash -c \ | |
35 | 'echo "$@" && mkdir -p "$BENCHMARK_DIR/$(dirname "$@")" && \ | |
36 | cp "$@" "$BENCHMARK_DIR/$@" && chmod +w "$BENCHMARK_DIR/$@"' _ {} \; | |
37 | ) | |
38 | ||
39 | # collect benchmark results into one array | |
40 | pushd $BENCHMARK_DIR | |
41 | components=(api sdk exporters) | |
42 | for component in "${components[@]}" | |
43 | do | |
44 | out=$component-benchmark_result.json | |
45 | find ./$component -type f -name "*_result.json" -exec cat {} \; > $component_tmp_bench.json | |
46 | cat $component_tmp_bench.json | docker run -i --rm itchyny/gojq:0.12.6 -s \ | |
47 | '.[0].benchmarks = ([.[].benchmarks] | add) | | |
48 | if .[0].benchmarks == null then null else .[0] end' > $BENCHMARK_DIR/$out | |
49 | done | |
50 | ||
51 | mv *benchmark_result.json ${SRC_DIR} | |
52 | popd | |
53 | docker kill $(docker ps -q) | |
54 | } | |
55 | ||
56 | [ -z "${SRC_DIR}" ] && export SRC_DIR="`pwd`" | |
57 | [ -z "${BUILD_DIR}" ] && export BUILD_DIR=$HOME/build | |
58 | mkdir -p "${BUILD_DIR}" | |
59 | [ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin | |
60 | mkdir -p "${PLUGIN_DIR}" | |
61 | ||
62 | BAZEL_OPTIONS="--copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST" | |
63 | # Previous legacy metrics use virtual drive, which can not be used without RTTI | |
64 | if [[ "$1" != "bazel.nortti" ]]; then | |
65 | BAZEL_OPTIONS="$BAZEL_OPTIONS --copt=-DENABLE_METRICS_PREVIEW" | |
66 | fi | |
67 | BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors" | |
68 | ||
69 | # https://github.com/bazelbuild/bazel/issues/4341 | |
70 | BAZEL_MACOS_OPTIONS="$BAZEL_OPTIONS --features=-supports_dynamic_linker --build_tag_filters=-jaeger" | |
71 | BAZEL_MACOS_TEST_OPTIONS="$BAZEL_MACOS_OPTIONS --test_output=errors" | |
72 | ||
73 | BAZEL_STARTUP_OPTIONS="--output_user_root=$HOME/.cache/bazel" | |
74 | ||
75 | export CTEST_OUTPUT_ON_FAILURE=1 | |
76 | ||
77 | if [[ "$1" == "cmake.test" ]]; then | |
78 | cd "${BUILD_DIR}" | |
79 | rm -rf * | |
80 | cmake -DCMAKE_BUILD_TYPE=Debug \ | |
81 | -DWITH_PROMETHEUS=ON \ | |
82 | -DWITH_ZIPKIN=ON \ | |
83 | -DWITH_JAEGER=ON \ | |
84 | -DWITH_ELASTICSEARCH=ON \ | |
85 | -DWITH_METRICS_PREVIEW=ON \ | |
86 | -DWITH_LOGS_PREVIEW=ON \ | |
87 | -DCMAKE_CXX_FLAGS="-Werror" \ | |
88 | "${SRC_DIR}" | |
89 | make | |
90 | make test | |
91 | exit 0 | |
92 | elif [[ "$1" == "cmake.abseil.test" ]]; then | |
93 | cd "${BUILD_DIR}" | |
94 | rm -rf * | |
95 | cmake -DCMAKE_BUILD_TYPE=Debug \ | |
96 | -DWITH_METRICS_PREVIEW=ON \ | |
97 | -DWITH_LOGS_PREVIEW=ON \ | |
98 | -DCMAKE_CXX_FLAGS="-Werror" \ | |
99 | -DWITH_ABSEIL=ON \ | |
100 | "${SRC_DIR}" | |
101 | make | |
102 | make test | |
103 | exit 0 | |
104 | elif [[ "$1" == "cmake.c++20.test" ]]; then | |
105 | cd "${BUILD_DIR}" | |
106 | rm -rf * | |
107 | cmake -DCMAKE_BUILD_TYPE=Debug \ | |
108 | -DCMAKE_CXX_FLAGS="-Werror" \ | |
109 | -DCMAKE_CXX_STANDARD=20 \ | |
110 | "${SRC_DIR}" | |
111 | make | |
112 | make test | |
113 | exit 0 | |
114 | elif [[ "$1" == "cmake.c++20.stl.test" ]]; then | |
115 | cd "${BUILD_DIR}" | |
116 | rm -rf * | |
117 | cmake -DCMAKE_BUILD_TYPE=Debug \ | |
118 | -DWITH_METRICS_PREVIEW=ON \ | |
119 | -DWITH_LOGS_PREVIEW=ON \ | |
120 | -DCMAKE_CXX_FLAGS="-Werror" \ | |
121 | -DWITH_STL=ON \ | |
122 | "${SRC_DIR}" | |
123 | make | |
124 | make test | |
125 | exit 0 | |
126 | elif [[ "$1" == "cmake.legacy.test" ]]; then | |
127 | cd "${BUILD_DIR}" | |
128 | rm -rf * | |
129 | export BUILD_ROOT="${BUILD_DIR}" | |
130 | ${SRC_DIR}/tools/build-gtest.sh | |
131 | ${SRC_DIR}/tools/build-benchmark.sh | |
132 | cmake -DCMAKE_BUILD_TYPE=Debug \ | |
133 | -DCMAKE_CXX_FLAGS="-Werror" \ | |
134 | -DCMAKE_CXX_STANDARD=11 \ | |
135 | "${SRC_DIR}" | |
136 | make | |
137 | make test | |
138 | exit 0 | |
139 | elif [[ "$1" == "cmake.legacy.exporter.otprotocol.test" ]]; then | |
140 | cd "${BUILD_DIR}" | |
141 | rm -rf * | |
142 | export BUILD_ROOT="${BUILD_DIR}" | |
143 | ${SRC_DIR}/tools/build-gtest.sh | |
144 | ${SRC_DIR}/tools/build-benchmark.sh | |
145 | cmake -DCMAKE_BUILD_TYPE=Debug \ | |
146 | -DCMAKE_CXX_STANDARD=11 \ | |
147 | -DWITH_OTLP=ON \ | |
148 | "${SRC_DIR}" | |
149 | grpc_cpp_plugin=`which grpc_cpp_plugin` | |
150 | proto_make_file="CMakeFiles/opentelemetry_proto.dir/build.make" | |
151 | sed -i "s~gRPC_CPP_PLUGIN_EXECUTABLE-NOTFOUND~$grpc_cpp_plugin~" ${proto_make_file} #fixme | |
152 | make -j $(nproc) | |
153 | cd exporters/otlp && make test | |
154 | exit 0 | |
155 | elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then | |
156 | cd "${BUILD_DIR}" | |
157 | rm -rf * | |
158 | cmake -DCMAKE_BUILD_TYPE=Debug \ | |
159 | -DWITH_OTLP=ON \ | |
160 | "${SRC_DIR}" | |
161 | grpc_cpp_plugin=`which grpc_cpp_plugin` | |
162 | proto_make_file="CMakeFiles/opentelemetry_proto.dir/build.make" | |
163 | sed -i "s~gRPC_CPP_PLUGIN_EXECUTABLE-NOTFOUND~$grpc_cpp_plugin~" ${proto_make_file} #fixme | |
164 | make -j $(nproc) | |
165 | cd exporters/otlp && make test | |
166 | exit 0 | |
167 | elif [[ "$1" == "bazel.with_abseil" ]]; then | |
168 | bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS --//api:with_abseil=true //... | |
169 | bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS --//api:with_abseil=true //... | |
170 | exit 0 | |
171 | elif [[ "$1" == "cmake.test_example_plugin" ]]; then | |
172 | # Build the plugin | |
173 | cd "${BUILD_DIR}" | |
174 | rm -rf * | |
175 | cat <<EOF > export.map | |
176 | { | |
177 | global: | |
178 | OpenTelemetryMakeFactoryImpl; | |
179 | local: *; | |
180 | }; | |
181 | EOF | |
182 | ||
183 | LINKER_FLAGS="\ | |
184 | -static-libstdc++ \ | |
185 | -static-libgcc \ | |
186 | -Wl,--version-script=${PWD}/export.map \ | |
187 | " | |
188 | cmake -DCMAKE_BUILD_TYPE=Debug \ | |
189 | -DCMAKE_CXX_FLAGS="-Werror" \ | |
190 | -DCMAKE_EXE_LINKER_FLAGS="$LINKER_FLAGS" \ | |
191 | -DCMAKE_SHARED_LINKER_FLAGS="$LINKER_FLAGS" \ | |
192 | "${SRC_DIR}" | |
193 | make example_plugin | |
194 | cp examples/plugin/plugin/libexample_plugin.so ${PLUGIN_DIR} | |
195 | ||
196 | # Verify we can load the plugin | |
197 | cd "${BUILD_DIR}" | |
198 | rm -rf * | |
199 | cmake -DCMAKE_BUILD_TYPE=Debug \ | |
200 | -DCMAKE_CXX_FLAGS="-Werror" \ | |
201 | "${SRC_DIR}" | |
202 | make load_plugin_example | |
203 | examples/plugin/load/load_plugin_example ${PLUGIN_DIR}/libexample_plugin.so /dev/null | |
204 | exit 0 | |
205 | elif [[ "$1" == "bazel.test" ]]; then | |
206 | bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS //... | |
207 | bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS //... | |
208 | exit 0 | |
209 | elif [[ "$1" == "bazel.benchmark" ]]; then | |
210 | run_benchmarks | |
211 | exit 0 | |
212 | elif [[ "$1" == "bazel.macos.test" ]]; then | |
213 | bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_MACOS_OPTIONS -- //... -//exporters/jaeger/... | |
214 | bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_MACOS_TEST_OPTIONS -- //... -//exporters/jaeger/... | |
215 | exit 0 | |
216 | elif [[ "$1" == "bazel.legacy.test" ]]; then | |
217 | # we uses C++ future and async() function to test the Prometheus Exporter functionality, | |
218 | # that make this test always fail. ignore Prometheus exporter here. | |
219 | bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS -- //... -//exporters/otlp/... -//exporters/prometheus/... | |
220 | bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS -- //... -//exporters/otlp/... -//exporters/prometheus/... | |
221 | exit 0 | |
222 | elif [[ "$1" == "bazel.noexcept" ]]; then | |
223 | # there are some exceptions and error handling code from the Prometheus and Jaeger Clients | |
224 | # that make this test always fail. ignore Prometheus and Jaeger exporters in the noexcept here. | |
225 | bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... -//examples/prometheus/... | |
226 | bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... -//examples/prometheus/... | |
227 | exit 0 | |
228 | elif [[ "$1" == "bazel.nortti" ]]; then | |
229 | # there are some exceptions and error handling code from the Prometheus and Jaeger Clients | |
230 | # that make this test always fail. ignore Prometheus and Jaeger exporters in the noexcept here. | |
231 | bazel $BAZEL_STARTUP_OPTIONS build --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... | |
232 | bazel $BAZEL_STARTUP_OPTIONS test --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... | |
233 | exit 0 | |
234 | elif [[ "$1" == "bazel.asan" ]]; then | |
235 | bazel $BAZEL_STARTUP_OPTIONS test --config=asan $BAZEL_TEST_OPTIONS //... | |
236 | exit 0 | |
237 | elif [[ "$1" == "bazel.tsan" ]]; then | |
238 | bazel $BAZEL_STARTUP_OPTIONS test --config=tsan $BAZEL_TEST_OPTIONS //... | |
239 | exit 0 | |
240 | elif [[ "$1" == "bazel.valgrind" ]]; then | |
241 | bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS //... | |
242 | bazel $BAZEL_STARTUP_OPTIONS test --run_under="/usr/bin/valgrind --leak-check=full --error-exitcode=1 --suppressions=\"${SRC_DIR}/ci/valgrind-suppressions\"" $BAZEL_TEST_OPTIONS //... | |
243 | exit 0 | |
244 | elif [[ "$1" == "benchmark" ]]; then | |
245 | [ -z "${BENCHMARK_DIR}" ] && export BENCHMARK_DIR=$HOME/benchmark | |
246 | bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS -c opt -- \ | |
247 | $(bazel query 'attr("tags", "benchmark_result", ...)') | |
248 | echo "" | |
249 | echo "Benchmark results in $BENCHMARK_DIR:" | |
250 | ( | |
251 | cd bazel-bin | |
252 | find . -name \*_result.json -exec bash -c \ | |
253 | 'echo "$@" && mkdir -p "$BENCHMARK_DIR/$(dirname "$@")" && \ | |
254 | cp "$@" "$BENCHMARK_DIR/$@" && chmod +w "$BENCHMARK_DIR/$@"' _ {} \; | |
255 | ) | |
256 | exit 0 | |
257 | elif [[ "$1" == "format" ]]; then | |
258 | tools/format.sh | |
259 | CHANGED="$(git ls-files --modified)" | |
260 | if [[ ! -z "$CHANGED" ]]; then | |
261 | echo "The following files have changes:" | |
262 | echo "$CHANGED" | |
263 | git diff | |
264 | exit 1 | |
265 | fi | |
266 | exit 0 | |
267 | elif [[ "$1" == "code.coverage" ]]; then | |
268 | cd "${BUILD_DIR}" | |
269 | rm -rf * | |
270 | cmake -DCMAKE_BUILD_TYPE=Debug \ | |
271 | -DCMAKE_CXX_FLAGS="-Werror --coverage" \ | |
272 | "${SRC_DIR}" | |
273 | make | |
274 | make test | |
275 | lcov --directory $PWD --capture --output-file coverage.info | |
276 | # removing test http server coverage from the total coverage. We don't use this server completely. | |
277 | lcov --remove coverage.info '*/ext/http/server/*'> tmp_coverage.info 2>/dev/null | |
278 | cp tmp_coverage.info coverage.info | |
279 | exit 0 | |
280 | elif [[ "$1" == "third_party.tags" ]]; then | |
281 | echo "gRPC=v1.43.2" > third_party_release | |
282 | echo "thrift=0.14.1" >> third_party_release | |
283 | echo "abseil=20210324.0" >> third_party_release | |
284 | git submodule foreach --quiet 'echo "$name=$(git describe --tags HEAD)"' | sed 's:.*/::' >> third_party_release | |
285 | exit 0 | |
286 | fi | |
287 | ||
288 | echo "Invalid do_ci.sh target, see ci/README.md for valid targets." | |
289 | exit 1 |