Skip to content

Commit

Permalink
Merge pull request #53 from DataDog/willgittoes-dd/upgrade-opentracin…
Browse files Browse the repository at this point in the history
…g-1-5-0

Upgrade to OpenTracing 1.5.0
  • Loading branch information
willgittoes-dd authored Sep 24, 2018
2 parents 3b035f5 + bfe8229 commit c458452
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 147 deletions.
29 changes: 24 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ version: 2
defaults: &defaults
working_directory: ~/dd-opentracing-cpp
docker:
- image: datadog/docker-library:dd_opentracing_cpp_build_0_3_0
- image: datadog/docker-library:dd_opentracing_cpp_build_0_3_2

jobs:
build:
<<: *defaults
environment:
CMAKE_ARGS: -DBUILD_PLUGIN=ON -DBUILD_SHARED=OFF
NGINX_OPENTRACING_VERSION: 0.6.0
NGINX_VERSION: 1.14.0
steps:
- checkout
- run:
Expand Down Expand Up @@ -38,6 +40,25 @@ jobs:
cmake $CMAKE_ARGS ..
make
cp libdd_opentracing_plugin.so /tmp/build/libdd_opentracing_plugin.so
- run:
name: Build opentracing-nginx
command: |
wget https://github.com/opentracing-contrib/nginx-opentracing/archive/v${NGINX_OPENTRACING_VERSION}.tar.gz -O nginx-opentracing.tar.gz
mkdir nginx-opentracing
tar zxvf nginx-opentracing.tar.gz -C nginx-opentracing --strip-components=1
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz -O nginx-${NGINX_VERSION}.tar.gz
tar zxvf nginx-${NGINX_VERSION}.tar.gz
# TODO(willgittoes-dd): Get these configure args automatically by installing nginx and using `nginx -V`.
cd nginx-${NGINX_VERSION}
./configure \
--prefix=/etc/nginx --modules-path=/usr/lib/nginx/modules \
--user=nginx --group=nginx --with-compat --with-file-aio --with-threads \
--with-cc-opt="-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-${NGINX_VERSION}/debian/debuild-base/nginx-${NGINX_VERSION}=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC" \
--with-ld-opt='-Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' \
--add-dynamic-module=../nginx-opentracing/opentracing
make
cp objs/ngx_http_opentracing_module.so /tmp/build/ngx_http_opentracing_module.so
- persist_to_workspace:
root: /tmp/
paths:
Expand Down Expand Up @@ -78,7 +99,6 @@ jobs:
docker:
- image: datadog/docker-library:dd_opentracing_cpp_test_0_3_0
environment:
NGINX_OPENTRACING_VERSION: 0.6.0
NGINX_VERSION: 1.14.0
steps:
- checkout
Expand All @@ -98,11 +118,10 @@ jobs:
name: Integration test
command: |
# Install the Datadog plugin
NGINX_MODULES=$(nginx -V 2>&1 | grep "configure arguments" | sed -n 's/.*--modules-path=\([^ ]*\).*/\1/p')
cp ./build/libdd_opentracing_plugin.so /usr/local/lib/libdd_opentracing_plugin.so
cp ./build/ngx_http_opentracing_module.so ${NGINX_MODULES}/ngx_http_opentracing_module.so
# Change the config to use it.
NGINX_MODULES=$(nginx -V 2>&1 | grep "configure arguments" | sed -n 's/.*--modules-path=\([^ ]*\).*/\1/p')
wget https://github.com/opentracing-contrib/nginx-opentracing/releases/download/v${NGINX_OPENTRACING_VERSION}/linux-amd64-nginx-${NGINX_VERSION}-ngx_http_module.so.tgz
tar zxf linux-amd64-nginx-${NGINX_VERSION}-ngx_http_module.so.tgz -C ${NGINX_MODULES}
cd ./test/integration/nginx/
NGINX_CONF=$(nginx -V 2>&1 | grep "configure arguments" | sed -n 's/.*--conf-path=\([^ ]*\).*/\1/p')
cp nginx.conf $NGINX_CONF
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@

# Bazel
bazel-*

# IDE settings
.vscode/
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ file(GLOB DD_OPENTRACING_SOURCES "src/*.cpp")
# Outputs
## Shared lib
if(BUILD_SHARED)
# Needed for curl if: curl is built statically, we compile a shared lib, and an nginx build
# is happening on the same machine. Using zlib1-dev from repos causes a linker fail.
find_package(ZLIB)
set(DATADOG_LINK_LIBRARIES ${OPENTRACING_LIB} ${ZLIB_LIBRARIES} ${CURL_LIBRARIES} Threads::Threads)

