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

ngx-otel module doesn't compile on Alpine 3.21 #86

Open
vndroid opened this issue Jan 20, 2025 · 2 comments
Open

ngx-otel module doesn't compile on Alpine 3.21 #86

vndroid opened this issue Jan 20, 2025 · 2 comments

Comments

@vndroid
Copy link

vndroid commented Jan 20, 2025

Describe the bug

It can't be compiled on Alpine 3.21.

To reproduce

Steps to reproduce the behavior:

  1. Base the official docker file Dockerfile,But base image change to Alpine 3.21.
  2. Error log
make[1]: Leaving directory '/tmp/tmp.KOJnkk/pkg-oss-f43e929dc7a6111ef5d9ecb281a75749f7934261/alpine/abuild-module-otel/src/abseil-cpp-20211102.0/build'
CMake Deprecation Warning at CMakeLists.txt:25 (cmake_minimum_required):
Compatibility with CMake < 3.10 will be removed from a future version of
CMake.

Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.


-- The C compiler identification is GNU 14.2.0
-- The CXX compiler identification is GNU 14.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found c-ares: /usr/lib/cmake/c-ares/c-ares-config.cmake (found suitable version "1.34.3", minimum required is "1.13.0")
-- Found ZLIB: /usr/lib/libz.so (found version "1.3.1")
-- Found RE2 via CMake.
-- Found OpenSSL: /usr/lib/libcrypto.so (found version "3.3.2")
-- Configuring done (2.0s)
CMake Error at /usr/lib/cmake/re2/re2Targets.cmake:70 (set_target_properties):
The link interface of target "re2::re2" contains:

  absl::absl_check

but the target was not found.  Possible reasons include:

  * There is a typo in the target name.
  * A find_package call is missing for an IMPORTED target.
  * An ALIAS target is missing.

Call Stack (most recent call first):
/usr/lib/cmake/re2/re2Config.cmake:60 (include)
cmake/modules/Findre2.cmake:15 (find_package)
cmake/re2.cmake:48 (find_package)
CMakeLists.txt:318 (include)


-- Generating done (1.0s)
CMake Warning:
Manually-specified variables were not used by the project:

  CMAKE_INSTALL_LIBDIR
  CMAKE_POLICY_DEFAULT_CMP0063


CMake Generate step failed.  Build files cannot be regenerated correctly.
>>> ERROR: nginx-module-otel: build failed
Command exited with non-zero status 1
real 1732.31
user 1377.06
sys 296.44
make: *** [Makefile:189: module-otel] Error 1

Expected behavior

Build Pass.

Your environment

/ # cmake --version
+ cmake --version
cmake version 3.31.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
/ # cat /etc/alpine-release 
+ cat /etc/alpine-release
3.21.2

Additional context

None

@ston1th
Copy link

ston1th commented Jan 21, 2025

@vndroid I managed to compile with the latest alpine version using the info from #16 (comment)

I made a few changes, here are the files:

Dockerfile:

FROM docker.io/library/alpine:3.21.2 as otel-module-builder
# Build nginx OpenTelemetry module
# https://github.com/nginxinc/nginx-otel
WORKDIR /opt

RUN apk add \
    cmake build-base openssl-dev zlib-dev pcre-dev \
    pkgconfig c-ares-dev re2-dev \
    grpc-dev protobuf-dev \
    git unzip

RUN wget https://github.com/nginx/nginx/archive/refs/tags/release-1.27.3.zip; unzip release-1.27.3.zip; mv nginx-release-1.27.3 nginx
WORKDIR /opt/nginx
RUN auto/configure --with-compat

WORKDIR /opt
RUN wget https://github.com/nginxinc/nginx-otel/archive/refs/heads/main.zip; unzip main.zip
# Modified CMake config to skip compiling grpc and protobuf, fix opentelemetry build, as well as disable cmake <3.24 workaround
COPY configs/nginx-otel-CMakeLists.txt /opt/nginx-otel-main/CMakeLists.txt
WORKDIR /opt/nginx-otel-main/build
RUN cmake -DNGX_OTEL_NGINX_BUILD_DIR=/opt/nginx/objs ..
RUN make -j 8

nginx-otel-CMakeLists.txt:

cmake_minimum_required(VERSION 3.24.0)
project(nginx-otel)

set(NGX_OTEL_NGINX_BUILD_DIR ""
    CACHE PATH "Nginx build (objs) dir")
set(NGX_OTEL_NGINX_DIR "${NGX_OTEL_NGINX_BUILD_DIR}/.."
    CACHE PATH "Nginx source dir")

set(NGX_OTEL_FETCH_DEPS ON CACHE BOOL "Download dependencies")
set(NGX_OTEL_PROTO_DIR  "" CACHE PATH "OTel proto files root")

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()

