Opentelemetry module build (#8585)

* nginx opentelemetry modules

* revert sha check
This commit is contained in:
Ehsan Saei 2022-05-14 15:41:17 +02:00 committed by GitHub
parent b0d198252f
commit 24925ccd2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 284 additions and 63 deletions

View file

@ -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)

View file

@ -13,16 +13,33 @@
# limitations under the License. # 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 \ RUN apk update \
&& apk upgrade \ && apk upgrade \
&& apk add -U bash \ && 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 # install OpenTelemetry-cpp
COPY --from=builder /etc/nginx/modules /etc/nginx/modules 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

View file

@ -18,15 +18,12 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail 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 # Check for recent changes: https://github.com/open-telemetry/opentelemetry-cpp/compare/v1.2.0...main
export OPENTELEMETRY_CPP_VERSION=1.2.0 export OPENTELEMETRY_CPP_VERSION=${OPENTELEMETRY_CPP_VERSION:="1.2.0"}
export INSTAL_DIR=/opt/third_party/install
# Check for recent changes: https://github.com/open-telemetry/opentelemetry-cpp-contrib/compare/2656a4...main # improve compilation times
export OPENTELEMETRY_CONTRIB_COMMIT=2656a4072e257b6794da86ddd1b773b49f5517b3 CORES=$(($(grep -c ^processor /proc/cpuinfo) - 1))
export BUILD_PATH=/tmp/build
rm -rf \ rm -rf \
/var/cache/debconf/* \ /var/cache/debconf/* \
@ -35,15 +32,80 @@ rm -rf \
/tmp/* \ /tmp/* \
/var/tmp/* /var/tmp/*
export BUILD_PATH=/tmp/build
mkdir -p /etc/nginx
mkdir --verbose -p "$BUILD_PATH" mkdir --verbose -p "$BUILD_PATH"
cd "$BUILD_PATH"
apk add \ Help()
curl \ {
git \ # Display Help
build-base 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() get_src()
{ {
@ -59,53 +121,100 @@ get_src()
rm -rf "$f" rm -rf "$f"
} }
install_nginx()
{
export NGINX_VERSION=1.19.10
get_src e8d0290ff561986ad7cd6c33307e12e11b137186c4403a6a5ccdb4914c082d88 \ # Check for recent changes: https://github.com/open-telemetry/opentelemetry-cpp-contrib/compare/2656a4...main
"https://nginx.org/download/nginx-$NGINX_VERSION.tar.gz" export OPENTELEMETRY_CONTRIB_COMMIT=6467ec2e4d67b08b44580b7eb7a298786f4eef91
get_src 360cdcbd1a235ec62119cc53956b2d31b6ff5f41d44415be53acc544709d58b8 \ mkdir -p /etc/nginx
"https://github.com/open-telemetry/opentelemetry-cpp-contrib/archive/$OPENTELEMETRY_CONTRIB_COMMIT.tar.gz" cd "$BUILD_PATH"
# improve compilation times get_src 360cdcbd1a235ec62119cc53956b2d31b6ff5f41d44415be53acc544709d58b8 \
CORES=$(($(grep -c ^processor /proc/cpuinfo) - 1)) "https://github.com/open-telemetry/opentelemetry-cpp-contrib/archive/$OPENTELEMETRY_CONTRIB_COMMIT.tar.gz"
export MAKEFLAGS=-j${CORES} 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
apk add \ mkdir -p /etc/nginx/modules
protobuf-dev \ cp ${INSTAL_DIR}/otel_ngx_module.so /etc/nginx/modules/otel_ngx_module.so
grpc \
grpc-dev \
gtest-dev \
c-ares-dev \
pcre-dev
cd $BUILD_PATH mkdir -p ${INSTAL_DIR}/lib
git clone --recursive https://github.com/open-telemetry/opentelemetry-cpp opentelemetry-cpp-$OPENTELEMETRY_CPP_VERSION cp /usr/lib/libopentelemetry_exporter_otlp_grpc.so* ${INSTAL_DIR}/lib
cd "opentelemetry-cpp-$OPENTELEMETRY_CPP_VERSION" cp /usr/lib/libopentelemetry_otlp_recordable.so* ${INSTAL_DIR}/lib
git checkout v$OPENTELEMETRY_CPP_VERSION cp /usr/lib/libprotobuf.so* ${INSTAL_DIR}/lib
mkdir .build cp /usr/lib/libopentelemetry_trace.so* ${INSTAL_DIR}/lib
cd .build 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
cmake -DCMAKE_BUILD_TYPE=Release \ cp /usr/lib/libgrpc.so* ${INSTAL_DIR}/lib
-DBUILD_TESTING=OFF \ cp /usr/lib/libgcc_s.so* ${INSTAL_DIR}/lib
-DWITH_EXAMPLES=OFF \ cp /usr/lib/libgrpc++.so* ${INSTAL_DIR}/lib
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \ cp /usr/lib/libabsl_bad_variant_access.so* ${INSTAL_DIR}/lib
-DWITH_OTLP=ON \ cp /usr/lib/libabsl_synchronization.so* ${INSTAL_DIR}/lib
-DWITH_OTLP_HTTP=OFF \ cp /usr/lib/libabsl_raw_hash_set.so* ${INSTAL_DIR}/lib
.. cp /usr/lib/libabsl_hash.so* ${INSTAL_DIR}/lib
make cp /usr/lib/libabsl_statusor.so* ${INSTAL_DIR}/lib
make install 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
}
# build nginx while getopts ":hpng:o:" option; do
cd "$BUILD_PATH/nginx-$NGINX_VERSION" case $option in
./configure \ h) # display Help
--prefix=/usr/local/nginx \ Help
--with-compat \ exit;;
--add-dynamic-module=$BUILD_PATH/opentelemetry-cpp-contrib-$OPENTELEMETRY_CONTRIB_COMMIT/instrumentation/nginx g) # install gRPC with git tag
GRPC_GIT_TAG=${OPTARG}
make modules install_grpc
mkdir -p /etc/nginx/modules exit;;
cp objs/otel_ngx_module.so /etc/nginx/modules/otel_ngx_module.so o) # install OpenTelemetry tag
OPENTELEMETRY_CPP_VERSION=${OPTARG}
# remove .a files install_otel
find /usr/local -name "*.a" -print | xargs /bin/rm exit;;
p) # prepare
prepare
exit;;
n) # install nginx
install_nginx
exit;;
\?)
Help
exit;;
esac
done