Skip to content

Commit

Permalink
Upgrade nginx instrumentation to support stable{1.22.0} and mainline{…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
DebajitDas authored Oct 11, 2022
1 parent c817ffc commit 39eb563
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 70 deletions.
7 changes: 4 additions & 3 deletions instrumentation/otel-webserver-module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down Expand Up @@ -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**.

Expand Down Expand Up @@ -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/<nginx-version>/ngx_http_opentelemetry_module.so;
include /opt/opentelemetry_module.conf;
```

Expand Down
133 changes: 78 additions & 55 deletions instrumentation/otel-webserver-module/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}"
Expand All @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/otel-webserver-module/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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 /

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down Expand Up @@ -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
Expand All @@ -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 /
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/


#include <stdbool.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <stdbool.h>
#include <stdarg.h>

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* limitations under the License.
*/

#include "ngx_http_opentelemetry_module.h"
#include "ngx_http_opentelemetry_log.h"
#include <sys/types.h>
#include <unistd.h>
#include <string.h>

#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;
Expand Down
5 changes: 5 additions & 0 deletions instrumentation/otel-webserver-module/src/nginx/script.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions instrumentation/otel-webserver-module/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
server-module-version=1.0.0
release=GA
nginxSupportedVersions=1.22.0,1.23.0,1.23.1

0 comments on commit 39eb563

Please sign in to comment.