Skip to content

Commit 39eb563

Browse files
authored
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
1 parent c817ffc commit 39eb563

File tree

9 files changed

+109
-70
lines changed

9 files changed

+109
-70
lines changed

instrumentation/otel-webserver-module/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Currently, Nginx Webserver module monitores some fixed set of modules, which get
149149

150150
| Library | Present Version |
151151
| ---------------------------------------------- | ----------- |
152-
| Nginx | 1.18.0 |
152+
| Nginx | 1.22.0, 1.23.0,1.23.1 |
153153
| Apr | 1.7.0 |
154154
| Apr-util | 1.6.1 |
155155

@@ -179,7 +179,8 @@ Currently, Nginx Webserver module monitores some fixed set of modules, which get
179179
- Docker Desktop should be installed on the system
180180

181181
#### Platform Supported
182-
- Supports only Nginx v1.18.0.
182+
- Supports both stable(1.22.0) and mainline(1.23.1).
183+
- Earlier support of v1.18.0 is deprecated.
183184
- The build is supported for **x86-64** platforms.
184185
- OS support: **Centos6**, **Centos7, ubuntu20.04**.
185186

@@ -235,7 +236,7 @@ Make sure to edit the directives values according to your need e.g NginxModuleOt
235236
Edit the nginx.conf to provide the reference to opentelemetry_module.conf and shared library.
236237
Please mind the order and location of the below entries by referring to ```conf/nginx/nginx.conf```.
237238
```
238-
load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/ngx_http_opentelemetry_module.so;
239+
load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/<nginx-version>/ngx_http_opentelemetry_module.so;
239240
include /opt/opentelemetry_module.conf;
240241
```
241242

instrumentation/otel-webserver-module/build.gradle

Lines changed: 78 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
plugins {
2+
id "de.undercouch.download" version "3.4.3"
3+
}
4+
15
apply plugin: 'cpp'
26
apply from: 'common.gradle'
7+
apply plugin: 'de.undercouch.download'
38

