-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.layered.example.yaml
More file actions
230 lines (199 loc) · 5.9 KB
/
Copy pathconfig.layered.example.yaml
File metadata and controls
230 lines (199 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Octopus API Gateway - Layered Configuration Example
#
# This example demonstrates multi-file configuration merging.
#
# Usage:
# octopus --config config/base.yaml --config config/production.yaml --config config/secrets.yaml
#
# Or in code:
# let config = octopus_config::load_and_merge(vec![
# "config/base.yaml",
# "config/production.yaml",
# "config/secrets.yaml"
# ])?;
#
# Files are merged in order:
# - Later files override earlier files
# - Upstreams/routes/plugins are merged by name/path
# - Arrays are replaced (not concatenated)
---
# File 1: config/base.yaml - Common defaults for all environments
gateway:
listen: "0.0.0.0:8080"
workers: 0 # Auto-detect
request_timeout: "30s"
shutdown_timeout: "10s"
max_body_size: 10485760 # 10MB
# Internal route prefix (default: "__")
# Internal endpoints will be accessible at:
# - /__admin (admin dashboard)
# - /__metrics (Prometheus metrics)
# - /__farp (FARP API)
# - /__health (health checks)
internal_route_prefix: "__"
compression:
enabled: true
algorithms: ["gzip", "brotli"]
min_size: 1024
upstreams:
- name: "api-service"
instances:
- id: "api-1"
host: "api-service"
port: 8080
weight: 1
lb_policy: "round_robin"
health_check:
enabled: true
interval: "10s"
timeout: "5s"
path: "/health"
routes:
- path: "/api/*"
methods: ["GET", "POST", "PUT", "DELETE"]
upstream: "api-service"
priority: 10
observability:
logging:
level: "info"
format: "json"
metrics:
enabled: true
endpoint: "/__metrics" # Using internal prefix
tracing:
enabled: false
---
# File 2: config/production.yaml - Production-specific overrides
gateway:
listen: "0.0.0.0:443" # Override port for production
workers: 16 # Override for production hardware
tls:
cert_file: "/etc/octopus/tls/cert.pem"
key_file: "/etc/octopus/tls/key.pem"
# Override upstream instances for production
upstreams:
- name: "api-service"
instances:
- id: "api-prod-1"
host: "api-prod-1.internal"
port: 8080
weight: 1
- id: "api-prod-2"
host: "api-prod-2.internal"
port: 8080
weight: 1
- id: "api-prod-3"
host: "api-prod-3.internal"
port: 8080
weight: 1
lb_policy: "least_conn" # Different policy for production
# Add production-only routes
routes:
- path: "/api/admin/*"
methods: ["GET", "POST", "PUT", "DELETE"]
upstream: "api-service"
priority: 20
# This will merge with existing routes
observability:
logging:
level: "warn" # Less verbose in production
format: "json"
tracing:
enabled: true
endpoint: "http://jaeger:14268/api/traces"
---
# File 3: config/secrets.yaml - Sensitive values (gitignored, from secrets manager)
# This file should NOT be committed to version control
# JWT secret from environment or secrets manager
plugins:
- name: "jwt-auth"
enabled: true
config:
secret: "${JWT_SECRET}" # From environment variable
algorithm: "HS256"
skip_paths:
- "/__health"
- "/__metrics"
# TLS certificates paths (could be from secrets manager)
gateway:
tls:
cert_file: "${TLS_CERT_PATH}"
key_file: "${TLS_KEY_PATH}"
# Database connection strings
upstreams:
- name: "database-service"
instances:
- id: "db-1"
host: "${DB_HOST}"
port: 5432
weight: 1
---
# COMPLETE EXAMPLE: How files are merged
# Starting with base.yaml:
# gateway.listen = "0.0.0.0:8080"
# gateway.workers = 0
# gateway.tls = null
# upstreams[0].instances = [api-1]
# After merging production.yaml:
# gateway.listen = "0.0.0.0:443" ← OVERRIDDEN
# gateway.workers = 16 ← OVERRIDDEN
# gateway.tls = { cert_file, key_file } ← ADDED
# upstreams[0].instances = [api-prod-1, api-prod-2, api-prod-3] ← REPLACED
# After merging secrets.yaml:
# gateway.tls.cert_file = "${TLS_CERT_PATH}" ← OVERRIDDEN
# gateway.tls.key_file = "${TLS_KEY_PATH}" ← OVERRIDDEN
# plugins = [jwt-auth] ← ADDED
# upstreams[1] = database-service ← ADDED (new upstream)
---
# TYPICAL DEPLOYMENT STRUCTURES:
# Development:
# octopus --config config/base.yaml --config config/dev.yaml
# Staging:
# octopus --config config/base.yaml --config config/staging.yaml --config config/secrets.yaml
# Production:
# octopus --config config/base.yaml --config config/production.yaml --config config/secrets.yaml
# Local developer overrides:
# octopus --config config/base.yaml --config config/dev.yaml --config config/local.yaml
---
# MERGE BEHAVIOR:
# 1. Gateway Config: Later values override earlier values
# 2. Upstreams: Merged by name (same name = override, new name = append)
# 3. Routes: Merged by path (same path = override, new path = append)
# 4. Plugins: Merged by name (same name = override, new name = append)
# 5. Arrays: Replaced entirely (not concatenated)
# Example: If base.yaml has instances=[a,b] and prod.yaml has instances=[c,d],
# result is instances=[c,d] (not [a,b,c,d])
---
# INTERNAL ROUTES:
# With internal_route_prefix: "__"
#
# Admin dashboard:
# http://localhost:8080/__admin
# http://localhost:8080/__admin/routes
# http://localhost:8080/__admin/health
# http://localhost:8080/__admin/plugins
#
# Prometheus metrics:
# http://localhost:8080/__metrics
#
# FARP API:
# http://localhost:8080/__farp/register
# http://localhost:8080/__farp/openapi.json
# http://localhost:8080/__farp/asyncapi.json
#
# Legacy routes (backwards compatible):
# http://localhost:8080/admin
# http://localhost:8080/metrics
# http://localhost:8080/farp
#
# This prevents conflicts with your application routes!
---
# ENVIRONMENT VARIABLE SUBSTITUTION:
# Syntax: ${VAR_NAME} or ${VAR_NAME:-default_value}
#
# Examples:
# jwt_secret: "${JWT_SECRET}"
# db_host: "${DATABASE_HOST:-localhost}"
# api_key: "${API_KEY}"
#
# Environment variables are expanded when config is loaded.