zuplo 7.15.1 → 7.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/ai-gateway/observability/data-handling.mdx +10 -10
- package/docs/ai-gateway/observability/tracing.mdx +206 -17
- package/docs/articles/deployments-and-rollbacks.mdx +0 -1
- package/docs/articles/opentelemetry.mdx +3 -0
- package/docs/dedicated/akamai/hostname-routing.mdx +264 -0
- package/docs/guides/backend-failover.mdx +0 -1
- package/docs/policies/mcp-token-exchange-inbound/doc.md +34 -3
- package/docs/policies/mcp-token-exchange-inbound/schema.json +28 -0
- package/package.json +5 -5
- package/docs/guides/blue-green-deployments.mdx +0 -199
|
@@ -53,16 +53,16 @@ bodies. How long Zuplo keeps them depends on your plan. See
|
|
|
53
53
|
These features handle prompt or completion text when you turn them on. Each one
|
|
54
54
|
is off until you add it.
|
|
55
55
|
|
|
56
|
-
| Feature | Content it handles
|
|
57
|
-
| ----------------------------------------------------------------------------- |
|
|
58
|
-
| [Semantic Cache](../../policies/ai-gateway-semantic-cache-inbound.mdx) | The system prompt and the most recent messages, which form the match key, and the provider's response.
|
|
59
|
-
| [Comet Opik Tracing](../../policies/ai-gateway-opik-tracing-inbound.mdx) | Prompt messages or input, completion text, model, token counts, temperature and maximum tokens, request ID, and route.
|
|
60
|
-
| [Galileo Tracing](../../policies/ai-gateway-galileo-tracing-inbound.mdx) | Prompt and completion text, model parameters, finish reasons, token counts, duration, request ID, and route.
|
|
61
|
-
| [Akamai AI Firewall](../../policies/ai-gateway-akamai-firewall-inbound.mdx) | Prompts and completions, for inspection.
|
|
62
|
-
| [Prompt Injection Protection](../../policies/ai-gateway-prompt-injection.mdx) | The newest message of each request, for classification.
|
|
63
|
-
| [Smart Router](../../policies/ai-gateway-smart-router-inbound.mdx) | The last user prompt, for classification.
|
|
64
|
-
| [Log plugins](../../articles/logging.mdx#log-integrations) | The request logs described earlier and messages that policies write with `context.log`. Content appears only if a custom policy logs it.
|
|
65
|
-
| [OpenTelemetry plugin](./tracing.mdx) | Span timings, HTTP method, URL, status code,
|
|
56
|
+
| Feature | Content it handles | Where the content goes |
|
|
57
|
+
| ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
58
|
+
| [Semantic Cache](../../policies/ai-gateway-semantic-cache-inbound.mdx) | The system prompt and the most recent messages, which form the match key, and the provider's response. | Zuplo's semantic cache, which keeps each app's entries apart. Entries expire after `expirationSecondsTtl` seconds: one hour by default, up to 30 days. |
|
|
59
|
+
| [Comet Opik Tracing](../../policies/ai-gateway-opik-tracing-inbound.mdx) | Prompt messages or input, completion text, model, token counts, temperature and maximum tokens, request ID, and route. | Your Comet Opik workspace and project. |
|
|
60
|
+
| [Galileo Tracing](../../policies/ai-gateway-galileo-tracing-inbound.mdx) | Prompt and completion text, model parameters, finish reasons, token counts, duration, request ID, and route. | Your Galileo project and log stream. |
|
|
61
|
+
| [Akamai AI Firewall](../../policies/ai-gateway-akamai-firewall-inbound.mdx) | Prompts and completions, for inspection. | Akamai Firewall for AI. |
|
|
62
|
+
| [Prompt Injection Protection](../../policies/ai-gateway-prompt-injection.mdx) | The newest message of each request, for classification. | The classifier you configure: an OpenAI-compatible API, or another app on the same gateway and its provider. |
|
|
63
|
+
| [Smart Router](../../policies/ai-gateway-smart-router-inbound.mdx) | The last user prompt, for classification. | The classifier you configure, such as another app on the same gateway and its provider. |
|
|
64
|
+
| [Log plugins](../../articles/logging.mdx#log-integrations) | The request logs described earlier and messages that policies write with `context.log`. Content appears only if a custom policy logs it. | Your logging service, such as Datadog, Splunk, or AWS CloudWatch. |
|
|
65
|
+
| [OpenTelemetry plugin](./tracing.mdx) | Span timings, HTTP method, URL, status code, request ID, model, token usage, and cost. Prompt and completion text only when you turn on content capture. | Zuplo's trace storage or your OpenTelemetry backend. |
|
|
66
66
|
|
|
67
67
|
The [Data Loss Prevention](../../policies/ai-gateway-dlp-inbound.mdx) policy
|
|
68
68
|
scans content inside the gateway and doesn't send it to another service.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: AI Gateway Tracing
|
|
2
|
+
title: AI Gateway OpenTelemetry Tracing
|
|
3
3
|
sidebar_label: Tracing
|
|
4
4
|
description:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Trace AI Gateway requests with OpenTelemetry GenAI spans that record model,
|
|
6
|
+
provider, token usage, cost, fallbacks, and optional prompt and completion
|
|
7
|
+
content.
|
|
8
8
|
applies_to:
|
|
9
9
|
product: gateway
|
|
10
10
|
hosting: all
|
|
@@ -13,10 +13,11 @@ applies_to:
|
|
|
13
13
|
An AI Gateway runs the same
|
|
14
14
|
[OpenTelemetry plugin](../../articles/opentelemetry.mdx) as any Zuplo project.
|
|
15
15
|
With the plugin on, each request to an app becomes a trace with a span for every
|
|
16
|
-
policy in the app's chain, the AI Gateway handler, and
|
|
17
|
-
provider.
|
|
18
|
-
|
|
19
|
-
trace
|
|
16
|
+
policy in the app's chain, the AI Gateway handler, and every call to an LLM
|
|
17
|
+
provider. Provider calls are recorded as OpenTelemetry GenAI spans that carry
|
|
18
|
+
the model, token usage, cost, and outcome of each attempt. The gateway reads W3C
|
|
19
|
+
trace context (`traceparent`) from the caller and sends it on to the provider,
|
|
20
|
+
so an agent's model calls join the agent's own trace.
|
|
20
21
|
|
|
21
22
|
<Diagram height="h-64">
|
|
22
23
|
<DiagramNode id="agent">Agent</DiagramNode>
|
|
@@ -108,11 +109,12 @@ to change it.
|
|
|
108
109
|
## What a trace contains
|
|
109
110
|
|
|
110
111
|
A request to an app produces a trace like the following. The app's policy chain
|
|
111
|
-
appears inside the Configuration Executor span, one span per entry
|
|
112
|
-
|
|
112
|
+
appears inside the Configuration Executor span, one span per entry. Each call to
|
|
113
|
+
an LLM provider gets a GenAI inference span, with the HTTP call to the
|
|
114
|
+
provider's host nested under it:
|
|
113
115
|
|
|
114
116
|
```text
|
|
115
|
-
POST <route>
|
|
117
|
+
POST <route> gen_ai.request.model, zuplo.ai_gateway.*
|
|
116
118
|
├── policies:inbound
|
|
117
119
|
│ ├── policy:ai-gateway-configuration-loader-inbound
|
|
118
120
|
│ └── policy:ai-gateway-configuration-executor-inbound
|
|
@@ -121,16 +123,203 @@ POST <route>
|
|
|
121
123
|
│ ├── policy:ai-gateway-metering-inbound
|
|
122
124
|
│ └── policy:ai-gateway-semantic-cache-inbound
|
|
123
125
|
└── handler:aiGatewayHandlerV2
|
|
124
|
-
└──
|
|
126
|
+
└── chat gpt-5 gen_ai.*, zuplo.ai_gateway.cost.*
|
|
127
|
+
└── POST: api.openai.com
|
|
125
128
|
```
|
|
126
129
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
completion text
|
|
130
|
+
Every span carries timings and the request ID (`zp-rid`) that also appears in
|
|
131
|
+
the gateway's logs. HTTP spans add the method, URL, and status code. Prompt and
|
|
132
|
+
completion text is recorded only when you
|
|
133
|
+
[turn on content capture](#capture-prompts-and-completions).
|
|
134
|
+
|
|
135
|
+
## GenAI inference spans
|
|
136
|
+
|
|
137
|
+
The gateway records one inference span for each attempt to call a provider: the
|
|
138
|
+
primary call, each [fallback](../fallback.mdx), a
|
|
139
|
+
[quota fallback](../usage-limits.mdx#when-a-limit-is-exceeded) after a usage
|
|
140
|
+
limit is exceeded, and each retry after a provider returns `429`. The spans
|
|
141
|
+
follow the
|
|
142
|
+
[OpenTelemetry semantic conventions for generative AI](https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/),
|
|
143
|
+
so backends that understand GenAI telemetry, such as Langfuse, Datadog LLM
|
|
144
|
+
Observability, Honeycomb, and Grafana, show model, token, and cost views without
|
|
145
|
+
any mapping.
|
|
146
|
+
|
|
147
|
+
There's nothing extra to enable. With the OpenTelemetry plugin registered,
|
|
148
|
+
inference spans appear for every sampled request. All of them use the
|
|
149
|
+
instrumentation scope `ai-gateway`.
|
|
150
|
+
|
|
151
|
+
### Span names and kinds
|
|
152
|
+
|
|
153
|
+
Each inference span is a `CLIENT` span named `{operation} {model}`, for example
|
|
154
|
+
`chat gpt-5` or `embeddings text-embedding-3-small`. The operation comes from
|
|
155
|
+
the endpoint the client called:
|
|
156
|
+
|
|
157
|
+
| Endpoint | `gen_ai.operation.name` |
|
|
158
|
+
| ------------------------------------------------- | ----------------------- |
|
|
159
|
+
| `/v1/chat/completions`, `/v1/messages` | `chat` |
|
|
160
|
+
| `POST /v1/responses` | `chat` |
|
|
161
|
+
| `GET /v1/responses/{id}` | `fetch_response` |
|
|
162
|
+
| `DELETE /v1/responses/{id}` | `delete_response` |
|
|
163
|
+
| `/v1/messages/count_tokens` | `count_tokens` |
|
|
164
|
+
| `/v1/embeddings` | `embeddings` |
|
|
165
|
+
| Bedrock Runtime `converse` and `invoke` endpoints | `chat` |
|
|
166
|
+
|
|
167
|
+
A request that never reaches a provider, such as one a policy rejects or one
|
|
168
|
+
that fails validation, has no inference span. A semantic cache hit has none
|
|
169
|
+
either, because the gateway answers from the cache.
|
|
170
|
+
|
|
171
|
+
### Inference span attributes
|
|
172
|
+
|
|
173
|
+
| Attribute | Description |
|
|
174
|
+
| -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
175
|
+
| `gen_ai.operation.name` | The operation, from the table above. |
|
|
176
|
+
| `gen_ai.provider.name` | The provider, for example `openai`, `anthropic`, `gcp.vertex_ai`, `aws.bedrock`, or `azure.ai.openai`. |
|
|
177
|
+
| `zuplo.ai_gateway.provider.label` | The name of the provider in your gateway's **AI Providers** settings. |
|
|
178
|
+
| `gen_ai.request.model` | The model sent to the provider. |
|
|
179
|
+
| `gen_ai.request.stream` | `true` for a streamed request, otherwise `false`. |
|
|
180
|
+
| `gen_ai.request.max_tokens`, `temperature`, `top_p`, `top_k`, `seed`, and others | Sampling parameters, when the request sets them. |
|
|
181
|
+
| `gen_ai.response.id` | The provider's response ID. |
|
|
182
|
+
| `gen_ai.response.model` | The model that answered, as the provider reported it. |
|
|
183
|
+
| `gen_ai.response.finish_reasons` | The provider's own finish reasons, for example `["stop"]` or `["end_turn"]`. |
|
|
184
|
+
| `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` | Token usage. Matches the usage that [AI Gateway analytics](./analytics.mdx) and usage limits record. |
|
|
185
|
+
| `gen_ai.usage.cache_read.input_tokens`, `gen_ai.usage.cache_write.input_tokens` | Prompt cache tokens, when the provider reports them. |
|
|
186
|
+
| `gen_ai.usage.reasoning.output_tokens` | Reasoning tokens, when the provider reports them. |
|
|
187
|
+
| `zuplo.ai_gateway.cost.usd` | The cost of the attempt in US dollars. |
|
|
188
|
+
| `zuplo.ai_gateway.cost.source` | Where the cost came from: `provider`, `catalog`, or `unpriced`. |
|
|
189
|
+
| `zuplo.ai_gateway.cost.accuracy` | `exact`, `estimated`, or `unpriced`. |
|
|
190
|
+
| `zuplo.ai_gateway.attempt` | `primary`, `fallback`, `quota_fallback`, or `retry` (a retry after a `429`). |
|
|
191
|
+
| `server.address`, `server.port` | The provider host. |
|
|
192
|
+
| `error.type` | Set on a failed attempt. See [Errors and fallbacks](#errors-and-fallbacks). |
|
|
193
|
+
|
|
194
|
+
Cost uses the same prices as budgets and spend analytics, including any
|
|
195
|
+
[custom pricing](../custom-pricing.mdx) you set.
|
|
196
|
+
|
|
197
|
+
### Request span attributes
|
|
198
|
+
|
|
199
|
+
The request's root `SERVER` span summarizes what the gateway did with the
|
|
200
|
+
request:
|
|
201
|
+
|
|
202
|
+
| Attribute | Description |
|
|
203
|
+
| --------------------------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
204
|
+
| `gen_ai.request.model` | The model the client asked for, before any routing or fallback policy changed it. |
|
|
205
|
+
| `zuplo.ai_gateway.cache.status` | `hit` or `miss`, when the app uses the [semantic cache](../../policies/ai-gateway-semantic-cache-inbound.mdx). |
|
|
206
|
+
| `zuplo.ai_gateway.refused_by` | The name of the policy that rejected the request, or `handler` when the gateway's handler rejected it. |
|
|
207
|
+
| `zuplo.ai_gateway.quota_fallback` | `true` when a usage limit sent the request to its quota fallback model. |
|
|
208
|
+
|
|
209
|
+
### Errors and fallbacks
|
|
210
|
+
|
|
211
|
+
A failed attempt sets the span status to error and records a low-cardinality
|
|
212
|
+
`error.type`:
|
|
213
|
+
|
|
214
|
+
- The provider's HTTP status code, for example `503` or `429`.
|
|
215
|
+
- `timeout` when the attempt hit the fallback timeout.
|
|
216
|
+
- The error name, for example `TypeError`, when the call threw before a response
|
|
217
|
+
arrived.
|
|
218
|
+
|
|
219
|
+
The provider's error message isn't recorded, because it can quote the request.
|
|
220
|
+
|
|
221
|
+
Attempts for one request are siblings under the handler span. A request whose
|
|
222
|
+
primary model returns `503` and whose fallback succeeds looks like this:
|
|
223
|
+
|
|
224
|
+
```text
|
|
225
|
+
handler:aiGatewayHandlerV2
|
|
226
|
+
├── chat gpt-5 error.type=503, zuplo.ai_gateway.attempt=primary
|
|
227
|
+
│ └── POST: api.openai.com
|
|
228
|
+
└── chat claude-sonnet-4-5 zuplo.ai_gateway.attempt=fallback, usage, cost
|
|
229
|
+
└── POST: api.anthropic.com
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Streaming responses
|
|
233
|
+
|
|
234
|
+
For a streamed response, the HTTP span ends when the provider starts streaming,
|
|
235
|
+
and the inference span stays open until the stream finishes. The inference span
|
|
236
|
+
records:
|
|
237
|
+
|
|
238
|
+
- `gen_ai.response.time_to_first_chunk`: seconds from sending the request to the
|
|
239
|
+
first chunk of the stream.
|
|
240
|
+
- `zuplo.ai_gateway.stream.end`: `complete`, `error` (including an error event
|
|
241
|
+
inside the stream), or `client_cancelled` when the client disconnected first.
|
|
242
|
+
- Token usage and cost, read from the finished stream.
|
|
243
|
+
|
|
244
|
+
The plugin waits for an open inference span before it exports the trace, up to
|
|
245
|
+
five minutes after the response starts, so long streams export complete.
|
|
246
|
+
|
|
247
|
+
## Capture prompts and completions
|
|
248
|
+
|
|
249
|
+
Inference spans don't record prompt or completion text by default. To record it,
|
|
250
|
+
set `instrumentation.genAi.captureContent` to `true`:
|
|
251
|
+
|
|
252
|
+
```ts title="modules/zuplo.runtime.ts"
|
|
253
|
+
runtime.addPlugin(
|
|
254
|
+
new OpenTelemetryPlugin({
|
|
255
|
+
exporter: {
|
|
256
|
+
url: environment.OTEL_TRACES_URL,
|
|
257
|
+
headers: { "api-key": environment.OTEL_API_KEY },
|
|
258
|
+
},
|
|
259
|
+
instrumentation: {
|
|
260
|
+
genAi: { captureContent: true },
|
|
261
|
+
},
|
|
262
|
+
}),
|
|
263
|
+
);
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
With capture on, each inference span records these attributes as JSON in the
|
|
267
|
+
OpenTelemetry GenAI message format:
|
|
268
|
+
|
|
269
|
+
- `gen_ai.system_instructions`: the system prompt.
|
|
270
|
+
- `gen_ai.input.messages`: the messages sent to the provider. Embeddings
|
|
271
|
+
requests don't record input.
|
|
272
|
+
- `gen_ai.output.messages`: the response the client received, including a
|
|
273
|
+
streamed response.
|
|
274
|
+
|
|
275
|
+
Each attribute is capped at 8 KiB and stays valid JSON when it's truncated. The
|
|
276
|
+
plugin turns capture on only for the boolean `true`.
|
|
277
|
+
|
|
278
|
+
Input is recorded as sent to the provider, after policies such as
|
|
279
|
+
[Data Loss Prevention](../../policies/ai-gateway-dlp-inbound.mdx) changed it.
|
|
280
|
+
Output is recorded as returned to the client, after every policy and hook that
|
|
281
|
+
changes the response. Well-known credential formats, such as API keys, bearer
|
|
282
|
+
tokens, JWTs, private keys, and cloud and GitHub tokens, are replaced with
|
|
283
|
+
placeholders such as `[REDACTED:api_key]`.
|
|
284
|
+
|
|
285
|
+
:::warning
|
|
286
|
+
|
|
287
|
+
Prompts and completions often contain personal or otherwise sensitive data.
|
|
288
|
+
Turning on content capture sends that content to Zuplo's trace storage and to
|
|
289
|
+
any backend you export to. Content capture doesn't remove personal data, so mask
|
|
290
|
+
it with the Data Loss Prevention policy, which runs before the content is
|
|
291
|
+
recorded.
|
|
292
|
+
|
|
293
|
+
:::
|
|
294
|
+
|
|
295
|
+
To capture content for a single app instead of the whole gateway, use a tracing
|
|
296
|
+
policy. See
|
|
130
297
|
[AI Gateway data handling](./data-handling.mdx#capture-prompts-and-completions-for-an-app).
|
|
131
298
|
|
|
132
|
-
|
|
133
|
-
|
|
299
|
+
## Query GenAI spans in your backend
|
|
300
|
+
|
|
301
|
+
Because the attributes follow the semantic conventions, you can query model
|
|
302
|
+
activity directly in your backend. For example:
|
|
303
|
+
|
|
304
|
+
- Compare models by latency: filter on `gen_ai.operation.name = chat` and group
|
|
305
|
+
span duration by `gen_ai.response.model`.
|
|
306
|
+
- Find spend by provider: sum `zuplo.ai_gateway.cost.usd` grouped by
|
|
307
|
+
`zuplo.ai_gateway.provider.label`.
|
|
308
|
+
- Find failing providers: filter on `error.type` and group by
|
|
309
|
+
`gen_ai.provider.name`.
|
|
310
|
+
- See how often fallbacks serve traffic: count spans where
|
|
311
|
+
`zuplo.ai_gateway.attempt` is `fallback` or `quota_fallback`.
|
|
312
|
+
- Measure time to first token: chart `gen_ai.response.time_to_first_chunk` for
|
|
313
|
+
streamed requests.
|
|
314
|
+
- Find rejected requests: filter request spans on `zuplo.ai_gateway.refused_by`.
|
|
315
|
+
|
|
316
|
+
:::note
|
|
317
|
+
|
|
318
|
+
The OpenTelemetry plugin exports traces and logs, not metrics. Use span
|
|
319
|
+
durations and attributes to measure latency and usage, or see
|
|
320
|
+
[AI Gateway analytics](./analytics.mdx) for built-in dashboards.
|
|
321
|
+
|
|
322
|
+
:::
|
|
134
323
|
|
|
135
324
|
## Follow an agent run across gateways
|
|
136
325
|
|
|
@@ -90,4 +90,3 @@ builds and deploys the reverted branch like any other change.
|
|
|
90
90
|
- [Environments](./environments.mdx)
|
|
91
91
|
- [Branch-Based Deployments](./branch-based-deployments.mdx)
|
|
92
92
|
- [Source Control and Deployment](../concepts/source-control-and-deployment.mdx)
|
|
93
|
-
- [Blue-Green Deployments for Your Backend](../guides/blue-green-deployments.mdx)
|
|
@@ -40,6 +40,9 @@ By default, when the OpenTelemetry plugin is enabled, the following is traced:
|
|
|
40
40
|
[MCP Gateway](../mcp-gateway/overview.mdx) handles gets a span that follows
|
|
41
41
|
the OpenTelemetry semantic conventions for MCP. See
|
|
42
42
|
[MCP tracing](#mcp-tracing).
|
|
43
|
+
- AI Gateway calls: Every call the AI Gateway makes to an LLM provider gets a
|
|
44
|
+
GenAI inference span with the model, token usage, and cost. See
|
|
45
|
+
[AI Gateway tracing](../ai-gateway/observability/tracing.mdx).
|
|
43
46
|
|
|
44
47
|
### Limitations
|
|
45
48
|
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Routing a Test Hostname to a Separate Backend
|
|
3
|
+
sidebar_label: Hostname-Based Routing
|
|
4
|
+
description:
|
|
5
|
+
Test backend releases against production data with a second Akamai hostname.
|
|
6
|
+
Akamai sets a routing header, and a Zuplo policy picks the matching backend.
|
|
7
|
+
applies_to:
|
|
8
|
+
product: gateway
|
|
9
|
+
hosting: [managed-dedicated]
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Test a new backend release against production data by sending a second public
|
|
13
|
+
hostname through the same production Zuplo gateway. Akamai tags each request
|
|
14
|
+
with a header based on the hostname, and one Zuplo policy uses that header to
|
|
15
|
+
pick the production or test backend. Your frontend and API clients change
|
|
16
|
+
nothing except the hostname they call.
|
|
17
|
+
|
|
18
|
+
## How it works
|
|
19
|
+
|
|
20
|
+
<Diagram height="h-80">
|
|
21
|
+
<DiagramNode id="prod-client">Production clients</DiagramNode>
|
|
22
|
+
<DiagramNode id="test-client">Test clients</DiagramNode>
|
|
23
|
+
<DiagramGroup id="akamai-edge" label="Akamai property">
|
|
24
|
+
<DiagramNode id="cdn" variant="blue">
|
|
25
|
+
api.example.com
|
|
26
|
+
<br />
|
|
27
|
+
api-test.example.com
|
|
28
|
+
</DiagramNode>
|
|
29
|
+
</DiagramGroup>
|
|
30
|
+
<DiagramNode id="gateway" variant="zuplo">
|
|
31
|
+
Production Zuplo gateway
|
|
32
|
+
</DiagramNode>
|
|
33
|
+
<DiagramGroup id="backends" label="Backends">
|
|
34
|
+
<DiagramNode id="prod-backend">Production backend</DiagramNode>
|
|
35
|
+
<DiagramNode id="test-backend">Test backend</DiagramNode>
|
|
36
|
+
</DiagramGroup>
|
|
37
|
+
<DiagramEdge from="prod-client" to="cdn" label="api.example.com" />
|
|
38
|
+
<DiagramEdge from="test-client" to="cdn" label="api-test.example.com" />
|
|
39
|
+
<DiagramEdge from="cdn" to="gateway" label="x-zuplo-route header" />
|
|
40
|
+
<DiagramEdge from="gateway" to="prod-backend" label="prod" />
|
|
41
|
+
<DiagramEdge from="gateway" to="test-backend" label="test" />
|
|
42
|
+
</Diagram>
|
|
43
|
+
|
|
44
|
+
Akamai turns the hostname into a header, and the gateway turns the header into a
|
|
45
|
+
backend. Everything between the client and the backend is the production path
|
|
46
|
+
for both hostnames: the same Akamai property, the same gateway deployment, and
|
|
47
|
+
the same routes, policies, and rate limits.
|
|
48
|
+
|
|
49
|
+
The examples on this page use these hostnames. Replace them with your own.
|
|
50
|
+
|
|
51
|
+
| Example hostname | Purpose |
|
|
52
|
+
| ----------------------------- | ----------------------------------------------------- |
|
|
53
|
+
| `api.example.com` | Public production hostname |
|
|
54
|
+
| `api-test.example.com` | New public test hostname, on the same Akamai property |
|
|
55
|
+
| `gateway.example.com` | Production Zuplo custom domain, the Akamai origin |
|
|
56
|
+
| `origin-api.example.com` | Production backend |
|
|
57
|
+
| `origin-api-test.example.com` | Test backend that runs the release candidate |
|
|
58
|
+
|
|
59
|
+
## Prerequisites
|
|
60
|
+
|
|
61
|
+
- An Akamai property that already forwards `api.example.com` to your production
|
|
62
|
+
Zuplo gateway. See [Setting up Akamai CDNs](./cdn.mdx).
|
|
63
|
+
- A test backend that runs the release you want to validate and can reach
|
|
64
|
+
production data.
|
|
65
|
+
- An edge certificate and DNS access for the new test hostname.
|
|
66
|
+
|
|
67
|
+
## Step 1: Set the routing header in Akamai
|
|
68
|
+
|
|
69
|
+
Both public hostnames live on the same Akamai property and use the same origin:
|
|
70
|
+
the production Zuplo custom domain. Akamai always sets `x-zuplo-route`, so it
|
|
71
|
+
overwrites any value a client sends.
|
|
72
|
+
|
|
73
|
+
In [Property Manager](https://techdocs.akamai.com/property-mgr/docs), edit the
|
|
74
|
+
property and make these changes:
|
|
75
|
+
|
|
76
|
+
1. **Default rule.** Add a
|
|
77
|
+
[Modify Outgoing Request Header](https://techdocs.akamai.com/property-mgr/docs/modify-outgoing-req-header)
|
|
78
|
+
behavior. Set the action to **Add** or **Modify**, the custom header name to
|
|
79
|
+
`x-zuplo-route`, and the value to `prod`.
|
|
80
|
+
2. **New child rule named `Test routing`.** Add a **Hostname** match for
|
|
81
|
+
`api-test.example.com`. Add a **Modify Outgoing Request Header** behavior
|
|
82
|
+
with the custom header name `x-zuplo-route` and the value `test`. Because the
|
|
83
|
+
child rule runs after the default rule, it wins for the test hostname.
|
|
84
|
+
3. **Cache key.** Make sure test and production responses can't share a cache
|
|
85
|
+
entry. Set **Cache Key Hostname** to **Incoming Host Header**, or turn off
|
|
86
|
+
caching in the `Test routing` rule.
|
|
87
|
+
4. **Hostname.** Add `api-test.example.com` to the property's hostnames with its
|
|
88
|
+
edge certificate, and create its CNAME record in your DNS.
|
|
89
|
+
|
|
90
|
+
Activate the property version. Clients that test the release only change the
|
|
91
|
+
base URL they call. They never send the header themselves.
|
|
92
|
+
|
|
93
|
+
## Step 2: Add the backend URLs in Zuplo
|
|
94
|
+
|
|
95
|
+
In the [Zuplo Portal](https://portal.zuplo.com/+/account/project/), open your
|
|
96
|
+
project and select **Settings → Environment Variables**. Add these variables to
|
|
97
|
+
the production environment. If you already have a variable for the production
|
|
98
|
+
backend, keep its name and use it in place of `BASE_URL_PROD` in the following
|
|
99
|
+
steps.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
BASE_URL_PROD=https://origin-api.example.com
|
|
103
|
+
BASE_URL_TEST=https://origin-api-test.example.com
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
You don't need a new Zuplo environment, branch, or custom domain. The production
|
|
107
|
+
deployment you run today serves both hostnames. For more on variables, see
|
|
108
|
+
[Environment variables](../../articles/environment-variables.mdx).
|
|
109
|
+
|
|
110
|
+
## Step 3: Add the routing policy
|
|
111
|
+
|
|
112
|
+
This policy follows the pattern in
|
|
113
|
+
[Canary routing for employees](../../guides/canary-routing-for-employees.mdx),
|
|
114
|
+
adapted to one signal: the `x-zuplo-route` header that Akamai sets. Any value
|
|
115
|
+
other than `test` goes to production, so a missing or unexpected value never
|
|
116
|
+
reaches the test backend. You add the policy once; it doesn't change between
|
|
117
|
+
releases.
|
|
118
|
+
|
|
119
|
+
Create `modules/test-routing.ts`:
|
|
120
|
+
|
|
121
|
+
```ts title="modules/test-routing.ts"
|
|
122
|
+
import {
|
|
123
|
+
HttpProblems,
|
|
124
|
+
ZuploContext,
|
|
125
|
+
ZuploRequest,
|
|
126
|
+
environment,
|
|
127
|
+
} from "@zuplo/runtime";
|
|
128
|
+
|
|
129
|
+
// Set by the Akamai property on every request. Never set by clients.
|
|
130
|
+
const ROUTE_HEADER = "x-zuplo-route";
|
|
131
|
+
|
|
132
|
+
export default async function testRouting(
|
|
133
|
+
request: ZuploRequest,
|
|
134
|
+
context: ZuploContext,
|
|
135
|
+
) {
|
|
136
|
+
const isTest =
|
|
137
|
+
request.headers.get(ROUTE_HEADER)?.trim().toLowerCase() === "test";
|
|
138
|
+
|
|
139
|
+
const backendUrl = isTest
|
|
140
|
+
? environment.BASE_URL_TEST
|
|
141
|
+
: environment.BASE_URL_PROD;
|
|
142
|
+
|
|
143
|
+
if (!backendUrl) {
|
|
144
|
+
context.log.error("Backend base URL is not configured", {
|
|
145
|
+
stage: isTest ? "test" : "prod",
|
|
146
|
+
});
|
|
147
|
+
return HttpProblems.internalServerError(request, context);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// The route's URL Forward handler reads this value as its baseUrl.
|
|
151
|
+
context.custom.backendUrl = backendUrl;
|
|
152
|
+
|
|
153
|
+
if (isTest) {
|
|
154
|
+
context.log.info("Routing to test backend", {
|
|
155
|
+
path: new URL(request.url).pathname,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Lets testers confirm which backend answered.
|
|
160
|
+
const stage = isTest ? "test" : "prod";
|
|
161
|
+
context.addResponseSendingHook((response) => {
|
|
162
|
+
const tagged = new Response(response.body, response);
|
|
163
|
+
tagged.headers.set("x-backend-stage", stage);
|
|
164
|
+
return tagged;
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return request;
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Register it in `config/policies.json`:
|
|
172
|
+
|
|
173
|
+
```json title="config/policies.json"
|
|
174
|
+
{
|
|
175
|
+
"name": "test-routing",
|
|
176
|
+
"policyType": "custom-code-inbound",
|
|
177
|
+
"handler": {
|
|
178
|
+
"export": "default",
|
|
179
|
+
"module": "$import(./modules/test-routing)"
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Step 4: Point each route at the chosen backend
|
|
185
|
+
|
|
186
|
+
On every route that forwards to the backend, make two changes:
|
|
187
|
+
|
|
188
|
+
1. Set the [URL Forward handler](../../handlers/url-forward.mdx) `baseUrl` to
|
|
189
|
+
`${context.custom.backendUrl}` instead of the environment variable.
|
|
190
|
+
2. Add `test-routing` to the inbound policies. Keep your existing policies. The
|
|
191
|
+
routing policy only reads a header, so its position in the list doesn't
|
|
192
|
+
matter.
|
|
193
|
+
|
|
194
|
+
```json title="config/routes.oas.json"
|
|
195
|
+
"/v1/products/{id}": {
|
|
196
|
+
"get": {
|
|
197
|
+
"x-zuplo-route": {
|
|
198
|
+
"handler": {
|
|
199
|
+
"export": "urlForwardHandler",
|
|
200
|
+
"module": "$import(@zuplo/runtime)",
|
|
201
|
+
"options": {
|
|
202
|
+
"baseUrl": "${context.custom.backendUrl}"
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
"policies": {
|
|
206
|
+
"inbound": ["<your-existing-policies>", "test-routing"]
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
If the route connects to your backend with
|
|
214
|
+
[mTLS](../../articles/securing-backend-mtls.mdx), keep the `mtlsCertificate`
|
|
215
|
+
option you use today and configure the test backend to trust the same client
|
|
216
|
+
certificate. One setting then covers both backends.
|
|
217
|
+
|
|
218
|
+
Deploy this change to production once. From then on, every route, policy, and
|
|
219
|
+
rate limit is identical for both hostnames; only the backend differs.
|
|
220
|
+
|
|
221
|
+
## Test the setup
|
|
222
|
+
|
|
223
|
+
Send these requests and check the `x-backend-stage` response header on each:
|
|
224
|
+
|
|
225
|
+
| Request | Expected `x-backend-stage` |
|
|
226
|
+
| ------------------------------------------------------------------------ | ------------------------------------ |
|
|
227
|
+
| `curl -i https://api.example.com/v1/products/1` | `prod` |
|
|
228
|
+
| `curl -i https://api-test.example.com/v1/products/1` | `test` |
|
|
229
|
+
| `curl -i https://api.example.com/v1/products/1 -H "x-zuplo-route: test"` | `prod` (Akamai overwrote the header) |
|
|
230
|
+
|
|
231
|
+
If the third request returns `test`, the default rule from Step 1 isn't setting
|
|
232
|
+
the header. Fix that before you share the test hostname.
|
|
233
|
+
|
|
234
|
+
## Release flow
|
|
235
|
+
|
|
236
|
+
A backend release doesn't require a gateway change:
|
|
237
|
+
|
|
238
|
+
1. Your CI/CD pipeline deploys the new backend version to the test backend.
|
|
239
|
+
2. Testers and test builds of your frontend call `api-test.example.com`. Their
|
|
240
|
+
requests go through the production Akamai property and the production gateway
|
|
241
|
+
and its policies, to production data.
|
|
242
|
+
3. When testing passes, promote the same build to the production backend.
|
|
243
|
+
|
|
244
|
+
Keep using your non-production Zuplo environments to test gateway changes.
|
|
245
|
+
Changing the gateway and the backend in the same test makes a failure hard to
|
|
246
|
+
place. Serving both hostnames from one gateway also means the test and
|
|
247
|
+
production paths can't drift apart, which a separate Zuplo environment for
|
|
248
|
+
testing would allow.
|
|
249
|
+
|
|
250
|
+
## Guardrails
|
|
251
|
+
|
|
252
|
+
- **Only Akamai sets the header.** If `gateway.example.com` is reachable without
|
|
253
|
+
going through Akamai, anyone could send `x-zuplo-route: test`. Restrict the
|
|
254
|
+
gateway to Akamai traffic with a shared secret header or mTLS. See
|
|
255
|
+
[Securing Zuplo from direct access](../../articles/waf-ddos-akamai.md#securing-zuplo-from-direct-access).
|
|
256
|
+
- **The test hostname uses production data.** Treat it as production: keep the
|
|
257
|
+
same authentication and rate limits, and don't publish the hostname.
|
|
258
|
+
|
|
259
|
+
## Related resources
|
|
260
|
+
|
|
261
|
+
- [Akamai architecture](./architecture.mdx)
|
|
262
|
+
- [Controlling Akamai CDN caching](./caching.mdx)
|
|
263
|
+
- [User-based backend routing](../../guides/user-based-backend-routing.mdx)
|
|
264
|
+
- [ZuploContext `addResponseSendingHook`](../../programmable-api/zuplo-context.mdx#addresponsesendinghook)
|
|
@@ -112,6 +112,5 @@ hides it from your users. See
|
|
|
112
112
|
|
|
113
113
|
## Next steps
|
|
114
114
|
|
|
115
|
-
- [Blue-Green Deployments for Your Backend](./blue-green-deployments.mdx)
|
|
116
115
|
- [Route to Different Backends Based on Geolocation](./geolocation-backend-routing.mdx)
|
|
117
116
|
- [Securing your backend](../articles/securing-your-backend.mdx)
|
|
@@ -109,6 +109,37 @@ as Entra tenant admin consent. If connections start requiring frequent
|
|
|
109
109
|
reauthorization after setting `prompt: false`, remove the option so the consent
|
|
110
110
|
grant is requested again.
|
|
111
111
|
|
|
112
|
+
## Extra Authorization Parameters
|
|
113
|
+
|
|
114
|
+
`authorizationParams` adds query parameters to the upstream authorization
|
|
115
|
+
request, for providers that need a parameter the MCP authorization flow does not
|
|
116
|
+
send. A configured value replaces any parameter of the same name. It supports
|
|
117
|
+
`user-oauth` and `shared-oauth`.
|
|
118
|
+
|
|
119
|
+
Google is the common case. Google issues a refresh token only when the
|
|
120
|
+
authorization request carries `access_type=offline`, and it does not advertise
|
|
121
|
+
the `offline_access` scope, so the MCP SDK never asks for one on its own.
|
|
122
|
+
Without it, every Google connection lasts only as long as its one-hour access
|
|
123
|
+
token and then needs a new sign-in. Set `access_type` to `offline` and `prompt`
|
|
124
|
+
to `consent`: Google returns a refresh token only on a fresh consent, so users
|
|
125
|
+
who approved the app before would otherwise still get none.
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"authMode": "user-oauth",
|
|
130
|
+
"scopes": ["https://www.googleapis.com/auth/gmail.modify"],
|
|
131
|
+
"prompt": "consent",
|
|
132
|
+
"authorizationParams": {
|
|
133
|
+
"access_type": "offline"
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`authorizationParams` cannot set parameters the gateway manages:
|
|
139
|
+
`response_type`, `response_mode`, `client_id`, `redirect_uri`, `scope`, `state`,
|
|
140
|
+
`code_challenge`, `code_challenge_method`, and `resource`. Use the `scopes`
|
|
141
|
+
option for scopes and the `prompt` option for `prompt`.
|
|
142
|
+
|
|
112
143
|
## OAuth Metadata Validation
|
|
113
144
|
|
|
114
145
|
The gateway checks OAuth metadata before connecting to an upstream. If a
|
|
@@ -197,9 +228,9 @@ Use this mode in enterprise deployments where the gateway and the upstream trust
|
|
|
197
228
|
the same identity provider (for example, Okta Cross-App Access), so upstream
|
|
198
229
|
access follows the caller's identity without a per-user upstream consent flow.
|
|
199
230
|
The `user-oauth`/`shared-oauth` options — `scopes`, `scopeDelimiter`, `prompt`,
|
|
200
|
-
`
|
|
201
|
-
`clientRegistration` — do not apply; the
|
|
202
|
-
through the `idJag` option.
|
|
231
|
+
`authorizationParams`, `skipIssuerMetadataValidation`,
|
|
232
|
+
`skipResourceIndicatorValidation`, and `clientRegistration` — do not apply; the
|
|
233
|
+
`id-jag` mode is configured entirely through the `idJag` option.
|
|
203
234
|
|
|
204
235
|
```json
|
|
205
236
|
{
|
|
@@ -56,6 +56,9 @@
|
|
|
56
56
|
{
|
|
57
57
|
"required": ["prompt"]
|
|
58
58
|
},
|
|
59
|
+
{
|
|
60
|
+
"required": ["authorizationParams"]
|
|
61
|
+
},
|
|
59
62
|
{
|
|
60
63
|
"required": ["skipIssuerMetadataValidation"]
|
|
61
64
|
},
|
|
@@ -126,6 +129,31 @@
|
|
|
126
129
|
}
|
|
127
130
|
]
|
|
128
131
|
},
|
|
132
|
+
"authorizationParams": {
|
|
133
|
+
"type": "object",
|
|
134
|
+
"x-advanced": true,
|
|
135
|
+
"description": "Extra query parameters added to upstream authorization requests, for providers that need a parameter the MCP authorization flow does not send. For example, Google issues a refresh token only when the request carries `access_type=offline`, so Google upstreams set `{ \"access_type\": \"offline\" }`, usually with `prompt: \"consent\"`. A value replaces any parameter of the same name. Parameters the gateway manages cannot be set here: `response_type`, `response_mode`, `client_id`, `redirect_uri`, `scope`, `state`, `code_challenge`, `code_challenge_method`, `resource`, and `prompt` (use the `prompt` option). Available only with `user-oauth` and `shared-oauth`.",
|
|
136
|
+
"propertyNames": {
|
|
137
|
+
"minLength": 1,
|
|
138
|
+
"not": {
|
|
139
|
+
"enum": [
|
|
140
|
+
"response_type",
|
|
141
|
+
"response_mode",
|
|
142
|
+
"client_id",
|
|
143
|
+
"redirect_uri",
|
|
144
|
+
"scope",
|
|
145
|
+
"state",
|
|
146
|
+
"code_challenge",
|
|
147
|
+
"code_challenge_method",
|
|
148
|
+
"resource",
|
|
149
|
+
"prompt"
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
"additionalProperties": {
|
|
154
|
+
"type": "string"
|
|
155
|
+
}
|
|
156
|
+
},
|
|
129
157
|
"skipIssuerMetadataValidation": {
|
|
130
158
|
"type": "boolean",
|
|
131
159
|
"x-advanced": true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zuplo",
|
|
3
|
-
"version": "7.15.
|
|
3
|
+
"version": "7.15.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The official Zuplo CLI for local development and platform management",
|
|
6
6
|
"homepage": "https://zuplo.com/docs/cli/overview",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"zuplo": "zuplo.js"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@zuplo/cli": "7.15.
|
|
36
|
-
"@zuplo/core": "7.15.
|
|
37
|
-
"@zuplo/runtime": "7.15.
|
|
38
|
-
"@zuplo/test": "7.15.
|
|
35
|
+
"@zuplo/cli": "7.15.4",
|
|
36
|
+
"@zuplo/core": "7.15.4",
|
|
37
|
+
"@zuplo/runtime": "7.15.4",
|
|
38
|
+
"@zuplo/test": "7.15.4"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Blue-Green Deployments for Your Backend
|
|
3
|
-
sidebar_label: Blue-Green Deployments
|
|
4
|
-
description:
|
|
5
|
-
Run blue and green backend stacks behind Zuplo, test the idle stack through a
|
|
6
|
-
staging gateway with the same policies, then switch traffic and roll back
|
|
7
|
-
safely.
|
|
8
|
-
tags:
|
|
9
|
-
- backends
|
|
10
|
-
- deployment
|
|
11
|
-
- testing
|
|
12
|
-
applies_to:
|
|
13
|
-
product: gateway
|
|
14
|
-
hosting: all
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
A blue-green deployment runs two copies of your backend, called blue and green.
|
|
18
|
-
One copy serves live traffic while you deploy and test the next release on the
|
|
19
|
-
other. When the new release passes its tests, you switch traffic to it, and the
|
|
20
|
-
old copy stays ready as a fallback.
|
|
21
|
-
|
|
22
|
-
This guide shows how to run a blue-green release behind a Zuplo gateway: a
|
|
23
|
-
staging gateway environment sends test traffic to the idle backend with the same
|
|
24
|
-
routes and policies as production, and production keeps serving the live backend
|
|
25
|
-
until you switch.
|
|
26
|
-
|
|
27
|
-
:::tip
|
|
28
|
-
|
|
29
|
-
Zuplo already deploys changes to the gateway itself without downtime, and you
|
|
30
|
-
can roll back to any earlier build. You don't need two gateways to change your
|
|
31
|
-
gateway safely. See
|
|
32
|
-
[Deployments and Rollbacks](../articles/deployments-and-rollbacks.mdx). This
|
|
33
|
-
guide is about releasing your backend.
|
|
34
|
-
|
|
35
|
-
:::
|
|
36
|
-
|
|
37
|
-
## How it works
|
|
38
|
-
|
|
39
|
-
Each backend copy has its own URL, for example its own load balancer or its own
|
|
40
|
-
hostname. Two Zuplo environments run the same project:
|
|
41
|
-
|
|
42
|
-
- **Production** is deployed from your default branch and forwards requests to
|
|
43
|
-
the live backend.
|
|
44
|
-
- **Staging** is a preview environment deployed from a separate branch. It
|
|
45
|
-
forwards requests to the idle backend, so you can test a release through the
|
|
46
|
-
same routes and policies that production uses.
|
|
47
|
-
|
|
48
|
-
<Diagram height="h-72">
|
|
49
|
-
<DiagramNode id="clients">API clients</DiagramNode>
|
|
50
|
-
<DiagramNode id="testers">Testers</DiagramNode>
|
|
51
|
-
<DiagramNode id="prod" variant="zuplo">
|
|
52
|
-
Production environment
|
|
53
|
-
</DiagramNode>
|
|
54
|
-
<DiagramNode id="staging" variant="zuplo">
|
|
55
|
-
Staging environment
|
|
56
|
-
</DiagramNode>
|
|
57
|
-
<DiagramNode id="blue" variant="blue">
|
|
58
|
-
Blue backend (live)
|
|
59
|
-
</DiagramNode>
|
|
60
|
-
<DiagramNode id="green" variant="green">
|
|
61
|
-
Green backend (idle)
|
|
62
|
-
</DiagramNode>
|
|
63
|
-
<DiagramEdge from="clients" to="prod" />
|
|
64
|
-
<DiagramEdge from="testers" to="staging" />
|
|
65
|
-
<DiagramEdge from="prod" to="blue" label="BACKEND_URL" />
|
|
66
|
-
<DiagramEdge from="staging" to="green" label="BACKEND_URL" />
|
|
67
|
-
</Diagram>
|
|
68
|
-
|
|
69
|
-
## Prerequisites
|
|
70
|
-
|
|
71
|
-
- A Zuplo project connected to [source control](../articles/source-control.mdx),
|
|
72
|
-
so that branches deploy as environments
|
|
73
|
-
- Two copies of your backend, each reachable at its own URL
|
|
74
|
-
|
|
75
|
-
## 1/ Read the backend URL from an environment variable
|
|
76
|
-
|
|
77
|
-
Set each route's backend URL from an
|
|
78
|
-
[environment variable](../articles/environment-variables.mdx), so the production
|
|
79
|
-
and staging environments can forward to different backends with the same code.
|
|
80
|
-
With the [URL Forward handler](../handlers/url-forward.mdx):
|
|
81
|
-
|
|
82
|
-
```json title="config/routes.oas.json"
|
|
83
|
-
{
|
|
84
|
-
"handler": {
|
|
85
|
-
"export": "urlForwardHandler",
|
|
86
|
-
"module": "$import(@zuplo/runtime)",
|
|
87
|
-
"options": {
|
|
88
|
-
"baseUrl": "${env.BACKEND_URL}"
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
In the Zuplo Portal, open
|
|
95
|
-
[**Settings**](https://portal.zuplo.com/+/account/project/settings/general) and
|
|
96
|
-
select **Environment Variables**. Add `BACKEND_URL` for the **Production**
|
|
97
|
-
environment, set to the URL of the live backend, for example
|
|
98
|
-
`https://blue.api.example.com`.
|
|
99
|
-
|
|
100
|
-
## 2/ Create the staging environment
|
|
101
|
-
|
|
102
|
-
Create a branch, for example `staging`, and push it. Zuplo deploys it as a
|
|
103
|
-
preview environment with its own URL. See
|
|
104
|
-
[Branch-Based Deployments](../articles/branch-based-deployments.mdx).
|
|
105
|
-
|
|
106
|
-
Then set up the staging environment:
|
|
107
|
-
|
|
108
|
-
- **Backend URL:** add `BACKEND_URL` for the `staging` preview environment, set
|
|
109
|
-
to the idle backend, for example `https://green.api.example.com`. A variable
|
|
110
|
-
can apply to one named preview environment, so it doesn't affect other
|
|
111
|
-
branches.
|
|
112
|
-
- **Secrets:** give every secret your policies read, such as a shared secret
|
|
113
|
-
from your CDN, a value for the staging environment.
|
|
114
|
-
- **API keys:** preview environments use a separate
|
|
115
|
-
[API key bucket](../articles/api-key-buckets.mdx) from production, so
|
|
116
|
-
production keys don't work there. Create test consumers in the preview bucket,
|
|
117
|
-
or see
|
|
118
|
-
[Custom bucket configuration](../articles/api-key-buckets.mdx#custom-bucket-configuration).
|
|
119
|
-
- **mTLS client certificates:** if your backend requires a
|
|
120
|
-
[client certificate](../articles/securing-backend-mtls.mdx), enable the
|
|
121
|
-
certificate for the preview environment type.
|
|
122
|
-
- **Custom domain (optional):** give the staging environment its own hostname,
|
|
123
|
-
such as `staging-api.example.com`. See
|
|
124
|
-
[Custom Domains](../articles/custom-domains.mdx).
|
|
125
|
-
|
|
126
|
-
Redeploy the staging environment after you change its variables, because
|
|
127
|
-
variable changes take effect on the next deployment.
|
|
128
|
-
|
|
129
|
-
## 3/ Release a new backend version
|
|
130
|
-
|
|
131
|
-
1. Deploy the new version of your backend to the idle copy (green).
|
|
132
|
-
2. Test it through the staging environment's URL. Requests pass through the same
|
|
133
|
-
routes and policies as production, so the test covers authentication, rate
|
|
134
|
-
limits, and request validation, not only the backend.
|
|
135
|
-
3. When the release passes, switch production traffic to green (see the next
|
|
136
|
-
section).
|
|
137
|
-
4. Point the staging environment at the copy that's now idle (blue), ready for
|
|
138
|
-
the next release.
|
|
139
|
-
|
|
140
|
-
## 4/ Switch production traffic
|
|
141
|
-
|
|
142
|
-
Choose where the switch happens:
|
|
143
|
-
|
|
144
|
-
| Switch at | How | Zuplo deployment needed |
|
|
145
|
-
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
|
|
146
|
-
| Your load balancer or DNS | Point the hostname that production's `BACKEND_URL` uses at green, for example by changing a load balancer rule or DNS record | No |
|
|
147
|
-
| The production `BACKEND_URL` | Change the variable to green's URL, then redeploy the production environment | Yes |
|
|
148
|
-
|
|
149
|
-
Switching at the load balancer is the fastest option, in both directions,
|
|
150
|
-
because it doesn't wait for a gateway deployment. Changing `BACKEND_URL` keeps
|
|
151
|
-
the switch in Zuplo, and the redeploy rolls out without downtime.
|
|
152
|
-
|
|
153
|
-
## Roll back
|
|
154
|
-
|
|
155
|
-
Switch back the same way you switched forward. Blue is still running the
|
|
156
|
-
previous release, so rolling back only changes where traffic goes:
|
|
157
|
-
|
|
158
|
-
- If you switched at the load balancer or DNS, point it back at blue.
|
|
159
|
-
- If you switched with `BACKEND_URL`, set it back to blue's URL and redeploy
|
|
160
|
-
production.
|
|
161
|
-
|
|
162
|
-
:::caution
|
|
163
|
-
|
|
164
|
-
Redeploying an earlier build of the production environment doesn't restore an
|
|
165
|
-
earlier value of `BACKEND_URL`, because a redeploy uses current settings. Change
|
|
166
|
-
the variable itself to roll back a `BACKEND_URL` switch.
|
|
167
|
-
|
|
168
|
-
:::
|
|
169
|
-
|
|
170
|
-
## Test through production instead of a staging environment
|
|
171
|
-
|
|
172
|
-
If the gateway configuration doesn't change between releases, testers can reach
|
|
173
|
-
the idle backend through the production environment itself. A routing policy
|
|
174
|
-
sends requests with a header such as `x-stage: canary`, or from users on an
|
|
175
|
-
allow list, to the idle backend, and everyone else to the live one. You don't
|
|
176
|
-
need a staging environment or a second hostname. The trade-off is that both
|
|
177
|
-
backends share one gateway deployment. See
|
|
178
|
-
[Route Employees to Canary or Staging Backends](./canary-routing-for-employees.mdx).
|
|
179
|
-
|
|
180
|
-
## When to run blue and green gateway environments
|
|
181
|
-
|
|
182
|
-
Most releases only need the pattern above. If a release also changes the gateway
|
|
183
|
-
configuration in a risky way, such as new authentication policies, you can run
|
|
184
|
-
two long-lived environments from `blue` and `green` branches and switch traffic
|
|
185
|
-
in front of Zuplo, for example by changing your CDN's origin.
|
|
186
|
-
|
|
187
|
-
Both environments are preview environments, which serve traffic the same way as
|
|
188
|
-
production. Production-scoped settings don't apply to them, so set their
|
|
189
|
-
[environment variables](../articles/environment-variables.mdx) for each named
|
|
190
|
-
environment and choose which [API key bucket](../articles/api-key-buckets.mdx)
|
|
191
|
-
they use. See
|
|
192
|
-
[Preview vs Production Environments](../articles/environments.mdx#preview-vs-production-environments-or-multiple-production-environments).
|
|
193
|
-
|
|
194
|
-
## Next steps
|
|
195
|
-
|
|
196
|
-
- [Deployments and Rollbacks](../articles/deployments-and-rollbacks.mdx)
|
|
197
|
-
- [Testing Preview Environments](../articles/testing-preview-environments.mdx)
|
|
198
|
-
- [Fail Over Between Backends](./backend-failover.mdx)
|
|
199
|
-
- [Connect to an AWS ALB with mTLS](../articles/connect-to-aws-alb-with-mtls.mdx)
|