From 39eb56348ca0e0f12c1cb9311e58f26ef1a07992 Mon Sep 17 00:00:00 2001 From: DEBAJIT DAS <85024550+DebajitDas@users.noreply.github.com> Date: Tue, 11 Oct 2022 12:01:58 +0530 Subject: [PATCH] Upgrade nginx instrumentation to support stable{1.22.0} and mainline{1.23.1} version. (#205) * Added some changes * Added support for multiple versions * Added dynamic build for nginx version * Removed unwanted changes * More update * Updated Dockerfile for centos7 and ubuntue --- .../otel-webserver-module/README.md | 7 +- .../otel-webserver-module/build.gradle | 133 ++++++++++-------- .../otel-webserver-module/docker-compose.yml | 2 +- .../docker/centos7/Dockerfile | 6 +- .../docker/ubuntu20.04/Dockerfile | 18 ++- .../src/nginx/ngx_http_opentelemetry_log.h | 2 +- .../src/nginx/ngx_http_opentelemetry_module.c | 5 +- .../otel-webserver-module/src/nginx/script.sh | 5 + .../otel-webserver-module/version.properties | 1 + 9 files changed, 109 insertions(+), 70 deletions(-) create mode 100755 instrumentation/otel-webserver-module/src/nginx/script.sh diff --git a/instrumentation/otel-webserver-module/README.md b/instrumentation/otel-webserver-module/README.md index ae31fa368..cf300c844 100644 --- a/instrumentation/otel-webserver-module/README.md +++ b/instrumentation/otel-webserver-module/README.md @@ -149,7 +149,7 @@ Currently, Nginx Webserver module monitores some fixed set of modules, which get | Library | Present Version | | ---------------------------------------------- | ----------- | -| Nginx | 1.18.0 | +| Nginx | 1.22.0, 1.23.0,1.23.1 | | Apr | 1.7.0 | | Apr-util | 1.6.1 | @@ -179,7 +179,8 @@ Currently, Nginx Webserver module monitores some fixed set of modules, which get - Docker Desktop should be installed on the system #### Platform Supported -- Supports only Nginx v1.18.0. +- Supports both stable(1.22.0) and mainline(1.23.1). +- Earlier support of v1.18.0 is deprecated. - The build is supported for **x86-64** platforms. - OS support: **Centos6**, **Centos7, ubuntu20.04**. @@ -235,7 +236,7 @@ Make sure to edit the directives values according to your need e.g NginxModuleOt Edit the nginx.conf to provide the reference to opentelemetry_module.conf and shared library. Please mind the order and location of the below entries by referring to ```conf/nginx/nginx.conf```. ``` -load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/ngx_http_opentelemetry_module.so; +load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx//ngx_http_opentelemetry_module.so; include /opt/opentelemetry_module.conf; ``` diff --git a/instrumentation/otel-webserver-module/build.gradle b/instrumentation/otel-webserver-module/build.gradle index ddbcf7c17..c07d8500d 100644 --- a/instrumentation/otel-webserver-module/build.gradle +++ b/instrumentation/otel-webserver-module/build.gradle @@ -1,5 +1,10 @@ +plugins { + id "de.undercouch.download" version "3.4.3" +} + apply plugin: 'cpp' apply from: 'common.gradle' +apply plugin: 'de.undercouch.download' def coverageEnabled = System.getenv('enableCoverage') def target_system = System.getProperty('targetSystem') ?: 'centos6' @@ -46,7 +51,7 @@ project.ext { apache22Version = "2.2.31" apache24Version = "2.4.23" - nginxVersion = '1.18.0' + nginxSupportedVersions=props.get("nginxSupportedVersions").split(',') libraryStageDir = "${platBuildDir}/opentelemetry-webserver-sdk" apacheStageDir = "${libraryStageDir}/WebServerModule/Apache" @@ -360,83 +365,98 @@ task assembleApacheModule(type: Tar) { } // NGINX -task extractNginx(type: Copy) { - from "build-dependencies" - into buildDir -} - -task configureNginx(type: Exec){ - group = 'OpenTelemetry module for Nginx' - description = 'Run configure to generate the build files for OpenTelemetry Module for Nginx' - - dependsOn extractNginx +nginxSupportedVersions.each { nginxVersion -> + task("downloadNginx${nginxVersion}", type: Download) { + src "http://nginx.org/download/nginx-${nginxVersion}.tar.gz" + dest buildDir + overwrite false + } - workingDir "${buildDir}/nginx-${nginxVersion}" - commandLine './configure', "--with-compat", "--with-cc-opt=-Wno-error -Wno-unused-variable -Wno-unused-but-set-variable", "--with-ld-opt=-L${libraryStageDir}/sdk_lib/lib", "--add-dynamic-module=${projectDir}/src/nginx" -} + task("extractNginx${nginxVersion}", type: Copy) { + dependsOn "downloadNginx${nginxVersion}" + from tarTree(resources.gzip("build/nginx-${nginxVersion}.tar.gz")) + into buildDir + } -task delMakefile(type: Exec){ - group = 'OpenTelemetry module for Nginx' - description = 'Deleting old Makefile' + task("configureNginx${nginxVersion}", type: Exec) { + group = 'OpenTelemetry module for Nginx' + description = 'Run configure to generate the build files for OpenTelemetry Module for Nginx' - workingDir "${buildDir}/nginx-${nginxVersion}/objs" - commandLine 'rm', '-rf', 'Makefile' -} + dependsOn "extractNginx${nginxVersion}" + workingDir "${buildDir}/nginx-${nginxVersion}" + commandLine './configure', "--with-compat", "--with-cc-opt=-Wno-error -Wno-unused-variable -Wno-unused-but-set-variable", "--with-ld-opt=-L${libraryStageDir}/sdk_lib/lib", "--add-dynamic-module=${projectDir}/src/nginx" + } -task copyMakefile(type: Copy){ - group = 'OpenTelemetry module for Nginx' - description = 'Copying Makefile for compiling Nginx Web Server Agent' + task("delMakefile${nginxVersion}", type: Exec) { + group = 'OpenTelemetry module for Nginx' + description = 'Deleting old Makefile' - dependsOn delMakefile + workingDir "${buildDir}/nginx-${nginxVersion}/objs" + commandLine 'rm', '-rf', 'Makefile' + } - from "src/nginx/Makefile" - into "${buildDir}/nginx-${nginxVersion}/objs/" -} + task("copyMakefile${nginxVersion}", type: Copy) { + group = 'OpenTelemetry module for Nginx' + description = 'Copying Makefile for compiling Nginx Web Server Agent' -task buildNginxModule(type: Exec) { - group = 'OpenTelemetry module for Nginx' - description = 'Build the Nginx Web Server Agent' + dependsOn "delMakefile${nginxVersion}" + from "src/nginx/Makefile" + into "${buildDir}/nginx-${nginxVersion}/objs/" + } - dependsOn configureNginx - dependsOn stageLibrary - dependsOn copyMakefile + task("updateMakefile${nginxVersion}", type: Exec) { + group = 'OpenTelemetry module for Nginx' + description = 'Updating the Makefile for dynamic build' - outputs.file "${buildDir}/nginx-${nginxVersion}/objs/ngx_http_opentelemetry_module.so" + commandLine 'bash', '-c', "src/nginx/script.sh ${buildDir}/nginx-${nginxVersion}/objs/Makefile" + } - workingDir "${buildDir}/nginx-${nginxVersion}" - commandLine 'make', 'modules' -} + task("buildNginxModule${nginxVersion}",type: Exec) { + group = 'OpenTelemetry module for Nginx' + description = 'Build the Nginx Web Server Agent' -task stageNginxModule(type: Copy) { - group = 'OpenTelemetry module for Nginx' - description = 'Stage the Nginx Web Server Agent distribution directory' + dependsOn "configureNginx${nginxVersion}" + dependsOn stageLibrary + dependsOn "updateMakefile${nginxVersion}" -// dependsOn stageLibrary + outputs.file "${buildDir}/nginx-${nginxVersion}/objs/ngx_http_opentelemetry_module.so" + workingDir "${buildDir}/nginx-${nginxVersion}" + commandLine 'make', 'modules' + } - from buildNginxModule - into nginxStageDir -} + task("stageNginxModule${nginxVersion}", type: Copy) { + group = 'OpenTelemetry module for Nginx' + description = 'Stage the Nginx Web Server Agent distribution directory' -task stripNginxModule(type: Exec){ - group = 'OpenTelemetry module for Nginx' - description = 'Strip the production Nginx Web Server Agent' + dependsOn "buildNginxModule${nginxVersion}" + def nginxStageDirVersion = "${nginxStageDir}/${nginxVersion}" + from "${buildDir}/nginx-${nginxVersion}/objs/ngx_http_opentelemetry_module.so" + into nginxStageDirVersion + } - dependsOn stageNginxModule + task("stripNginxModule${nginxVersion}", type: Exec) { + group = 'OpenTelemetry module for Nginx' + description = 'Strip the production Nginx Web Server Agent' - onlyIf { !debug } + dependsOn "stageNginxModule${nginxVersion}" + onlyIf { !debug } - inputs.dir stageNginxModule - outputs.file "${nginxStageDir}/ngx_http_opentelemetry_module.${sharedLibraryExt}" + inputs.dir "stageNginxModule${nginxVersion}" + outputs.file "${nginxStageDir}/${nginxVersion}/ngx_http_opentelemetry_module.${sharedLibraryExt}" - workingDir nginxStageDir - commandLine 'strip', '-x', "ngx_http_opentelemetry_module.${sharedLibraryExt}" + workingDir "${nginxStageDir}/${nginxVersion}" + commandLine 'strip', '-x', "ngx_http_opentelemetry_module.${sharedLibraryExt}" + } } task assembleNginxModule(type: Tar) { group = 'Nginx Web Server Module' description = 'Assemble the Nginx Web Server module artifact (tgz)' - dependsOn stripNginxModule + nginxSupportedVersions.each { + nginxVersion -> + dependsOn "stripNginxModule${nginxVersion}" + } from libraryStageDir baseName "opentelemetry-webserver-sdk-${osArch}-${osName}" @@ -451,7 +471,10 @@ task assembleWebServerModule(type: Tar) { description = 'Assemble the Web Server agent artifact (tgz)' dependsOn stripApacheModule - dependsOn stripNginxModule + nginxSupportedVersions.each { + nginxVersion -> + dependsOn "stripNginxModule${nginxVersion}" + } from libraryStageDir baseName "opentelemetry-webserver-sdk-${osArch}-${osName}" diff --git a/instrumentation/otel-webserver-module/docker-compose.yml b/instrumentation/otel-webserver-module/docker-compose.yml index 5ca22ce2b..8b2e431bf 100644 --- a/instrumentation/otel-webserver-module/docker-compose.yml +++ b/instrumentation/otel-webserver-module/docker-compose.yml @@ -98,7 +98,7 @@ services: - centos_nginx - centos7_nginx - ubuntu20.04_nginx - command: ["--config=/etc/otel-config.yml", "--log-level=DEBUG", "${OTELCOL_ARGS}"] + command: ["--config=/etc/otel-config.yml", "${OTELCOL_ARGS}"] volumes: - ./otel-config.yml:/etc/otel-config.yml ports: diff --git a/instrumentation/otel-webserver-module/docker/centos7/Dockerfile b/instrumentation/otel-webserver-module/docker/centos7/Dockerfile index 1c5f14b3e..afd224ec5 100644 --- a/instrumentation/otel-webserver-module/docker/centos7/Dockerfile +++ b/instrumentation/otel-webserver-module/docker/centos7/Dockerfile @@ -26,7 +26,7 @@ ARG AUTOMAKE_VERSION="1.16.3" ARG PERL_VERSION="5.20.2" ARG PERL_CPANVERSION="5.0" ARG PCRE_VERSION="8.44" -ARG NGINX_VERSION="1.18.0" +ARG NGINX_VERSION="1.22.0" # create default non-root user RUN groupadd -r swuser && useradd -u 1000 -g swuser -m -s /sbin/nologin -c "default non-root user" swuser @@ -276,7 +276,7 @@ RUN echo '[nginx]' >> /etc/yum.repos.d/nginx.repo \ && echo 'baseurl=https://nginx.org/packages/centos/7/x86_64' >> /etc/yum.repos.d/nginx.repo \ && echo 'gpgcheck=0' >> /etc/yum.repos.d/nginx.repo \ && echo 'enabled=1' >> /etc/yum.repos.d/nginx.repo \ - && yum install nginx-1.18.0 -y + && yum install nginx-${NGINX_VERSION} -y RUN cd /otel-webserver-module/build \ && tar -xf opentelemetry-webserver-sdk-x64-linux.tgz \ @@ -290,7 +290,7 @@ RUN cd /otel-webserver-module/build \ && cd / RUN cp /otel-webserver-module/conf/nginx/opentelemetry_module.conf /opt/ \ - && sed -i '8i load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/ngx_http_opentelemetry_module.so;' /etc/nginx/nginx.conf \ + && sed -i '8i load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/1.22.0/ngx_http_opentelemetry_module.so;' /etc/nginx/nginx.conf \ && sed -i '33i include /opt/opentelemetry_module.conf;' /etc/nginx/nginx.conf \ && cd / diff --git a/instrumentation/otel-webserver-module/docker/ubuntu20.04/Dockerfile b/instrumentation/otel-webserver-module/docker/ubuntu20.04/Dockerfile index ab84bfc8f..f694cd65d 100644 --- a/instrumentation/otel-webserver-module/docker/ubuntu20.04/Dockerfile +++ b/instrumentation/otel-webserver-module/docker/ubuntu20.04/Dockerfile @@ -38,7 +38,7 @@ ARG APRUTIL_VERSION="1.6.1" ARG LOG4CXX_VERSION="0.11.0" ARG GTEST_VERSION="1.10.0" ARG PCRE_VERSION="8.44" -ARG NGINX_VERSION="1.18.0" +ARG NGINX_VERSION="1.22.0" # Install GRPC RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v${GRPC_VERSION} \ @@ -180,7 +180,17 @@ RUN wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \ && tar -xvf nginx-${NGINX_VERSION}.tar.gz -C /build-dependencies \ && rm -rf nginx-${NGINX_VERSION}.tar.gz -RUN apt-get install nginx -y +# Install Nginx stable version +RUN apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring -y \ + && curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \ + | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null \ + && gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg; exit 0 +RUN echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ + http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \ + | tee /etc/apt/sources.list.d/nginx.list \ + && echo "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \ + | tee /etc/apt/preferences.d/99nginx \ + && apt update -y && apt install nginx -y # Build Webserver Module COPY . /otel-webserver-module @@ -203,8 +213,8 @@ RUN cd /otel-webserver-module/build \ RUN cd /otel-webserver-module/build \ && cp ../conf/nginx/opentelemetry_module.conf /opt/ \ - && sed -i '5i load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/ngx_http_opentelemetry_module.so;' /etc/nginx/nginx.conf \ - && sed -i '64i include /opt/opentelemetry_module.conf;' /etc/nginx/nginx.conf \ + && sed -i '5i load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/1.22.0/ngx_http_opentelemetry_module.so;' /etc/nginx/nginx.conf \ + && sed -i '33i include /opt/opentelemetry_module.conf;' /etc/nginx/nginx.conf \ && cd /opt/opentelemetry-webserver-sdk \ && ./install.sh \ && cd / diff --git a/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_log.h b/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_log.h index 1f2f6aa92..9df692435 100644 --- a/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_log.h +++ b/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_log.h @@ -15,9 +15,9 @@ */ -#include #include #include +#include #include /* diff --git a/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.c b/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.c index 45d684ca7..63ede7543 100644 --- a/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.c +++ b/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.c @@ -14,13 +14,12 @@ * limitations under the License. */ +#include "ngx_http_opentelemetry_module.h" +#include "ngx_http_opentelemetry_log.h" #include #include #include -#include "ngx_http_opentelemetry_module.h" -#include "ngx_http_opentelemetry_log.h" - ngx_http_opentelemetry_worker_conf_t *worker_conf; static contextNode contexts[5]; static unsigned int c_count = 0; diff --git a/instrumentation/otel-webserver-module/src/nginx/script.sh b/instrumentation/otel-webserver-module/src/nginx/script.sh new file mode 100755 index 000000000..e6c3ef125 --- /dev/null +++ b/instrumentation/otel-webserver-module/src/nginx/script.sh @@ -0,0 +1,5 @@ +#!/bin/bash +fileName=$1 + +sed -i "s/-L\/otel-webserver-module\/build\/linux-x64\/opentelemetry-webserver-sdk\/sdk_lib\/lib\ -lopentelemetry_webserver_sdk\ -ldl\ -lpthread\ -lcrypt\ -lpcre\ -lz\ \\\/-L\/otel-webserver-module\/build\/linux-x64\/opentelemetry-webserver-sdk\/sdk_lib\/lib\ -lopentelemetry_webserver_sdk\ -ldl\ -lrt\ -lpthread\ -lcrypt\ -lpcre\ -lz\ \\\/g" $fileName +sed -i "s/-L\/otel-webserver-module\/build\/linux-x64\/opentelemetry-webserver-sdk\/sdk_lib\/lib\ \\\/-L\/otel-webserver-module\/build\/linux-x64\/opentelemetry-webserver-sdk\/sdk_lib\/lib\ -lopentelemetry_webserver_sdk\ \\\/g" $fileName diff --git a/instrumentation/otel-webserver-module/version.properties b/instrumentation/otel-webserver-module/version.properties index 04a5e2d09..cc32e12eb 100644 --- a/instrumentation/otel-webserver-module/version.properties +++ b/instrumentation/otel-webserver-module/version.properties @@ -1,2 +1,3 @@ server-module-version=1.0.0 release=GA +nginxSupportedVersions=1.22.0,1.23.0,1.23.1