add_library(dd_opentracing SHARED ${DD_OPENTRACING_SOURCES})
add_sanitizers(dd_opentracing)
target_link_libraries(dd_opentracing ${DATADOG_LINK_LIBRARIES})
Expand Down
20 changes: 17 additions & 3 deletions scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/bin/bash
set -eo pipefail

OPENTRACING_VERSION=${OPENTRACING_VERSION:-1.4.0}
CURL_VERSION=${CURL_VERSION:-7.60.0}
MSGPACK_VERSION=${MSGPACK_VERSION:-3.0.1}
OPENTRACING_VERSION=${OPENTRACING_VERSION:-1.5.0}
CURL_VERSION=${CURL_VERSION:-7.61.1}
MSGPACK_VERSION=${MSGPACK_VERSION:-3.1.1}
ZLIB_VERSION=${ZLIB_VERSION:-1.2.11}

# Allow specifying dependencies not to install. By default we want to compile
# our own versions, but under some circumstances (eg building opentracing-nginx
# docker images) some of these dependencies are already provided.
BUILD_OPENTRACING=1
BUILD_CURL=1
BUILD_MSGPACK=1
BUILD_ZLIB=1

while test $# -gt 0
do
Expand All @@ -21,6 +23,8 @@ do
;;
not-curl) BUILD_CURL=0
;;
not-zlib) BUILD_ZLIB=0
;;
*) echo "unknown dependency: $1" && exit 1
;;
esac
Expand Down Expand Up @@ -56,6 +60,16 @@ if [ "$BUILD_MSGPACK" -eq "1" ]; then
cd ../..
fi

# Zlib
if [ "$BUILD_ZLIB" -eq "1" ]; then
wget https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz
tar zxf zlib-${ZLIB_VERSION}.tar.gz
cd zlib-${ZLIB_VERSION}
./configure --static
make && make install
cd ..
fi

# Libcurl
if [ "$BUILD_CURL" -eq "1" ]; then
wget https://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz
Expand Down
25 changes: 18 additions & 7 deletions src/dynamic_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@
#include <iostream>
#include "tracer.h"
#include "tracer_factory.h"
#include "version_check.h"

int OpenTracingMakeTracerFactory(const char* opentracing_version, const void** error_category,
void** tracer_factory) try {
if (!datadog::opentracing::equal_or_higher_version(std::string(opentracing_version),
std::string(OPENTRACING_VERSION))) {
std::cerr << "version mismatch: " << std::string(opentracing_version)
<< " != " << std::string(OPENTRACING_VERSION) << std::endl;
int OpenTracingMakeTracerFactoryFunction(const char* opentracing_version,
const char* opentracing_abi_version,
const void** error_category, void* error_message,
void** tracer_factory) try {
if (opentracing_version == nullptr || opentracing_abi_version == nullptr ||
error_message == nullptr || error_category == nullptr || tracer_factory == nullptr) {
std::cerr << "opentracing_version, opentracing_abi_version, error_message, `error_category, "
" and tracer_factory must be non-null."
<< std::endl;
std::terminate();
}

if (std::strcmp(opentracing_abi_version, OPENTRACING_ABI_VERSION) != 0) {
std::cerr << "version mismatch: " << std::string(opentracing_abi_version)
<< " != " << std::string(OPENTRACING_ABI_VERSION) << std::endl;
*error_category = static_cast<const void*>(&opentracing::dynamic_load_error_category());
return opentracing::incompatible_library_versions_error.value();
}

*tracer_factory = new datadog::opentracing::TracerFactory<datadog::opentracing::Tracer>{};
return 0;
} catch (const std::bad_alloc&) {
*error_category = static_cast<const void*>(&std::generic_category());
return static_cast<int>(std::errc::not_enough_memory);
}

OPENTRACING_DECLARE_IMPL_FACTORY(OpenTracingMakeTracerFactoryFunction)
81 changes: 0 additions & 81 deletions src/version_check.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions src/version_check.h

This file was deleted.

1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ macro(_datadog_test TEST_NAME)
endmacro()

_datadog_test(opentracing_test opentracing_test.cpp)
_datadog_test(version_check_test version_check_test.cpp)
_datadog_test(propagation_test propagation_test.cpp)
_datadog_test(span_buffer_test span_buffer_test.cpp)
_datadog_test(span_test span_test.cpp)
Expand Down
34 changes: 24 additions & 10 deletions test/integration/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
FROM ubuntu:18.04 as build

# Also set in the second stage.
ARG NGINX_VERSION=1.14.0
ARG NGINX_OPENTRACING_VERSION=0.6.0

# Creates an image with nginx and the Datadog OpenTracing nginx module installed.
# Runs a simple integration test.

RUN apt-get update && \
apt-get install -y git build-essential wget curl tar cmake
apt-get install -y git build-essential wget curl tar cmake libpcre3-dev zlib1g-dev

WORKDIR ~/

COPY ./scripts ./dd-opentracing-cpp/scripts
RUN export OPENTRACING_VERSION=1.4.0 && \
export MSGPACK_VERSION=3.0.1 && \
export CURL_VERSION=7.60.0 && \
cd dd-opentracing-cpp && \
RUN cd dd-opentracing-cpp && \
./scripts/install_dependencies.sh
COPY ./3rd_party ./dd-opentracing-cpp/3rd_party
COPY ./include ./dd-opentracing-cpp/include
Expand All @@ -25,11 +26,26 @@ RUN cmake -DBUILD_PLUGIN=ON -DBUILD_TESTING=OFF -DBUILD_SHARED=OFF ..
RUN make
RUN make install

# Build nginx-opentracing ourselves
RUN wget https://github.com/opentracing-contrib/nginx-opentracing/archive/v${NGINX_OPENTRACING_VERSION}.tar.gz -O nginx-opentracing.tar.gz && \
mkdir nginx-opentracing && \
tar zxvf nginx-opentracing.tar.gz -C nginx-opentracing --strip-components=1
RUN wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz -O nginx-${NGINX_VERSION}.tar.gz
RUN tar zxvf nginx-${NGINX_VERSION}.tar.gz
# TODO(willgittoes-dd): Get these configure args automatically by installing nginx and using `nginx -V`.
RUN cd nginx-${NGINX_VERSION} && \
./configure \
--prefix=/etc/nginx --modules-path=/usr/lib/nginx/modules \
--user=nginx --group=nginx --with-compat --with-file-aio --with-threads \
--with-cc-opt="-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-${NGINX_VERSION}/debian/debuild-base/nginx-${NGINX_VERSION}=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC" \
--with-ld-opt='-Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' \
--add-dynamic-module=../nginx-opentracing/opentracing && \
make && \
make install

FROM ubuntu:18.04

ARG NGINX_VERSION=1.14.0
ARG NGINX_OPENTRACING_VERSION=0.6.0

RUN apt-get update && \
apt-get install -y git gnupg lsb-release wget curl tar openjdk-8-jre golang jq
Expand All @@ -44,9 +60,7 @@ RUN CODENAME=$(lsb_release -s -c) && \
apt-get install nginx=${NGINX_VERSION}-1~${CODENAME}

# Install OpenTracing
ADD https://github.com/opentracing-contrib/nginx-opentracing/releases/download/v${NGINX_OPENTRACING_VERSION}/linux-amd64-nginx-${NGINX_VERSION}-ngx_http_module.so.tgz linux-amd64-nginx-${NGINX_VERSION}-ngx_http_module.so.tgz
RUN NGINX_MODULES=$(nginx -V 2>&1 | grep "configure arguments" | sed -n 's/.*--modules-path=\([^ ]*\).*/\1/p') && \
tar zxf linux-amd64-nginx-${NGINX_VERSION}-ngx_http_module.so.tgz -C ${NGINX_MODULES}
COPY --from=build /usr/lib/nginx/modules/ngx_http_opentracing_module.so /usr/lib/nginx/modules/ngx_http_opentracing_module.so
# And Datadog OT
COPY --from=build /usr/local/lib/libdd_opentracing_plugin.so /usr/local/lib/libdd_opentracing_plugin.so

Expand All @@ -59,7 +73,7 @@ RUN mkdir -p /var/www/
COPY ./test/integration/nginx/index.html /var/www/index.html

# Get Wiremock
ADD http://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-standalone/2.18.0/wiremock-standalone-2.18.0.jar wiremock-standalone-2.18.0.jar
RUN wget http://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-standalone/2.18.0/wiremock-standalone-2.18.0.jar -O wiremock-standalone-2.18.0.jar
RUN printf '#!/bin/bash\nset -x\njava -jar '"$(pwd)/wiremock-standalone-2.18.0.jar \"\$@\"\n" > /usr/local/bin/wiremock && \
chmod a+x /usr/local/bin/wiremock

Expand Down
26 changes: 0 additions & 26 deletions test/version_check_test.cpp

This file was deleted.

0 comments on commit c458452

Please sign in to comment.