diff --git a/Makefile b/Makefile index ac58634ae..d24d61089 100644 --- a/Makefile +++ b/Makefile @@ -165,9 +165,6 @@ gateway-logs: export IMAGE_NAME = does-not-matter gateway-logs: $(DOCKER) compose logs gateway -opentelemetry-gateway: ## run gateway instrumented with opentelemetry - $(DOCKER) compose run opentelemetry-instrumented-gateway - opentracing-gateway: ## run gateway instrumented with opentracing $(DOCKER) compose run opentracing-instrumented-gateway diff --git a/dev-environments/opentelemetry-instrumented-gateway/Makefile b/dev-environments/opentelemetry-instrumented-gateway/Makefile new file mode 100644 index 000000000..7e0707631 --- /dev/null +++ b/dev-environments/opentelemetry-instrumented-gateway/Makefile @@ -0,0 +1,13 @@ +SHELL = /usr/bin/env bash -o pipefail +.SHELLFLAGS = -ec +.DEFAULT_GOAL := gateway +MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +WORKDIR := $(patsubst %/,%,$(dir $(MKFILE_PATH))) +DOCKER ?= $(shell which docker 2> /dev/null || echo "docker") + +gateway: ## run gateway configured to access plain HTTP 1.1 upstream + $(DOCKER) compose -f docker-compose.yml run --service-ports gateway + +clean: + $(DOCKER) compose down --volumes --remove-orphans + $(DOCKER) compose -f docker-compose.yml down --volumes --remove-orphans diff --git a/dev-environments/opentelemetry-instrumented-gateway/README.md b/dev-environments/opentelemetry-instrumented-gateway/README.md new file mode 100644 index 000000000..abf168825 --- /dev/null +++ b/dev-environments/opentelemetry-instrumented-gateway/README.md @@ -0,0 +1,51 @@ +# Gateway instrumented with opentelemetry + +APIcast (opentelemetry) --> upstream plain HTTP 1.1 upstream + +APIcast configured with plain HTTP 1.1 upstream server equipped with traffic rely agent (socat) + +## Run the gateway + +Running local `apicast-test` docker image + +```sh +make gateway +``` + +Running custom apicast image + +```sh +make gateway IMAGE_NAME=quay.io/3scale/apicast:latest +``` + +Traffic between the proxy and upstream can be inspected looking at logs from `example.com` service + +``` +docker compose -p opentelemetry-instrumented-gateway logs -f example.com +``` + +Open in local browser jaeger dashboard + +``` +http://127.0.0.1:16686/search +``` + +## Testing + +`GET` request + +```sh +curl --resolve get.example.com:8080:127.0.0.1 -v "http://get.example.com:8080/?user_key=123" +``` + +`POST` request + +```sh +curl --resolve post.example.com:8080:127.0.0.1 -v -X POST "http://post.example.com:8080/?user_key=123" +``` + +## Clean env + +```sh +make clean +``` diff --git a/dev-environments/opentelemetry-instrumented-gateway/apicast-config.json b/dev-environments/opentelemetry-instrumented-gateway/apicast-config.json new file mode 100644 index 000000000..30c2db396 --- /dev/null +++ b/dev-environments/opentelemetry-instrumented-gateway/apicast-config.json @@ -0,0 +1,58 @@ +{ + "services": [ + { + "id": "1", + "backend_version": "1", + "proxy": { + "hosts": ["get.example.com"], + "api_backend": "http://example.com/get", + "backend": { + "endpoint": "http://127.0.0.1:8081", + "host": "backend" + }, + "policy_chain": [ + { + "name": "apicast.policy.apicast" + } + ], + "proxy_rules": [ + { + "http_method": "GET", + "pattern": "/", + "metric_system_name": "hits", + "delta": 1, + "parameters": [], + "querystring_parameters": {} + } + ] + } + }, + { + "id": "2", + "backend_version": "1", + "proxy": { + "hosts": ["post.example.com"], + "api_backend": "http://example.com/post", + "backend": { + "endpoint": "http://127.0.0.1:8081", + "host": "backend" + }, + "policy_chain": [ + { + "name": "apicast.policy.apicast" + } + ], + "proxy_rules": [ + { + "http_method": "POST", + "pattern": "/", + "metric_system_name": "hits", + "delta": 1, + "parameters": [], + "querystring_parameters": {} + } + ] + } + } + ] +} diff --git a/dev-environments/opentelemetry-instrumented-gateway/docker-compose.yml b/dev-environments/opentelemetry-instrumented-gateway/docker-compose.yml new file mode 100644 index 000000000..f9e3b760c --- /dev/null +++ b/dev-environments/opentelemetry-instrumented-gateway/docker-compose.yml @@ -0,0 +1,47 @@ +--- +version: '3.8' +services: + gateway: + image: ${IMAGE_NAME:-apicast-test} + depends_on: + - jaeger + - example.com + - two.upstream + environment: + THREESCALE_CONFIG_FILE: /tmp/config.json + THREESCALE_DEPLOYMENT_ENV: staging + APICAST_CONFIGURATION_LOADER: lazy + APICAST_WORKERS: 1 + APICAST_LOG_LEVEL: debug + APICAST_CONFIGURATION_CACHE: "0" + OPENTELEMETRY: "1" + OPENTELEMETRY_CONFIG: /opt/app-root/src/tracing-configs/otel.toml + expose: + - "8080" + - "8090" + ports: + - "8080:8080" + - "8090:8090" + volumes: + - ./apicast-config.json:/tmp/config.json + - ./otel.toml:/opt/app-root/src/tracing-configs/otel.toml + example.com: + image: alpine/socat:1.7.4.4 + container_name: example.com + command: "-d -v -d TCP-LISTEN:80,reuseaddr,fork TCP:two.upstream:80" + expose: + - "80" + restart: unless-stopped + two.upstream: + image: kennethreitz/httpbin + expose: + - "80" + jaeger: + image: jaegertracing/all-in-one:latest + environment: + JAEGER_DISABLED: "false" + COLLECTOR_OTLP_ENABLED: "true" + ports: + - 16686:16686 + expose: + - "4317" diff --git a/examples/opentelemetry/otel.toml b/dev-environments/opentelemetry-instrumented-gateway/otel.toml similarity index 100% rename from examples/opentelemetry/otel.toml rename to dev-environments/opentelemetry-instrumented-gateway/otel.toml diff --git a/docker-compose.forward-proxy.yml b/docker-compose.forward-proxy.yml deleted file mode 100644 index 6b214dc8c..000000000 --- a/docker-compose.forward-proxy.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- -version: '3.8' -services: - gateway: - image: ${IMAGE_NAME:-apicast-test} - depends_on: - - proxy - - upstream - environment: - THREESCALE_CONFIG_FILE: /tmp/config.json - THREESCALE_DEPLOYMENT_ENV: staging - APICAST_CONFIGURATION_LOADER: lazy - APICAST_WORKERS: 1 - APICAST_LOG_LEVEL: debug - APICAST_CONFIGURATION_CACHE: "0" - expose: - - "8080" - - "8090" - ports: - - "8080:8080" - - "8090:8090" - volumes: - - ./examples/forward-proxy/apicast-config.json:/tmp/config.json - upstream: - image: nginx:1.23.4 - expose: - - "443" - volumes: - - ./examples/forward-proxy/proxy-nginx.conf:/etc/nginx/nginx.conf - - ./examples/forward-proxy/upstream-cert/upstream.key:/etc/pki/tls.key - - ./examples/forward-proxy/upstream-cert/upstream.crt:/etc/pki/tls.crt - proxy: - build: - dockerfile: ./examples/forward-proxy/tinyproxy.Dockerfile - expose: - - "3128:3128" - - "443:443" - volumes: - - ./examples/forward-proxy/tinyproxy.conf:/etc/tinyproxy/tinyproxy.conf diff --git a/docker-compose.yml b/docker-compose.yml index ef00eb3be..300f8c93f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -69,21 +69,6 @@ services: volumes: - ./examples/opentracing/apicast-config.json:/tmp/config.json - ./examples/opentracing/jaeger-config.json:/opt/app-root/src/tracing-configs/tracing-config-jaeger-jaeger-config.json - opentelemetry-instrumented-gateway: - image: ${IMAGE_NAME:-apicast-test} - depends_on: - - jaeger - environment: - THREESCALE_CONFIG_FILE: /tmp/config.json - THREESCALE_DEPLOYMENT_ENV: staging - APICAST_CONFIGURATION_LOADER: lazy - APICAST_LOG_LEVEL: debug - APICAST_CONFIGURATION_CACHE: "0" - OPENTELEMETRY: "1" - OPENTELEMETRY_CONFIG: /opt/app-root/src/tracing-configs/otel.toml - volumes: - - ./examples/opentelemetry/apicast-config.json:/tmp/config.json - - ./examples/opentelemetry/otel.toml:/opt/app-root/src/tracing-configs/otel.toml jaeger: image: jaegertracing/all-in-one:latest environment: diff --git a/examples/opentelemetry/apicast-config.json b/examples/opentelemetry/apicast-config.json deleted file mode 100644 index a99361b8c..000000000 --- a/examples/opentelemetry/apicast-config.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "services": [ - { - "backend_version": "1", - "proxy": { - "hosts": ["one"], - "api_backend": "http://httpbin.org", - "backend": { - "endpoint": "http://127.0.0.1:8081", - "host": "backend" - }, - "proxy_rules": [ - { - "http_method": "GET", - "pattern": "/", - "metric_system_name": "hits", - "delta": 1, - "parameters": [], - "querystring_parameters": {} - } - ] - } - } - ] -}