set(CMAKE_CXX_VISIBILITY_PRESET hidden)

include(FetchContent)

FetchContent_Declare(
    otelcpp
    GIT_REPOSITORY https://github.com/open-telemetry/opentelemetry-cpp
    GIT_TAG        955a807c0461544560429c2414b8967f6023e590 # v1.18.0
    GIT_SUBMODULES third_party/opentelemetry-proto
    GIT_SHALLOW    ON)

set(BUILD_TESTING OFF CACHE INTERNAL "")
set(WITH_EXAMPLES OFF CACHE INTERNAL "")
set(WITH_ABSEIL ON CACHE INTERNAL "")

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)

FetchContent_MakeAvailable(otelcpp)

set_property(DIRECTORY ${otelcpp_SOURCE_DIR}
             PROPERTY EXCLUDE_FROM_ALL YES)

if(NOT NGX_OTEL_PROTO_DIR)
    set(NGX_OTEL_PROTO_DIR
        "${otelcpp_SOURCE_DIR}/third_party/opentelemetry-proto")
endif()

add_library(opentelemetry-cpp::trace ALIAS opentelemetry_trace)

find_package(Protobuf REQUIRED)
find_package(gRPC REQUIRED)

set(PROTO_DIR ${NGX_OTEL_PROTO_DIR})
set(PROTOS
    "${PROTO_DIR}/opentelemetry/proto/common/v1/common.proto"
    "${PROTO_DIR}/opentelemetry/proto/resource/v1/resource.proto"
    "${PROTO_DIR}/opentelemetry/proto/trace/v1/trace.proto"
    "${PROTO_DIR}/opentelemetry/proto/collector/trace/v1/trace_service.proto")

set(PROTO_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(PROTO_SOURCES
    "${PROTO_OUT_DIR}/opentelemetry/proto/common/v1/common.pb.cc"
    "${PROTO_OUT_DIR}/opentelemetry/proto/resource/v1/resource.pb.cc"
    "${PROTO_OUT_DIR}/opentelemetry/proto/trace/v1/trace.pb.cc"
    "${PROTO_OUT_DIR}/opentelemetry/proto/collector/trace/v1/trace_service.pb.cc"
    "${PROTO_OUT_DIR}/opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.cc")

# generate protobuf code for lite runtime
add_custom_command(
    OUTPUT ${PROTO_SOURCES}
    COMMAND protobuf::protoc
        --proto_path ${PROTO_DIR}
        --cpp_out lite:${PROTO_OUT_DIR}
        --grpc_out ${PROTO_OUT_DIR}
        --plugin protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
        ${PROTOS}
    # remove inconsequential UTF8 check during serialization to aid performance
    COMMAND sed -i.bak -E
        -e [[/    ::(PROTOBUF_NAMESPACE_ID|google::protobuf)::internal::WireFormatLite::VerifyUtf8String\(/,/\);/d]]
        ${PROTO_SOURCES}
    DEPENDS ${PROTOS} protobuf::protoc gRPC::grpc_cpp_plugin
    VERBATIM)

add_library(ngx_otel_module MODULE
    src/http_module.cpp
    src/grpc_log.cpp
    src/modules.c
    ${PROTO_SOURCES})

# avoid 'lib' prefix in binary name
set_target_properties(ngx_otel_module PROPERTIES PREFIX "")

target_include_directories(ngx_otel_module PRIVATE
    ${NGX_OTEL_NGINX_BUILD_DIR}
    ${NGX_OTEL_NGINX_DIR}/src/core
    ${NGX_OTEL_NGINX_DIR}/src/event
    ${NGX_OTEL_NGINX_DIR}/src/event/modules
    ${NGX_OTEL_NGINX_DIR}/src/event/quic
    ${NGX_OTEL_NGINX_DIR}/src/os/unix
    ${NGX_OTEL_NGINX_DIR}/src/http
    ${NGX_OTEL_NGINX_DIR}/src/http/modules
    ${NGX_OTEL_NGINX_DIR}/src/http/v2
    ${NGX_OTEL_NGINX_DIR}/src/http/v3
    ${PROTO_OUT_DIR})

target_link_libraries(ngx_otel_module
    absl::log_initialize
    opentelemetry-cpp::trace
    gRPC::grpc++)

The inclusion of absl::log_initialize in the target_link_libraries is needed. Otherwise the linker won't find the lib:

Error relocating ngx_otel_module.so: _ZN4absl12lts_2024072213InitializeLogEv: symbol not found

You will need to add the grpc-cpp and abseil-cpp-log-initialize dependencies to your final container: apk add --no-cache grpc-cpp abseil-cpp-log-initialize

@thresheek
Copy link

This particular issue is fixed for nginx-otel on Alpine 3.21 via nginx/pkg-oss@b9dbbfb - the fix will be available when nginx 1.27.4 is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants