Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opentelemetry module build #8585

Merged
merged 2 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions images/opentelemetry/rootfs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 23 additions & 6 deletions images/opentelemetry/rootfs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
237 changes: 173 additions & 64 deletions images/opentelemetry/rootfs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/* \
Expand All @@ -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()
{
Expand All @@ -59,53 +121,100 @@ get_src()
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