From d71c1216abe16c7981736d200a5c7f04ffde604a Mon Sep 17 00:00:00 2001 From: SteveWW Date: Fri, 25 Jun 2021 11:30:16 +0100 Subject: [PATCH] add Nginx tracing --- README.md | 8 ++++++++ docker-compose.yaml | 17 ++++++++++------- web/Dockerfile | 24 ++++++++++++++++++++++-- web/default.conf.template | 4 ++++ web/entrypoint.sh | 18 ++++++++++++++++++ 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e1116e8..571e2b7 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,14 @@ To see the application performance results in the Instana dashboard, you will fi ## Build from Source To optionally build from source (you will need a newish version of Docker to do this) use Docker Compose. Optionally edit the `.env` file to specify an alternative image registry and version tag; see the official [documentation](https://docs.docker.com/compose/env-file/) for more information. +To download the tracing module for Nginx, it needs a valid Instana agent key. Set this in the environment before starting the build. + +```shell +$ export INSTANA_AGENT_KEY="" +``` + +Now build all the images. + ```shell $ docker-compose build ``` diff --git a/docker-compose.yaml b/docker-compose.yaml index 3c57bfc..549895a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -33,7 +33,7 @@ services: - robot-shop healthcheck: test: [ "CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/health" ] - interval: 1s + interval: 10s timeout: 10s retries: 3 logging: @@ -49,7 +49,7 @@ services: - robot-shop healthcheck: test: [ "CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/health" ] - interval: 1s + interval: 10s timeout: 10s retries: 3 logging: @@ -64,7 +64,7 @@ services: - robot-shop healthcheck: test: [ "CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/health" ] - interval: 1s + interval: 10s timeout: 10s retries: 3 logging: @@ -89,7 +89,7 @@ services: - robot-shop healthcheck: test: ["CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/health"] - interval: 1s + interval: 10s timeout: 10s retries: 3 logging: @@ -106,7 +106,7 @@ services: - mysql healthcheck: test: ["CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost/_health"] - interval: 1s + interval: 10s timeout: 10s retries: 3 logging: @@ -121,7 +121,7 @@ services: - robot-shop healthcheck: test: ["CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/health"] - interval: 1s + interval: 10s timeout: 10s retries: 3 # Uncomment to change payment gateway @@ -142,6 +142,9 @@ services: web: build: context: web + args: + # agent key to download tracing libs + KEY: ${INSTANA_AGENT_KEY} image: ${REPO}/rs-web:${TAG} depends_on: - catalogue @@ -154,7 +157,7 @@ services: - robot-shop healthcheck: test: [ "CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/" ] - interval: 1s + interval: 10s timeout: 10s retries: 3 # Uncomment to enable Instana EUM diff --git a/web/Dockerfile b/web/Dockerfile index 181b46e..57c57ea 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,4 +1,20 @@ -FROM nginx:1.19 +FROM alpine AS build +ARG KEY + +WORKDIR /instana + +RUN apk add --update --no-cache curl + +RUN curl \ + --output instana.zip \ + --user "_:$KEY" \ + https://artifact-public.instana.io/artifactory/shared/com/instana/nginx_tracing/1.1.2/linux-amd64-glibc-nginx-1.20.1.zip && \ + unzip instana.zip && \ + mv glibc-libinstana_sensor.so libinstana_sensor.so && \ + mv glibc-nginx-1.20.1-ngx_http_ot_module.so ngx_http_opentracing_module.so + + +FROM nginx:1.20.1 EXPOSE 8080 @@ -7,7 +23,11 @@ ENV CATALOGUE_HOST=catalogue \ CART_HOST=cart \ SHIPPING_HOST=shipping \ PAYMENT_HOST=payment \ - RATINGS_HOST=ratings + RATINGS_HOST=ratings \ + INSTANA_SERVICE_NAME=nginx-web + +# Instana tracing +COPY --from=build /instana/*.so /tmp/ COPY entrypoint.sh /root/ ENTRYPOINT ["/root/entrypoint.sh"] diff --git a/web/default.conf.template b/web/default.conf.template index 7db8e96..ff70fe5 100644 --- a/web/default.conf.template +++ b/web/default.conf.template @@ -1,3 +1,7 @@ +# Instana tracing +opentracing_load_tracer /usr/local/lib/libinstana_sensor.so /etc/instana-config.json; +opentracing_propagate_context; + server { listen 8080; server_name localhost; diff --git a/web/entrypoint.sh b/web/entrypoint.sh index a6f2ab2..89304c7 100755 --- a/web/entrypoint.sh +++ b/web/entrypoint.sh @@ -29,5 +29,23 @@ chmod 644 $BASE_DIR/eum.html # apply environment variables to default.conf envsubst '${CATALOGUE_HOST} ${USER_HOST} ${CART_HOST} ${SHIPPING_HOST} ${PAYMENT_HOST} ${RATINGS_HOST}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf +# Patching for Instana tracing +mv /tmp/ngx_http_opentracing_module.so /usr/lib/nginx/modules +mv /tmp/libinstana_sensor.so /usr/local/lib +cat - /etc/nginx/nginx.conf << !EOF! > /tmp/nginx.conf +# Extra configuration for Instana tracing +load_module modules/ngx_http_opentracing_module.so; + +# Pass through these env vars +env INSTANA_SERVICE_NAME; +env INSTANA_AGENT_HOST; +env INSTANA_AGENT_PORT; +env INSTANA_MAX_BUFFERED_SPANS; +env INSTANA_DEV; +!EOF! + +mv /tmp/nginx.conf /etc/nginx/nginx.conf +echo "{}" > /etc/instana-config.json + exec nginx-debug -g "daemon off;"