Skip to content

Commit c84d5d2

Browse files
authored
feat: add ipv6 toggling logic
1 parent 012f632 commit c84d5d2

File tree

7 files changed

+58
-7
lines changed

7 files changed

+58
-7
lines changed

.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ IMAGE_VERSION=2.0.2
55
IMAGE_NAME=ghcr.io/open-telemetry/demo
66
DEMO_VERSION=latest
77

8+
IPV6_ENABLED=true
9+
810
# Build Args
911
TRACETEST_IMAGE_VERSION=v1.7.1
1012
OTEL_JAVA_AGENT_VERSION=2.20.0
@@ -83,9 +85,10 @@ FRONTEND_DOCKERFILE=./src/frontend/Dockerfile
8385

8486
# Frontend Proxy (Envoy)
8587
FRONTEND_HOST=frontend
86-
ENVOY_PORT=8080
8788
FRONTEND_PROXY_ADDR=frontend-proxy:${ENVOY_PORT}
8889
FRONTEND_PROXY_DOCKERFILE=./src/frontend-proxy/Dockerfile
90+
ENVOY_ADDR=0.0.0.0
91+
ENVOY_PORT=8080
8992

9093
# Image Provider
9194
IMAGE_PROVIDER_HOST=image-provider

docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ services:
192192
- VERSION=${IMAGE_VERSION}
193193
- OTEL_EXPORTER_OTLP_ENDPOINT
194194
- OTEL_RESOURCE_ATTRIBUTES=${OTEL_RESOURCE_ATTRIBUTES},service.name=currency # The C++ SDK does not support OTEL_SERVICE_NAME
195+
- IPV6_ENABLED
195196
depends_on:
196197
otel-collector:
197198
condition: service_started
@@ -352,6 +353,7 @@ services:
352353
- OTEL_RESOURCE_ATTRIBUTES
353354
- OTEL_SERVICE_NAME=frontend-proxy
354355
- ENVOY_PORT
356+
- ENVOY_ADDR
355357
- FLAGD_HOST
356358
- FLAGD_PORT
357359
- FLAGD_UI_HOST
@@ -458,6 +460,7 @@ services:
458460
- OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE
459461
- OTEL_RESOURCE_ATTRIBUTES
460462
- OTEL_SERVICE_NAME=payment
463+
- IPV6_ENABLED
461464
depends_on:
462465
otel-collector:
463466
condition: service_started
@@ -523,6 +526,7 @@ services:
523526
- OTEL_RESOURCE_ATTRIBUTES
524527
- OTEL_SERVICE_NAME=quote
525528
- OTEL_PHP_INTERNAL_METRICS_ENABLED=true
529+
- IPV6_ENABLED
526530
depends_on:
527531
otel-collector:
528532
condition: service_started
@@ -587,6 +591,7 @@ services:
587591
- OTEL_RESOURCE_ATTRIBUTES
588592
- OTEL_SERVICE_NAME=shipping
589593
- OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE
594+
- IPV6_ENABLED
590595
healthcheck:
591596
test: ["CMD-SHELL", "timeout 1 bash -c '>/dev/tcp/localhost/${SHIPPING_PORT}'"]
592597
start_period: 10s

src/currency/src/server.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,17 @@ class CurrencyService final : public oteldemo::CurrencyService::Service
238238

239239
void RunServer(uint16_t port)
240240
{
241-
std::string address("0.0.0.0:" + std::to_string(port));
241+
std::string ip("0.0.0.0");
242+
243+
const char* ipv6_enabled = std::getenv("IPV6_ENABLED");
244+
245+
if (ipv6_enabled == "true") {
246+
ip = "[::]";
247+
logger->Info("Overwriting Localhost IP: " + ip);
248+
}
249+
250+
std::string address(ip + ":" + std::to_string(port));
251+
242252
CurrencyService currencyService;
243253
HealthServer healthService;
244254
ServerBuilder builder;

src/frontend-proxy/envoy.tmpl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ static_resources:
66
listeners:
77
- address:
88
socket_address:
9-
address: 0.0.0.0
9+
address: "${ENVOY_ADDR}"
1010
port_value: ${ENVOY_PORT}
1111
filter_chains:
1212
- filters:

src/payment/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,24 @@ server.addService(health.service, new health.Implementation({
4444

4545
server.addService(otelDemoPackage.oteldemo.PaymentService.service, { charge: chargeServiceHandler })
4646

47-
server.bindAsync(`0.0.0.0:${process.env['PAYMENT_PORT']}`, grpc.ServerCredentials.createInsecure(), (err, port) => {
47+
48+
let ip = "0.0.0.0";
49+
50+
const ipv6_enabled = process.env.IPV6_ENABLED;
51+
52+
if (ipv6_enabled == "true") {
53+
ip = "[::]";
54+
logger.info(`Overwriting Localhost IP: ${ip}`)
55+
}
56+
57+
const address = ip + `:${process.env['PAYMENT_PORT']}`;
58+
59+
server.bindAsync(address, grpc.ServerCredentials.createInsecure(), (err, port) => {
4860
if (err) {
4961
return logger.error({ err })
5062
}
5163

52-
logger.info(`payment gRPC server started on port ${port}`)
64+
logger.info(`payment gRPC server started on ${address}`)
5365
})
5466

5567
process.once('SIGINT', closeGracefully)

src/quote/public/index.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,18 @@
8787

8888
return $response;
8989
});
90-
$address = '0.0.0.0:' . getenv('QUOTE_PORT');
90+
91+
$ip = "0.0.0.0";
92+
93+
$ipv6_enabled = getenv('IPV6_ENABLED');
94+
95+
if ($ipv6_enabled == "true") {
96+
$ip = "[::]";
97+
echo "Overwriting Localhost IP: {$ip}" . PHP_EOL;
98+
}
99+
100+
$address = $ip . ':' . getenv('QUOTE_PORT');
101+
91102
$socket = new SocketServer($address);
92103
$server->listen($socket);
93104

src/shipping/src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ async fn main() -> std::io::Result<()> {
2626
.expect("$SHIPPING_PORT is not set")
2727
.parse()
2828
.expect("$SHIPPING_PORT is not a valid port");
29-
let addr = format!("0.0.0.0:{}", port);
29+
30+
let mut ip = "0.0.0.0".to_string();
31+
32+
if let Ok(ipv6_enabled) = env::var("IPV6_ENABLED") {
33+
if ipv6_enabled == "true" {
34+
ip = "[::]".to_string();
35+
info!("Overwriting Localhost IP: {ip}");
36+
}
37+
}
38+
39+
let addr = format!("{}:{}", ip, port);
3040
info!(
3141
name = "ServerStartedSuccessfully",
3242
addr = addr.as_str(),

0 commit comments

Comments
 (0)