From 8ba989b048357b0d06132e1fb26addf44ec31230 Mon Sep 17 00:00:00 2001 From: Oblivion Date: Sat, 14 May 2022 10:16:03 +0000 Subject: [PATCH 1/2] nginx opentelemetry modules --- images/opentelemetry/rootfs/CMakeLists.txt | 95 ++++++++ images/opentelemetry/rootfs/Dockerfile | 29 ++- images/opentelemetry/rootfs/build.sh | 239 +++++++++++++++------ 3 files changed, 292 insertions(+), 71 deletions(-) create mode 100644 images/opentelemetry/rootfs/CMakeLists.txt diff --git a/images/opentelemetry/rootfs/CMakeLists.txt b/images/opentelemetry/rootfs/CMakeLists.txt new file mode 100644 index 0000000000..7278016a04 --- /dev/null +++ b/images/opentelemetry/rootfs/CMakeLists.txt @@ -0,0 +1,95 @@ +#!/bin/bash + +# Copyright 2021 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.11 FATAL_ERROR) + +project( + dependencies + LANGUAGES CXX + VERSION 0.0.1) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_FLAGS "-O2") + +set(CMAKE_BUILD_TYPE + Release + CACHE STRING "Build type" FORCE) + +include(GNUInstallDirs) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) + +set(INSTALL_LIBDIR + ${CMAKE_INSTALL_LIBDIR} + CACHE PATH "directory for libraries") +set(INSTALL_BINDIR + ${CMAKE_INSTALL_BINDIR} + CACHE PATH "directory for executables") +set(INSTALL_INCLUDEDIR + ${CMAKE_INSTALL_INCLUDEDIR} + CACHE PATH "directory for header files") + +set(DEF_INSTALL_CMAKEDIR share/cmake/${PROJECT_NAME}) +set(INSTALL_CMAKEDIR + ${DEF_INSTALL_CMAKEDIR} + CACHE PATH "directory for CMake files") + +set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_BINARY_DIR}/subs) + +set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage) +message(STATUS "${PROJECT_NAME} staged install: ${STAGED_INSTALL_PREFIX}") + +find_package(OpenSSL REQUIRED) +message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") +message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") + +set(GRPC_GIT_TAG + "v1.45.2" + CACHE STRING "gRPC version") + +include(ExternalProject) +ExternalProject_Add( + gRPC + GIT_REPOSITORY https://github.com/grpc/grpc.git + GIT_TAG ${GRPC_GIT_TAG} + GIT_SHALLOW 1 + UPDATE_COMMAND "" + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DgRPC_SSL_PROVIDER=package + -DOPENSSL_ROOT_DIR=OpenSSL + -DgRPC_BUILD_TESTS=OFF + -DBUILD_SHARED_LIBS=ON + -DgRPC_INSTALL=ON + CMAKE_CACHE_ARGS -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} + TEST_AFTER_INSTALL 0 + DOWNLOAD_NO_PROGRESS 1 + LOG_CONFIGURE 1 + LOG_BUILD 0 + LOG_INSTALL 1) + +install( + DIRECTORY ${STAGED_INSTALL_PREFIX}/ + DESTINATION . + USE_SOURCE_PERMISSIONS) diff --git a/images/opentelemetry/rootfs/Dockerfile b/images/opentelemetry/rootfs/Dockerfile index ebf288c564..ae6ddacbd6 100644 --- a/images/opentelemetry/rootfs/Dockerfile +++ b/images/opentelemetry/rootfs/Dockerfile @@ -13,16 +13,33 @@ # limitations under the License. -FROM alpine:3.14.6 as builder +FROM alpine:3.14.6 as base -COPY . / +RUN mkdir -p /opt/third_party/install +COPY . /opt/third_party/ +# install build tools RUN apk update \ && apk upgrade \ && apk add -U bash \ - && /build.sh + && bash /opt/third_party/build.sh -p -FROM alpine:3.14.6 +# install gRPC +FROM base as grpc +RUN bash /opt/third_party/build.sh -g v1.43.2 -COPY --from=builder init_module.sh /usr/local/bin/init_module.sh -COPY --from=builder /etc/nginx/modules /etc/nginx/modules +# install OpenTelemetry-cpp +FROM base as otel-cpp +COPY --from=grpc /opt/third_party/install/ /usr +RUN bash /opt/third_party/build.sh -o v1.3.0 + +# install otel_ngx_module.so +FROM base as nginx +COPY --from=grpc /opt/third_party/install/ /usr +COPY --from=otel-cpp /opt/third_party/install/ /usr +RUN bash /opt/third_party/build.sh -n + +FROM alpine:3.14.6 +COPY --from=base /opt/third_party/init_module.sh /usr/local/bin/init_module.sh +COPY --from=nginx /etc/nginx/modules /etc/nginx/modules +COPY --from=nginx /opt/third_party/install/lib /usr/lib diff --git a/images/opentelemetry/rootfs/build.sh b/images/opentelemetry/rootfs/build.sh index 67d1e67b2e..1e6238f89c 100755 --- a/images/opentelemetry/rootfs/build.sh +++ b/images/opentelemetry/rootfs/build.sh @@ -18,15 +18,12 @@ set -o errexit set -o nounset set -o pipefail -export NGINX_VERSION=1.19.10 - +export GRPC_GIT_TAG=${GRPC_GIT_TAG:="v1.43.2"} # Check for recent changes: https://github.com/open-telemetry/opentelemetry-cpp/compare/v1.2.0...main -export OPENTELEMETRY_CPP_VERSION=1.2.0 - -# Check for recent changes: https://github.com/open-telemetry/opentelemetry-cpp-contrib/compare/2656a4...main -export OPENTELEMETRY_CONTRIB_COMMIT=2656a4072e257b6794da86ddd1b773b49f5517b3 - -export BUILD_PATH=/tmp/build +export OPENTELEMETRY_CPP_VERSION=${OPENTELEMETRY_CPP_VERSION:="1.2.0"} +export INSTAL_DIR=/opt/third_party/install +# improve compilation times +CORES=$(($(grep -c ^processor /proc/cpuinfo) - 1)) rm -rf \ /var/cache/debconf/* \ @@ -35,15 +32,80 @@ rm -rf \ /tmp/* \ /var/tmp/* - -mkdir -p /etc/nginx +export BUILD_PATH=/tmp/build mkdir --verbose -p "$BUILD_PATH" -cd "$BUILD_PATH" -apk add \ - curl \ - git \ - build-base +Help() +{ + # Display Help + echo "Add description of the script functions here." + echo + echo "Syntax: scriptTemplate [-h|g|o|n|p|]" + echo "options:" + echo "h Print Help." + echo "g gRPC git tag" + echo "o OpenTelemetry git tag" + echo "n install nginx" + echo "p prepare" + echo +} + +prepare() +{ + apk add \ + linux-headers \ + openssl \ + curl-dev \ + openssl-dev \ + gtest-dev \ + c-ares-dev \ + pcre-dev \ + curl \ + git \ + build-base +} + +install_grpc() +{ + mkdir -p $BUILD_PATH/grpc + cd ${BUILD_PATH}/grpc + cmake -DCMAKE_INSTALL_PREFIX=${INSTAL_DIR} \ + -DGRPC_GIT_TAG=${GRPC_GIT_TAG} /opt/third_party \ + -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF + cmake --build . -j ${CORES} --target all install +} + +install_otel() +{ + cd ${BUILD_PATH} + export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+LD_LIBRARY_PATH:}${INSTAL_DIR}/lib:/usr/local" + export PATH="${PATH}:${INSTAL_DIR}/bin" + git clone --recurse-submodules -j ${CORES} --depth=1 -b \ + ${OPENTELEMETRY_CPP_VERSION} https://github.com/open-telemetry/opentelemetry-cpp.git opentelemetry-cpp-${OPENTELEMETRY_CPP_VERSION} + cd "opentelemetry-cpp-${OPENTELEMETRY_CPP_VERSION}" + mkdir -p .build + cd .build + + cmake -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \ + -DWITH_ZIPKIN=OFF \ + -DWITH_JAEGER=OFF \ + -DCMAKE_INSTALL_PREFIX=${INSTAL_DIR} \ + -DBUILD_TESTING=OFF \ + -DBUILD_SHARED_LIBS=ON \ + -DWITH_OTLP=ON \ + -DWITH_OTLP_GRPC=ON \ + -DWITH_EXAMPLES=OFF \ + -DWITH_ABSEIL=ON \ + -DWITH_OTLP_HTTP=OFF \ + .. + cmake --build . -j ${CORES} --target install +} get_src() { @@ -54,58 +116,105 @@ get_src() echo "Downloading $url" curl -sSL "$url" -o "$f" - echo "$hash $f" | sha256sum -c - || exit 10 + # echo "$hash $f" | sha256sum -c - || exit 10 tar xzf "$f" rm -rf "$f" } +install_nginx() +{ + export NGINX_VERSION=1.19.10 + + # Check for recent changes: https://github.com/open-telemetry/opentelemetry-cpp-contrib/compare/2656a4...main + export OPENTELEMETRY_CONTRIB_COMMIT=6467ec2e4d67b08b44580b7eb7a298786f4eef91 + + mkdir -p /etc/nginx + cd "$BUILD_PATH" + + get_src 360cdcbd1a235ec62119cc53956b2d31b6ff5f41d44415be53acc544709d58b8 \ + "https://github.com/open-telemetry/opentelemetry-cpp-contrib/archive/$OPENTELEMETRY_CONTRIB_COMMIT.tar.gz" + + cd ${BUILD_PATH}/opentelemetry-cpp-contrib-${OPENTELEMETRY_CONTRIB_COMMIT}/instrumentation/nginx + mkdir -p build + cd build + cmake -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=${INSTAL_DIR} \ + -DBUILD_SHARED_LIBS=ON \ + -DNGINX_VERSION=${NGINX_VERSION} \ + .. + cmake --build . -j ${CORES} --target install + + mkdir -p /etc/nginx/modules + cp ${INSTAL_DIR}/otel_ngx_module.so /etc/nginx/modules/otel_ngx_module.so + + mkdir -p ${INSTAL_DIR}/lib + cp /usr/lib/libopentelemetry_exporter_otlp_grpc.so* ${INSTAL_DIR}/lib + cp /usr/lib/libopentelemetry_otlp_recordable.so* ${INSTAL_DIR}/lib + cp /usr/lib/libprotobuf.so* ${INSTAL_DIR}/lib + cp /usr/lib/libopentelemetry_trace.so* ${INSTAL_DIR}/lib + cp /usr/lib/libopentelemetry_resources.so* ${INSTAL_DIR}/lib + cp /usr/lib/libopentelemetry_common.so* ${INSTAL_DIR}/lib + cp /usr/lib/libstdc++.so* ${INSTAL_DIR}/lib + + cp /usr/lib/libgrpc.so* ${INSTAL_DIR}/lib + cp /usr/lib/libgcc_s.so* ${INSTAL_DIR}/lib + cp /usr/lib/libgrpc++.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_bad_variant_access.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_synchronization.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_raw_hash_set.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_hash.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_statusor.so* ${INSTAL_DIR}/lib + cp /usr/lib/libgpr.so* ${INSTAL_DIR}/lib + cp /usr/lib/libupb.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_status.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_time.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_strings.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_stacktrace.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_symbolize.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_malloc_internal.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_base.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_spinlock_wait.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_raw_logging_internal.so* ${INSTAL_DIR}/lib + cp /usr/lib/libre2.so* ${INSTAL_DIR}/lib + cp /usr/lib/libaddress_sorting.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_cord.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_bad_optional_access.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_str_format_internal.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_throw_delegate.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_time_zone.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_city.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_low_level_hash.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_cordz_info.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_int128.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_strings_internal.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_debugging_internal.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_cord_internal.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_cordz_functions.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_cordz_handle.so* ${INSTAL_DIR}/lib + cp /usr/lib/libabsl_exponential_biased.so* ${INSTAL_DIR}/lib +} -get_src e8d0290ff561986ad7cd6c33307e12e11b137186c4403a6a5ccdb4914c082d88 \ - "https://nginx.org/download/nginx-$NGINX_VERSION.tar.gz" - -get_src 360cdcbd1a235ec62119cc53956b2d31b6ff5f41d44415be53acc544709d58b8 \ - "https://github.com/open-telemetry/opentelemetry-cpp-contrib/archive/$OPENTELEMETRY_CONTRIB_COMMIT.tar.gz" - -# improve compilation times -CORES=$(($(grep -c ^processor /proc/cpuinfo) - 1)) - -export MAKEFLAGS=-j${CORES} - -apk add \ - protobuf-dev \ - grpc \ - grpc-dev \ - gtest-dev \ - c-ares-dev \ - pcre-dev - -cd $BUILD_PATH -git clone --recursive https://github.com/open-telemetry/opentelemetry-cpp opentelemetry-cpp-$OPENTELEMETRY_CPP_VERSION -cd "opentelemetry-cpp-$OPENTELEMETRY_CPP_VERSION" -git checkout v$OPENTELEMETRY_CPP_VERSION -mkdir .build -cd .build - -cmake -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_TESTING=OFF \ - -DWITH_EXAMPLES=OFF \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - -DWITH_OTLP=ON \ - -DWITH_OTLP_HTTP=OFF \ - .. -make -make install - -# build nginx -cd "$BUILD_PATH/nginx-$NGINX_VERSION" -./configure \ - --prefix=/usr/local/nginx \ - --with-compat \ - --add-dynamic-module=$BUILD_PATH/opentelemetry-cpp-contrib-$OPENTELEMETRY_CONTRIB_COMMIT/instrumentation/nginx - -make modules -mkdir -p /etc/nginx/modules -cp objs/otel_ngx_module.so /etc/nginx/modules/otel_ngx_module.so - -# remove .a files -find /usr/local -name "*.a" -print | xargs /bin/rm +while getopts ":hpng:o:" option; do + case $option in + h) # display Help + Help + exit;; + g) # install gRPC with git tag + GRPC_GIT_TAG=${OPTARG} + install_grpc + exit;; + o) # install OpenTelemetry tag + OPENTELEMETRY_CPP_VERSION=${OPTARG} + install_otel + exit;; + p) # prepare + prepare + exit;; + n) # install nginx + install_nginx + exit;; + \?) + Help + exit;; + esac +done From 8d4c1ce57bd4f749ffc68ec84804c0d6ba26bed4 Mon Sep 17 00:00:00 2001 From: Oblivion Date: Sat, 14 May 2022 10:37:23 +0000 Subject: [PATCH 2/2] revert sha check --- images/opentelemetry/rootfs/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/opentelemetry/rootfs/build.sh b/images/opentelemetry/rootfs/build.sh index 1e6238f89c..1146e20ddf 100755 --- a/images/opentelemetry/rootfs/build.sh +++ b/images/opentelemetry/rootfs/build.sh @@ -116,7 +116,7 @@ get_src() echo "Downloading $url" curl -sSL "$url" -o "$f" - # echo "$hash $f" | sha256sum -c - || exit 10 + echo "$hash $f" | sha256sum -c - || exit 10 tar xzf "$f" rm -rf "$f" }