49
def coverageEnabled = System.getenv('enableCoverage')
510
def target_system = System.getProperty('targetSystem') ?: 'centos6'
@@ -46,7 +51,7 @@ project.ext {
4651

4752
apache22Version = "2.2.31"
4853
apache24Version = "2.4.23"
49-
nginxVersion = '1.18.0'
54+
nginxSupportedVersions=props.get("nginxSupportedVersions").split(',')
5055

5156
libraryStageDir = "${platBuildDir}/opentelemetry-webserver-sdk"
5257
apacheStageDir = "${libraryStageDir}/WebServerModule/Apache"
@@ -360,83 +365,98 @@ task assembleApacheModule(type: Tar) {
360365
}
361366

362367
// NGINX
363-
task extractNginx(type: Copy) {
364-
from "build-dependencies"
365-
into buildDir
366-
}
367-
368-
task configureNginx(type: Exec){
369-
group = 'OpenTelemetry module for Nginx'
370-
description = 'Run configure to generate the build files for OpenTelemetry Module for Nginx'
371-
372-
dependsOn extractNginx
368+
nginxSupportedVersions.each { nginxVersion ->
369+
task("downloadNginx${nginxVersion}", type: Download) {
370+
src "http://nginx.org/download/nginx-${nginxVersion}.tar.gz"
371+
dest buildDir
372+
overwrite false
373+
}
373374

374-
workingDir "${buildDir}/nginx-${nginxVersion}"
375-
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"
376-
}
375+
task("extractNginx${nginxVersion}", type: Copy) {
376+
dependsOn "downloadNginx${nginxVersion}"
377+
from tarTree(resources.gzip("build/nginx-${nginxVersion}.tar.gz"))
378+
into buildDir
379+
}
377380

378-
task delMakefile(type: Exec){
379-
group = 'OpenTelemetry module for Nginx'
380-
description = 'Deleting old Makefile'
381+
task("configureNginx${nginxVersion}", type: Exec) {
382+
group = 'OpenTelemetry module for Nginx'
383+
description = 'Run configure to generate the build files for OpenTelemetry Module for Nginx'
381384

382-
workingDir "${buildDir}/nginx-${nginxVersion}/objs"
383-
commandLine 'rm', '-rf', 'Makefile'
384-
}
385+
dependsOn "extractNginx${nginxVersion}"
386+
workingDir "${buildDir}/nginx-${nginxVersion}"
387+
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"
388+
}
385389

386-
task copyMakefile(type: Copy){
387-
group = 'OpenTelemetry module for Nginx'
388-
description = 'Copying Makefile for compiling Nginx Web Server Agent'
390+
task("delMakefile${nginxVersion}", type: Exec) {
391+
group = 'OpenTelemetry module for Nginx'
392+
description = 'Deleting old Makefile'
389393

390-
dependsOn delMakefile
394+
workingDir "${buildDir}/nginx-${nginxVersion}/objs"
395+
commandLine 'rm', '-rf', 'Makefile'
396+
}
391397

392-
from "src/nginx/Makefile"
393-
into "${buildDir}/nginx-${nginxVersion}/objs/"
394-
}
398+
task("copyMakefile${nginxVersion}", type: Copy) {
399+
group = 'OpenTelemetry module for Nginx'
400+
description = 'Copying Makefile for compiling Nginx Web Server Agent'
395401

396-
task buildNginxModule(type: Exec) {
397-
group = 'OpenTelemetry module for Nginx'
398-
description = 'Build the Nginx Web Server Agent'
402+
dependsOn "delMakefile${nginxVersion}"
403+
from "src/nginx/Makefile"
404+
into "${buildDir}/nginx-${nginxVersion}/objs/"
405+
}
399406

400-
dependsOn configureNginx
401-
dependsOn stageLibrary
402-
dependsOn copyMakefile
407+
task("updateMakefile${nginxVersion}", type: Exec) {
408+
group = 'OpenTelemetry module for Nginx'
409+
description = 'Updating the Makefile for dynamic build'
403410

404-
outputs.file "${buildDir}/nginx-${nginxVersion}/objs/ngx_http_opentelemetry_module.so"
411+
commandLine 'bash', '-c', "src/nginx/script.sh ${buildDir}/nginx-${nginxVersion}/objs/Makefile"
412+
}
405413

406-
workingDir "${buildDir}/nginx-${nginxVersion}"
407-
commandLine 'make', 'modules'
408-
}
414+
task("buildNginxModule${nginxVersion}",type: Exec) {
415+
group = 'OpenTelemetry module for Nginx'
416+
description = 'Build the Nginx Web Server Agent'
409417

410-
task stageNginxModule(type: Copy) {
411-
group = 'OpenTelemetry module for Nginx'
412-
description = 'Stage the Nginx Web Server Agent distribution directory'
418+
dependsOn "configureNginx${nginxVersion}"
419+
dependsOn stageLibrary
420+
dependsOn "updateMakefile${nginxVersion}"
413421

414-
// dependsOn stageLibrary
422+
outputs.file "${buildDir}/nginx-${nginxVersion}/objs/ngx_http_opentelemetry_module.so"
423+
workingDir "${buildDir}/nginx-${nginxVersion}"
424+
commandLine 'make', 'modules'
425+
}
415426

416-
from buildNginxModule
417-
into nginxStageDir
418-
}
427+
task("stageNginxModule${nginxVersion}", type: Copy) {
428+
group = 'OpenTelemetry module for Nginx'
429+
description = 'Stage the Nginx Web Server Agent distribution directory'
419430

420-
task stripNginxModule(type: Exec){
421-
group = 'OpenTelemetry module for Nginx'
422-
description = 'Strip the production Nginx Web Server Agent'
431+
dependsOn "buildNginxModule${nginxVersion}"
432+
def nginxStageDirVersion = "${nginxStageDir}/${nginxVersion}"
433+
from "${buildDir}/nginx-${nginxVersion}/objs/ngx_http_opentelemetry_module.so"
434+
into nginxStageDirVersion
435+
}
423436

424-
dependsOn stageNginxModule
437+
task("stripNginxModule${nginxVersion}", type: Exec) {
438+
group = 'OpenTelemetry module for Nginx'
439+
description = 'Strip the production Nginx Web Server Agent'
425440

426-
onlyIf { !debug }
441+
dependsOn "stageNginxModule${nginxVersion}"
442+
onlyIf { !debug }
427443

428-
inputs.dir stageNginxModule
429-
outputs.file "${nginxStageDir}/ngx_http_opentelemetry_module.${sharedLibraryExt}"
444+
inputs.dir "stageNginxModule${nginxVersion}"
445+
outputs.file "${nginxStageDir}/${nginxVersion}/ngx_http_opentelemetry_module.${sharedLibraryExt}"
430446

431-
workingDir nginxStageDir
432-
commandLine 'strip', '-x', "ngx_http_opentelemetry_module.${sharedLibraryExt}"
447+
workingDir "${nginxStageDir}/${nginxVersion}"
448+
commandLine 'strip', '-x', "ngx_http_opentelemetry_module.${sharedLibraryExt}"
449+
}
433450
}
434451

435452
task assembleNginxModule(type: Tar) {
436453
group = 'Nginx Web Server Module'
437454
description = 'Assemble the Nginx Web Server module artifact (tgz)'
438455

439-
dependsOn stripNginxModule
456+
nginxSupportedVersions.each {
457+
nginxVersion ->
458+
dependsOn "stripNginxModule${nginxVersion}"
459+
}
440460

441461
from libraryStageDir
442462
baseName "opentelemetry-webserver-sdk-${osArch}-${osName}"
@@ -451,7 +471,10 @@ task assembleWebServerModule(type: Tar) {
451471
description = 'Assemble the Web Server agent artifact (tgz)'
452472

453473
dependsOn stripApacheModule
454-
dependsOn stripNginxModule
474+
nginxSupportedVersions.each {
475+
nginxVersion ->
476+
dependsOn "stripNginxModule${nginxVersion}"
477+
}
455478

456479
from libraryStageDir
457480
baseName "opentelemetry-webserver-sdk-${osArch}-${osName}"

instrumentation/otel-webserver-module/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ services:
9898
- centos_nginx
9999
- centos7_nginx
100100
- ubuntu20.04_nginx
101-
command: ["--config=/etc/otel-config.yml", "--log-level=DEBUG", "${OTELCOL_ARGS}"]
101+
command: ["--config=/etc/otel-config.yml", "${OTELCOL_ARGS}"]
102102
volumes:
103103
- ./otel-config.yml:/etc/otel-config.yml
104104
ports:

instrumentation/otel-webserver-module/docker/centos7/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ARG AUTOMAKE_VERSION="1.16.3"
2626
ARG PERL_VERSION="5.20.2"
2727
ARG PERL_CPANVERSION="5.0"
2828
ARG PCRE_VERSION="8.44"
29-
ARG NGINX_VERSION="1.18.0"
29+
ARG NGINX_VERSION="1.22.0"
3030

3131
# create default non-root user
3232
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 \
276276
&& echo 'baseurl=https://nginx.org/packages/centos/7/x86_64' >> /etc/yum.repos.d/nginx.repo \
277277
&& echo 'gpgcheck=0' >> /etc/yum.repos.d/nginx.repo \
278278
&& echo 'enabled=1' >> /etc/yum.repos.d/nginx.repo \
279-
&& yum install nginx-1.18.0 -y
279+
&& yum install nginx-${NGINX_VERSION} -y
280280

281281
RUN cd /otel-webserver-module/build \
282282
&& tar -xf opentelemetry-webserver-sdk-x64-linux.tgz \
@@ -290,7 +290,7 @@ RUN cd /otel-webserver-module/build \
290290
&& cd /
291291

292292
RUN cp /otel-webserver-module/conf/nginx/opentelemetry_module.conf /opt/ \
293-
&& sed -i '8i load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/ngx_http_opentelemetry_module.so;' /etc/nginx/nginx.conf \
293+
&& sed -i '8i load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/1.22.0/ngx_http_opentelemetry_module.so;' /etc/nginx/nginx.conf \
294294
&& sed -i '33i include /opt/opentelemetry_module.conf;' /etc/nginx/nginx.conf \
295295
&& cd /
296296

instrumentation/otel-webserver-module/docker/ubuntu20.04/Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ARG APRUTIL_VERSION="1.6.1"
3838
ARG LOG4CXX_VERSION="0.11.0"
3939
ARG GTEST_VERSION="1.10.0"
4040
ARG PCRE_VERSION="8.44"
41-
ARG NGINX_VERSION="1.18.0"
41+
ARG NGINX_VERSION="1.22.0"
4242

4343
# Install GRPC
4444
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 \
180180
&& tar -xvf nginx-${NGINX_VERSION}.tar.gz -C /build-dependencies \
181181
&& rm -rf nginx-${NGINX_VERSION}.tar.gz
182182

183-
RUN apt-get install nginx -y
183+
# Install Nginx stable version
184+
RUN apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring -y \
185+
&& curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
186+
| tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null \
187+
&& gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg; exit 0
188+
RUN echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
189+
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
190+
| tee /etc/apt/sources.list.d/nginx.list \
191+
&& echo "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
192+
| tee /etc/apt/preferences.d/99nginx \
193+
&& apt update -y && apt install nginx -y
184194

185195
# Build Webserver Module
186196
COPY . /otel-webserver-module
@@ -203,8 +213,8 @@ RUN cd /otel-webserver-module/build \
203213

204214
RUN cd /otel-webserver-module/build \
205215
&& cp ../conf/nginx/opentelemetry_module.conf /opt/ \
206-
&& sed -i '5i load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/ngx_http_opentelemetry_module.so;' /etc/nginx/nginx.conf \
207-
&& sed -i '64i include /opt/opentelemetry_module.conf;' /etc/nginx/nginx.conf \
216+
&& sed -i '5i load_module /opt/opentelemetry-webserver-sdk/WebServerModule/Nginx/1.22.0/ngx_http_opentelemetry_module.so;' /etc/nginx/nginx.conf \
217+
&& sed -i '33i include /opt/opentelemetry_module.conf;' /etc/nginx/nginx.conf \
208218
&& cd /opt/opentelemetry-webserver-sdk \
209219
&& ./install.sh \
210220
&& cd /

instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717

18-
#include <stdbool.h>
1918
#include <ngx_config.h>
2019
#include <ngx_core.h>
20+
#include <stdbool.h>
2121
#include <stdarg.h>
2222

2323
/*

instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17+
#include "ngx_http_opentelemetry_module.h"
18+
#include "ngx_http_opentelemetry_log.h"
1719
#include <sys/types.h>
1820
#include <unistd.h>
1921
#include <string.h>
2022

21-
#include "ngx_http_opentelemetry_module.h"
22-
#include "ngx_http_opentelemetry_log.h"
23-
2423
ngx_http_opentelemetry_worker_conf_t *worker_conf;
2524
static contextNode contexts[5];
2625
static unsigned int c_count = 0;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
fileName=$1
3+
4+
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
5+
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
server-module-version=1.0.0
22
release=GA
3+
nginxSupportedVersions=1.22.0,1.23.0,1.23.1

0 commit comments

Comments
 (0)