Skip to content

Commit be36ddc

Browse files
authored
Rename environment variables to clarify service enablement (#238)
1 parent 5642d92 commit be36ddc

11 files changed

+53
-51
lines changed

CLAUDE.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ QuickPizza is a demonstration web application that generates pizza recommendatio
3939
### Microservices Architecture
4040
The application is designed as a modular monolith that can be deployed as separate microservices. Services are controlled by environment variables:
4141

42-
- **Frontend** (`QUICKPIZZA_FRONTEND`) - Serves SvelteKit UI
43-
- **Catalog** (`QUICKPIZZA_CATALOG`) - Manages ingredients, tools, doughs, users, ratings
44-
- **Copy** (`QUICKPIZZA_COPY`) - Handles quotes, names, adjectives for pizza generation
45-
- **Recommendations** (`QUICKPIZZA_RECOMMENDATIONS`) - Core pizza recommendation logic
46-
- **WebSocket** (`QUICKPIZZA_WS`) - Real-time communication
42+
- **PublicAPI** (`QUICKPIZZA_ENABLE_PUBLIC_API_SERVICE`) - Serves Frontend and Gateway
43+
- **Frontend** - Serves SvelteKit UI
4744
- **Gateway** - Routes requests between services in microservice deployments
48-
- **gRPC** (`QUICKPIZZA_GRPC`) - gRPC service on ports 3334/3335
49-
- **Config** (`QUICKPIZZA_CONFIG`) - Configuration endpoint
50-
- **HTTP Testing** (`QUICKPIZZA_HTTP_TESTING`) - HTTP testing utilities
51-
- **Test K6 IO** (`QUICKPIZZA_TEST_K6_IO`) - Legacy test.k6.io replacement endpoints
45+
- **Catalog** (`QUICKPIZZA_ENABLE_CATALOG_SERVICE`) - Manages ingredients, tools, doughs, users, ratings
46+
- **Copy** (`QUICKPIZZA_ENABLE_COPY_SERVICE`) - Handles quotes, names, adjectives for pizza generation
47+
- **Recommendations** (`QUICKPIZZA_ENABLE_RECOMMENDATIONS_SERVICE`) - Core pizza recommendation logic
48+
- **WebSocket** (`QUICKPIZZA_ENABLE_WS_SERVICE`) - Real-time communication
49+
- **gRPC** (`QUICKPIZZA_ENABLE_GRPC_SERVICE`) - gRPC service on ports 3334/3335
50+
- **Config** (`QUICKPIZZA_ENABLE_CONFIG_SERVICE`) - Configuration endpoint
51+
- **HTTP Testing** (`QUICKPIZZA_ENABLE_HTTP_TESTING_SERVICE`) - HTTP testing utilities
52+
- **Test K6 IO** (`QUICKPIZZA_ENABLE_TEST_K6_IO_SERVICE`) - Legacy test.k6.io replacement endpoints
5253

5354
### Key Packages
5455
- `pkg/http/` - Main HTTP server and route handlers
@@ -73,7 +74,7 @@ Comprehensive observability built-in:
7374
- **Frontend Observability**: Grafana Faro support
7475

7576
### Environment Configuration
76-
- `QUICKPIZZA_ALL_SERVICES` - Enable all services (default: true)
77+
- `QUICKPIZZA_ENABLE_ALL_SERVICES` - Enable all services (default: true)
7778
- `QUICKPIZZA_LOG_LEVEL` - Set logging level (default: info)
7879
- `QUICKPIZZA_OTLP_ENDPOINT` - OpenTelemetry collector endpoint
7980
- `QUICKPIZZA_PYROSCOPE_ENDPOINT` - Pyroscope server for profiling

cmd/main.go

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,47 +73,47 @@ func main() {
7373
server.AddPrometheusHandler()
7474

7575
// Enable services in this instance. Services are enabled with the following logic:
76-
// If QUICKPIZZA_ALL_SERVICES is either _not set_ or set to a truthy value, all services are enabled. This is the
76+
// If QUICKPIZZA_ENABLE_ALL_SERVICES is either _not set_ or set to a truthy value, all services are enabled. This is the
7777
// default behavior.
78-
// If QUICKPIZZA_ALL_SERVICES is set to a falsy values, services are opted-in by setting the environment variables
78+
// If QUICKPIZZA_ENABLE_ALL_SERVICES is set to a falsy values, services are opted-in by setting the environment variables
7979
// below to a truty value.
8080

81-
if envServe("QUICKPIZZA_HTTP_TESTING") {
81+
if envServe("QUICKPIZZA_ENABLE_HTTP_TESTING_SERVICE") {
8282
server.AddHTTPTesting()
8383
}
8484

85-
if envServe("QUICKPIZZA_TEST_K6_IO") {
85+
if envServe("QUICKPIZZA_ENABLE_TEST_K6_IO_SERVICE") {
8686
server.AddTestK6IO()
8787
}
8888

89-
if envServe("QUICKPIZZA_CONFIG") {
89+
if envServe("QUICKPIZZA_ENABLE_CONFIG_SERVICE") {
9090
// Prefix for env vars is QUICKPIZZA_CONF_ instead of QUICKPIZZA_CONFIG_ to avoid picking up variables
9191
// generated by K8s from the pod name.
9292
server.AddConfigHandler(envConfig("QUICKPIZZA_CONF_"))
9393
}
9494

95-
if envServe("QUICKPIZZA_FRONTEND") {
95+
if envServe("QUICKPIZZA_ENABLE_PUBLIC_API_SERVICE") {
9696
// Serve frontend static assets
9797
server.AddFrontend()
9898

9999
// If running as a microservice (not all services in one instance),
100100
// also act as a gateway to proxy public-facing endpoints
101101
if !envServeAll() {
102102
server.AddGateway(
103-
envEndpoint("QUICKPIZZA_CATALOG"),
104-
envEndpoint("QUICKPIZZA_COPY"),
105-
envEndpoint("QUICKPIZZA_WS"),
106-
envEndpoint("QUICKPIZZA_RECOMMENDATIONS"),
107-
envEndpoint("QUICKPIZZA_CONFIG"),
103+
envEndpoint("QUICKPIZZA_ENABLE_CATALOG_SERVICE", "QUICKPIZZA_CATALOG_ENDPOINT"),
104+
envEndpoint("QUICKPIZZA_ENABLE_COPY_SERVICE", "QUICKPIZZA_COPY_ENDPOINT"),
105+
envEndpoint("QUICKPIZZA_ENABLE_WS_SERVICE", "QUICKPIZZA_WS_ENDPOINT"),
106+
envEndpoint("QUICKPIZZA_ENABLE_RECOMMENDATIONS_SERVICE", "QUICKPIZZA_RECOMMENDATIONS_ENDPOINT"),
107+
envEndpoint("QUICKPIZZA_ENABLE_CONFIG_SERVICE", "QUICKPIZZA_CONFIG_ENDPOINT"),
108108
)
109109
}
110110
}
111111

112-
if envServe("QUICKPIZZA_WS") {
112+
if envServe("QUICKPIZZA_ENABLE_WS_SERVICE") {
113113
server.AddWebSocket()
114114
}
115115

116-
if envServe("QUICKPIZZA_CATALOG") {
116+
if envServe("QUICKPIZZA_ENABLE_CATALOG_SERVICE") {
117117
db, err := database.NewCatalog(envDBConnString())
118118
if err != nil {
119119
slog.Error("setting up database connection", "err", err)
@@ -122,7 +122,7 @@ func main() {
122122
server.AddCatalogHandler(db)
123123
}
124124

125-
if envServe("QUICKPIZZA_COPY") {
125+
if envServe("QUICKPIZZA_ENABLE_COPY_SERVICE") {
126126
db, err := database.NewCopy(envDBConnString())
127127
if err != nil {
128128
slog.Error("setting up database connection", "err", err)
@@ -134,14 +134,14 @@ func main() {
134134
// Recommendations service needs to know the URL where the Catalog and Copy services are located.
135135
// This URL is automatically set to `localhost` if Recommendations is enabled at the same time as either of those.
136136
// If they are not, URLs are sourced from QUICKPIZZA_CATALOG_ENDPOINT and QUICKPIZZA_COPY_ENDPOINT.
137-
if envServe("QUICKPIZZA_RECOMMENDATIONS") {
138-
catalogClient := qphttp.NewCatalogClient(envEndpoint("QUICKPIZZA_CATALOG")).WithClient(httpCli)
139-
copyClient := qphttp.NewCopyClient(envEndpoint("QUICKPIZZA_COPY")).WithClient(httpCli)
137+
if envServe("QUICKPIZZA_ENABLE_RECOMMENDATIONS_SERVICE") {
138+
catalogClient := qphttp.NewCatalogClient(envEndpoint("QUICKPIZZA_ENABLE_CATALOG_SERVICE", "QUICKPIZZA_CATALOG_ENDPOINT")).WithClient(httpCli)
139+
copyClient := qphttp.NewCopyClient(envEndpoint("QUICKPIZZA_ENABLE_COPY_SERVICE", "QUICKPIZZA_COPY_ENDPOINT")).WithClient(httpCli)
140140

141141
server.AddRecommendations(catalogClient, copyClient)
142142
}
143143

144-
if envServe("QUICKPIZZA_GRPC") {
144+
if envServe("QUICKPIZZA_ENABLE_GRPC_SERVICE") {
145145
grpcServer := qpgrpc.NewServer(":3334", ":3335")
146146
go func() {
147147
err := grpcServer.ListenAndServe()
@@ -263,15 +263,15 @@ func envPyroscopeConfig() (pyroscope.Config, bool) {
263263
}
264264

265265
func envServeAll() bool {
266-
allSvcs, present := os.LookupEnv("QUICKPIZZA_ALL_SERVICES")
266+
allSvcs, present := os.LookupEnv("QUICKPIZZA_ENABLE_ALL_SERVICES")
267267
allSvcsB, _ := strconv.ParseBool(allSvcs)
268268

269-
// If QUICKPIZZA_ALL_SERVICES is not defined (default), serve everything.
269+
// If QUICKPIZZA_ENABLE_ALL_SERVICES is not defined (default), serve everything.
270270
if !present {
271271
return true
272272
}
273273

274-
// Otherwise, serve all if QUICKPIZZA_ALL_SERVICES is truthy.
274+
// Otherwise, serve all if QUICKPIZZA_ENABLE_ALL_SERVICES is truthy.
275275
return allSvcsB
276276
}
277277

@@ -280,14 +280,15 @@ func envServe(name string) bool {
280280
return envServeAll() || envBool(name)
281281
}
282282

283-
// envEndpoint returns the endpoint for a given service. If the service is enabled in this instance, it returns
284-
// `localhost`. If it isn't, it returns the value of QUICKPIZZA_SERVICENAME_ENDPOINT.fs
285-
func envEndpoint(name string) string {
286-
if envServe(name) {
283+
// envEndpoint returns the endpoint URL for a service.
284+
// If the service is enabled (envServe(svcEnv) == true), it returns "http://localhost:3333".
285+
// Otherwise, it returns the value of the endpointEnv environment variable.
286+
func envEndpoint(svcEnv, endpointEnv string) string {
287+
if envServe(svcEnv) {
287288
return "http://localhost:3333"
288289
}
289290

290-
endpoint, _ := os.LookupEnv(name + "_ENDPOINT")
291+
endpoint, _ := os.LookupEnv(endpointEnv)
291292
return endpoint
292293
}
293294

compose.grafana-cloud.microservices.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
x-quickpizza-env-common: &quickpizza-env-common
22
QUICKPIZZA_OTLP_ENDPOINT: http://alloy:4318
33
QUICKPIZZA_TRUST_CLIENT_TRACEID: true
4-
QUICKPIZZA_ALL_SERVICES: 0
4+
QUICKPIZZA_ENABLE_ALL_SERVICES: 0 # 0 for microservice mode
55
QUICKPIZZA_CATALOG_ENDPOINT: http://catalog:3333
66
QUICKPIZZA_COPY_ENDPOINT: http://copy:3333
77
QUICKPIZZA_WS_ENDPOINT: http://ws:3333
@@ -51,7 +51,7 @@ services:
5151
- "service.type=application"
5252
environment:
5353
<<: *quickpizza-env-common
54-
QUICKPIZZA_CATALOG: "1"
54+
QUICKPIZZA_ENABLE_CATALOG_SERVICE: "1"
5555
QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID: "catalog"
5656
QUICKPIZZA_OTEL_SERVICE_NAME: "catalog"
5757

@@ -62,7 +62,7 @@ services:
6262
- "service.type=application"
6363
environment:
6464
<<: *quickpizza-env-common
65-
QUICKPIZZA_CONFIG: "1"
65+
QUICKPIZZA_ENABLE_CONFIG_SERVICE: "1"
6666
QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID: "config"
6767
QUICKPIZZA_OTEL_SERVICE_NAME: "config"
6868
copy:
@@ -72,7 +72,7 @@ services:
7272
- "service.type=application"
7373
environment:
7474
<<: *quickpizza-env-common
75-
QUICKPIZZA_COPY: "1"
75+
QUICKPIZZA_ENABLE_COPY_SERVICE: "1"
7676
QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID: "copy"
7777
QUICKPIZZA_OTEL_SERVICE_NAME: "copy"
7878

@@ -85,7 +85,7 @@ services:
8585
- "3333:3333"
8686
environment:
8787
<<: *quickpizza-env-common
88-
QUICKPIZZA_FRONTEND: "1"
88+
QUICKPIZZA_ENABLE_PUBLIC_API_SERVICE: "1"
8989
QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID: "public-api"
9090
QUICKPIZZA_OTEL_SERVICE_NAME: "public-api"
9191

@@ -96,7 +96,7 @@ services:
9696
- "service.type=application"
9797
environment:
9898
<<: *quickpizza-env-common
99-
QUICKPIZZA_RECOMMENDATIONS: "1"
99+
QUICKPIZZA_ENABLE_RECOMMENDATIONS_SERVICE: "1"
100100
QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID: "recommendations"
101101
QUICKPIZZA_OTEL_SERVICE_NAME: "recommendations"
102102

@@ -107,7 +107,7 @@ services:
107107
- "service.type=application"
108108
environment:
109109
<<: *quickpizza-env-common
110-
QUICKPIZZA_WS: "1"
110+
QUICKPIZZA_ENABLE_WS_SERVICE: "1"
111111
QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID: "ws"
112112
QUICKPIZZA_OTEL_SERVICE_NAME: "ws"
113113

compose.grafana-cloud.monolithic.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ services:
4040
environment:
4141
QUICKPIZZA_OTLP_ENDPOINT: http://alloy:4318
4242
QUICKPIZZA_TRUST_CLIENT_TRACEID: 1
43-
QUICKPIZZA_ALL_SERVICES: 1 # 1 for monolithic mode
43+
QUICKPIZZA_ENABLE_ALL_SERVICES: 1 # 1 for monolithic mode
4444
QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID: "quickpizza"
4545
QUICKPIZZA_OTEL_SERVICE_NAME: "quickpizza"
4646

kubernetes/base/quickpizza/catalog.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ spec:
3434
name: quickpizza-env
3535
optional: true
3636
env:
37-
- name: QUICKPIZZA_CATALOG
37+
- name: QUICKPIZZA_ENABLE_CATALOG_SERVICE
3838
value: "1"
3939
- name: QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID
4040
valueFrom:

kubernetes/base/quickpizza/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ spec:
3434
name: quickpizza-env
3535
optional: true
3636
env:
37-
- name: QUICKPIZZA_CONFIG
37+
- name: QUICKPIZZA_ENABLE_CONFIG_SERVICE
3838
value: "1"
3939
- name: QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID
4040
valueFrom:

kubernetes/base/quickpizza/copy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ spec:
3434
name: quickpizza-env
3535
optional: true
3636
env:
37-
- name: QUICKPIZZA_COPY
37+
- name: QUICKPIZZA_ENABLE_COPY_SERVICE
3838
value: "1"
3939
- name: QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID
4040
valueFrom:

kubernetes/base/quickpizza/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ configMapGenerator:
1818
# Trust all incoming TraceIDs for demo purposes
1919
- QUICKPIZZA_TRUST_CLIENT_TRACEID=true
2020
# Microservice mode: Set to 0 to run services in separate pods
21-
- QUICKPIZZA_ALL_SERVICES=0
21+
- QUICKPIZZA_ENABLE_ALL_SERVICES=0
2222
- QUICKPIZZA_CATALOG_ENDPOINT=http://quickpizza-catalog:3333
2323
- QUICKPIZZA_COPY_ENDPOINT=http://quickpizza-copy:3333
2424
- QUICKPIZZA_WS_ENDPOINT=http://quickpizza-ws:3333

kubernetes/base/quickpizza/public-api.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ spec:
3434
name: quickpizza-env
3535
optional: true
3636
env:
37-
- name: QUICKPIZZA_FRONTEND
37+
- name: QUICKPIZZA_ENABLE_PUBLIC_API_SERVICE
3838
value: "1"
3939
- name: QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID
4040
valueFrom:

kubernetes/base/quickpizza/recommendations.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ spec:
3434
name: quickpizza-env
3535
optional: true
3636
env:
37-
- name: QUICKPIZZA_RECOMMENDATIONS
37+
- name: QUICKPIZZA_ENABLE_RECOMMENDATIONS_SERVICE
3838
value: "1"
3939
- name: QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID
4040
valueFrom:

0 commit comments

Comments
 (0)