Skip to content

Commit 7a499f8

Browse files
[frontend] [ops golf?] Pass collector URL to frontend via reverse proxy. (#508)
* support setting collector URL for browser * rename to frontend-proxy * refactor to use envoy rather than nginx * cleanup * fix composefile * delete unneeded nginx conf template * cleanup naming * set cors to * * also front ffs with envoy * update docs, changelog, etc * update one more port mapping in docs * update for envoy url * update for envoy url * Revert "update for envoy url" This reverts commit 63c7bcf. * fixup Co-authored-by: Pierre Tessier <[email protected]>
1 parent 694481f commit 7a499f8

File tree

16 files changed

+189
-15
lines changed

16 files changed

+189
-15
lines changed

.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=cumulative
1515
FRONTEND_PORT=8080
1616
FRONTEND_ADDR=frontend:${FRONTEND_PORT}
1717

18+
# Envoy
19+
FRONTEND_HOST=frontend
20+
ENVOY_PORT=80
21+
1822
# Redis
1923
REDIS_PORT=6379
2024
REDIS_ADDR=redis-cart:${REDIS_PORT}
@@ -52,6 +56,7 @@ SHIPPING_SERVICE_ADDR=shippingservice:${SHIPPING_SERVICE_PORT}
5256

5357
FEATURE_FLAG_SERVICE_PORT=8081
5458
FEATURE_FLAG_SERVICE_ADDR=featureflagservice:${FEATURE_FLAG_SERVICE_PORT}
59+
FEATURE_FLAG_SERVICE_HOST=feature-flag-service
5560
FEATURE_FLAG_GRPC_SERVICE_PORT=50053
5661
FEATURE_FLAG_GRPC_SERVICE_ADDR=featureflagservice:${FEATURE_FLAG_GRPC_SERVICE_PORT}
5762

.github/.mlc_config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"ignorePatterns": [
3+
{"pattern": "^http://localhost"},
34
{"pattern": "^http://localhost:3000"},
4-
{"pattern": "^http://localhost:8080"},
5-
{"pattern": "^http://localhost:8081"},
65
{"pattern": "^http://localhost:8089"},
76
{"pattern": "^http://localhost:9090"},
87
{"pattern": "^http://localhost:16686"},

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,5 @@ significant modifications will be credited to OpenTelemetry Authors.
124124
([#455](https://github.com/open-telemetry/opentelemetry-demo/pull/455))
125125
* Update cartservice Dockerfile to support ARM64
126126
([#439](https://github.com/open-telemetry/opentelemetry-demo/pull/439))
127+
* Add Envoy as reverse proxy for all user-facing services
128+
([#508](https://github.com/open-telemetry/opentelemetry-demo/pull/508))

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ docker compose up -d
9191

9292
Once the images are built and containers are started you can access:
9393

94-
- Webstore: <http://localhost:8080/>
94+
- Webstore: <http://localhost/>
9595
- Jaeger: <http://localhost:16686/>
9696
- Prometheus: <http://localhost:9090/>
9797
- Grafana: <http://localhost:3000/>
98-
- Feature Flags UI: <http://localhost:8081/>
98+
- Feature Flags UI: <http://localhost/feature/>
9999
- Load Generator UI: <http://localhost:8089/>
100100

101101
## Create Your First Pull Request

docker-compose.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ services:
181181
memory: 200M
182182
restart: always
183183
ports:
184-
- "${FRONTEND_PORT}:${FRONTEND_PORT}"
184+
- "${FRONTEND_PORT}"
185185
environment:
186186
- PORT=${FRONTEND_PORT}
187187
- FRONTEND_ADDR
@@ -210,7 +210,28 @@ services:
210210
- shippingservice
211211
logging: *logging
212212

213-
# Load generator
213+
frontendproxy:
214+
image: ${IMAGE_NAME}:${IMAGE_VERSION}-frontend-envoy
215+
build:
216+
context: ./
217+
dockerfile: ./src/frontendProxy/Dockerfile
218+
container_name: frontend-proxy
219+
volumes:
220+
- ./src/frontendproxy/envoy.yaml.tmpl:/etc/envoy/envoy.yaml.tmpl
221+
ports:
222+
- "${ENVOY_PORT}:${ENVOY_PORT}"
223+
environment:
224+
- PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
225+
- FRONTEND_PORT
226+
- FRONTEND_HOST
227+
- FEATURE_FLAG_SERVICE_PORT
228+
- FEATURE_FLAG_SERVICE_HOST
229+
- ENVOY_PORT
230+
- ENVOY_UID=0
231+
depends_on:
232+
- frontend
233+
command: /bin/sh -c "envsubst < /etc/envoy/envoy.yaml.tmpl > /etc/envoy/envoy.yaml && envoy -c /etc/envoy/envoy.yaml;"
234+
214235
loadgenerator:
215236
image: ${IMAGE_NAME}:${IMAGE_VERSION}-loadgenerator
216237
container_name: load-generator
@@ -389,7 +410,7 @@ services:
389410
memory: 160M
390411
restart: always
391412
ports:
392-
- "${FEATURE_FLAG_SERVICE_PORT}:${FEATURE_FLAG_SERVICE_PORT}" # Feature Flag Service UI
413+
- "${FEATURE_FLAG_SERVICE_PORT}" # Feature Flag Service UI
393414
- "${FEATURE_FLAG_GRPC_SERVICE_PORT}" # Feature Flag Service gRPC API
394415
environment:
395416
- FEATURE_FLAG_SERVICE_PORT
@@ -398,6 +419,7 @@ services:
398419
- OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc
399420
- OTEL_SERVICE_NAME=featureflagservice
400421
- DATABASE_URL=ecto://ffs:ffs@ffs_postgres:5432/ffs
422+
- FEATURE_FLAG_SERVICE_PATH_ROOT="/feature"
401423
depends_on:
402424
ffs_postgres:
403425
condition: service_healthy

docs/current_architecture.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ checkoutservice(Checkout Service):::golang
1515
currencyservice(Currency Service):::cpp
1616
emailservice(Email Service):::ruby
1717
frontend(Frontend):::javascript
18+
frontendproxy(Frontend Proxy <br/>&#40Envoy&#41):::cpp
1819
loadgenerator([Load Generator]):::python
1920
paymentservice(Payment Service):::javascript
2021
productcatalogservice(Product Catalog Service):::golang
@@ -24,7 +25,9 @@ shippingservice(Shipping Service):::rust
2425
featureflagservice(Feature Flag Service):::erlang
2526
featureflagstore[(Feature Flag Store<br/>&#40PostgreSQL DB&#41)]
2627
27-
Internet -->|HTTP| frontend
28+
Internet -->|HTTP| frontendproxy
29+
frontendproxy -->|HTTP| frontend
30+
frontendproxy -->|HTTP| featureflagservice
2831
loadgenerator -->|HTTP| frontend
2932
3033
checkoutservice --->|gRPC| cartservice --> cache

docs/docker_deployment.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ source. It may take more than 20 minutes to build if the flag is omitted.
3939

4040
Once the images are built and containers are started you can access:
4141

42-
- Webstore: <http://localhost:8080/>
42+
- Webstore: <http://localhost/>
4343
- Jaeger: <http://localhost:16686/>
4444
- Prometheus: <http://localhost:9090/>
4545
- Grafana: <http://localhost:3000/>
46-
- Feature Flags UI: <http://localhost:8081/>
46+
- Feature Flags UI: <http://localhost/feature/>
4747
- Load Generator UI: <http://localhost:8089/>
4848

4949
## Bring your own backend

src/featureflagservice/config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config :featureflagservice,
1212

1313
# Configures the endpoint
1414
config :featureflagservice, FeatureflagserviceWeb.Endpoint,
15-
url: [host: "localhost"],
15+
url: [host: "localhost", path: "/feature"],
1616
render_errors: [view: FeatureflagserviceWeb.ErrorView, accepts: ~w(html json), layout: false],
1717
pubsub_server: Featureflagservice.PubSub,
1818
live_view: [signing_salt: "T88WPl/Q"]

src/frontend/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ from the root folder.
2424
It will start all of the required backend services
2525
and within the container simply run `npm run dev`.
2626
After that the app should be available at <http://localhost:8080/>.
27+
28+
## Collector Config
29+
30+
The app looks for a cookie named 'otelCollectorUrl' and gets its value on page
31+
load. This cookie key + value needs to be set by a reverse proxy.

src/frontend/package-lock.json

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)