-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathapi-gateway.kdl
More file actions
248 lines (207 loc) · 5.25 KB
/
api-gateway.kdl
File metadata and controls
248 lines (207 loc) · 5.25 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// Example: API Gateway Configuration
//
// Production-ready API gateway with:
// - Versioned APIs (v1 deprecated, v2 current)
// - JWT/API key authentication
// - Rate limiting per client
// - Security headers
// - JSON error responses
system {
worker-threads 0
max-connections 10000
graceful-shutdown-timeout-secs 30
}
listeners {
listener "https" {
address "0.0.0.0:8443"
protocol "https"
tls {
cert-file "/etc/zentinel/certs/api.crt"
key-file "/etc/zentinel/certs/api.key"
min-version "TLS1.2"
}
}
listener "http" {
address "0.0.0.0:8080"
protocol "http"
request-timeout-secs 60
}
}
// =============================================================================
// Agents for auth and rate limiting
// =============================================================================
agents {
agent "auth" {
type "auth"
grpc address="http://localhost:50051"
events "request_headers"
timeout-ms 100
failure-mode "closed"
circuit-breaker {
failure-threshold 5
success-threshold 2
timeout-seconds 30
}
}
agent "ratelimit" {
type "rate-limit"
grpc address="http://localhost:50052"
events "request_headers"
timeout-ms 50
failure-mode "open"
}
}
// =============================================================================
// Filters (agent-backed)
// =============================================================================
filters {
filter "auth" {
type "agent"
agent "auth"
timeout-ms 100
failure-mode "closed"
}
filter "ratelimit" {
type "agent"
agent "ratelimit"
timeout-ms 50
failure-mode "open"
}
}
// =============================================================================
// Routes
// =============================================================================
routes {
// Health check - no auth required
route "health" {
priority "critical"
matches {
path "/health"
}
builtin-handler "health"
}
// Metrics endpoint
route "metrics" {
priority "critical"
matches {
path "/metrics"
}
builtin-handler "metrics"
}
// API v2 - current version
route "api-v2" {
priority "high"
matches {
path-prefix "/api/v2/"
method "GET" "POST" "PUT" "DELETE" "PATCH"
}
upstream "api-v2"
filters "auth" "ratelimit"
retry-policy {
max-attempts 3
timeout-ms 5000
backoff-base-ms 100
retryable-status-codes 502 503 504
}
policies {
timeout-secs 30
max-body-size "10MB"
failure-mode "closed"
}
}
// API v1 - legacy, deprecated
route "api-v1" {
priority "normal"
matches {
path-prefix "/api/v1/"
}
upstream "api-v1"
filters "auth"
policies {
timeout-secs 60
failure-mode "closed"
}
}
// OpenAPI documentation - public
route "docs" {
priority "low"
matches {
path-prefix "/docs/"
}
upstream "docs-server"
policies {
timeout-secs 10
}
}
}
// =============================================================================
// Upstreams
// =============================================================================
upstreams {
upstream "api-v2" {
target "127.0.0.1:3000" weight=100
target "127.0.0.1:3001" weight=100
load-balancing "round-robin"
health-check {
type "http" {
path "/health"
expected-status 200
}
interval-secs 5
timeout-secs 3
healthy-threshold 2
unhealthy-threshold 3
}
timeouts {
connect-secs 5
request-secs 30
}
}
upstream "api-v1" {
target "127.0.0.1:3010" weight=1
load-balancing "round-robin"
health-check {
type "http" {
path "/health"
}
interval-secs 10
timeout-secs 5
healthy-threshold 2
unhealthy-threshold 3
}
}
upstream "docs-server" {
target "127.0.0.1:3020" weight=1
load-balancing "round-robin"
}
}
// =============================================================================
// Observability
// =============================================================================
observability {
metrics {
enabled #true
address "0.0.0.0:9090"
path "/metrics"
}
logging {
level "info"
format "json"
access-log {
enabled #true
file "/var/log/zentinel/api-gateway-access.log"
include-trace-id #true
}
}
tracing {
enabled #true
backend "otlp" {
endpoint "http://localhost:4317"
}
}
}
limits {
max-header-size-bytes 8192
max-header-count 100
max-body-size-bytes 10485760
}