Skip to content

Commit

Permalink
dev-environment: opentelemetry-instrumented-gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Oct 21, 2023
1 parent 9877507 commit 064c47d
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 82 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions dev-environments/opentelemetry-instrumented-gateway/Makefile
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions dev-environments/opentelemetry-instrumented-gateway/README.md
Original file line number Diff line number Diff line change
@@ -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
```
Original file line number Diff line number Diff line change
@@ -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": {}
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.
39 changes: 0 additions & 39 deletions docker-compose.forward-proxy.yml

This file was deleted.

15 changes: 0 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 0 additions & 25 deletions examples/opentelemetry/apicast-config.json

This file was deleted.

0 comments on commit 064c47d

Please sign in to comment.