Skip to content

Commit 40cce4a

Browse files
first commit
1 parent efb8166 commit 40cce4a

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

site/content/guides/canary-deploys.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ One final note, canary deployments are sometimes called blue-green deployments,
2020

2121
Our site, is releasing major new features and we're running a canary deployment to make sure everything's working. Visitors to the site are randomly assigned to a canary group, and receive an additional header on their page requests that activates the new features. Essentially our canary deploy is setting this feature flag to 'true' for a number of users.
2222

23-
We're already monitoring the site with Checkly's browser and API synthetics monitors, and using uptime monitoring to make sure that every URL is available. If we change nothing about our Checkly configuration, some check runs will be randomly assigned to the canary group, and the rest will run with the same set of features as most visitors. We'd like to enhance this experience during our canary deployment. Here are the requirements:
23+
We're already monitoring the site with Checkly's browser and API synthetics monitors, and using uptime monitoring to make sure that every URL is available. If we change nothing about our Checkly configuration, some check runs will be randomly assigned to the canary group, and the rest will run with the same set of features as most visitors. We'd like to enhance this experience during our canary deployment. Here are three use cases to better support canary deployments:
2424

25-
* For better reliability, we want active control whether a check runs as a user that can see the canary deployment.
25+
* For better reliability, we want active control over whether a check runs as a user that can see the canary deployment.
2626

2727
* Our engineers want to integrate our Checkly monitors into their deploy process, letting us roll back deployments if monitors fail.
2828

29-
* For some checks, we want a version that reports separate data for just this canary deployment, with a chart on our Checkly dashboard showing how checks in the canary group are performing.
29+
* For some checks, we want a version that reports separate data for just this canary deployment, with a chart on our Checkly web UI showing how checks in the canary group are performing.
3030

3131
At Checkly, we're on a mission to empower developers, making it easier to detect, communicate, and resolve problems before they affect users.
3232

3333
These improvements will help us better **detect** problems with our canary deployment, with clearer ways to **communicate** the results of checks and their context to our team. With clear results information, our team can **resolve** issues faster, making every canary deployment a smoother experience for engineers and users.
3434

3535
## 1. Set Feature Flags With Headers & User Agents
3636

37-
In our scenario, we can control whether we get the canary version of our service with a feature flag. By control a request's headers, we can set the user agent or add arbitrary header values to our requests. Let's set some headers in an API check, a browser check, and a more complex Multistep API check.
37+
In our scenario, we can control whether we get the canary version of our service with a feature flag. By control a request's headers, we can set the user agent or add arbitrary header values to our requests. Let's set some headers in an API check, a Browser check, and a more complex Multistep API check.
3838

3939
### A. Set Headers for an API Check
4040
When running API checks, headers are part of your configuration. You can add [HTTP headers](https://www.checklyhq.com/docs/api-checks/request-settings/#headers) in the Checkly web UI when setting up your API checks, but since we developers prefer to use monitoring as code, here's how to control API checks' headers right from your IDE. API checks are created as a [Checkly construct](https://www.checklyhq.com/docs/cli/constructs-reference/#apicheck), and we can create a new one by creating a new file in our Checkly Project (if you haven't set up a Checkly Project or used monitoring as code before, check out our [getting started tutorial](https://www.checklyhq.com/guides/startup-guide-detect-communiate-resolve/) before returning here to start modifying headers):
@@ -72,7 +72,7 @@ Since headers are part of the basic configuration of your check, you can populat
7272

7373
### B. Set Headers in a Browser Check
7474

75-
Headers for request are not part of the basic configuration of browser checks. In part because an automated browser will make many checks as part of a single run, and it wouldn't be clear exactly which requests should have an additional header. It's quite easy to add headers to some or all requests from a check written in playwright, with a specialized version of [request interception](https://www.checklyhq.com/learn/playwright/intercept-requests/). In this example we only want to modify requests for SVG files with our new header:
75+
Headers for request are not part of the basic configuration of Browser checks. In part because an automated browser will make many checks as part of a single run, and it wouldn't be clear exactly which requests should have an additional header. It's quite easy to add headers to some or all requests from a check written in playwright, with a specialized version of [request interception](https://www.checklyhq.com/learn/playwright/intercept-requests/). In this example we only want to modify requests for SVG files with our new header:
7676

7777
```ts {title="book-listing-canary.spec.ts"}
7878
import { test, expect } from '@playwright/test'
@@ -100,7 +100,7 @@ The example above filters for all requests with a route ending in `.svg` but you
100100
101101

102102
### C. Set Headers in a Multistep API Check
103-
A multistep check uses Playwright scripting to perform a series of API requests with more complex evaluation of the response. Since we're only making API requests, we can feed in new headers as a property.
103+
A Multistep check uses Playwright scripting to perform a series of API requests with more complex evaluation of the response. Since we're only making API requests, we can feed in new headers as a property.
104104

105105
In this example we are making a pair of sequential API checks, the second test step relying on the results of the first step. Both requests use our header settings.
106106

@@ -172,13 +172,13 @@ At the unique link provided we can see all our check runs succeeded.
172172

173173
![a checkly one-off report](/guides/images/canary-deploy-01.png)
174174

175-
And you can click on each to view the report on the check run. Our browser check will show a full trace, and we can look at our request headers on the network tab:
175+
And you can click on each to view the report on the check run. Our Browser check will show a full trace, and we can look at our request headers on the network tab:
176176

177177
![a checkly one-off report](/guides/images/canary-deploy-02.png)
178178

179179
For both API monitors and Multistep Monitors, the headers on request and response are listed in the Checkly web UI
180180

181-
![a checkly one-off report](/guides/images/canary-deploy-02.png)
181+
![a checkly one-off report](/guides/images/canary-deploy-03.png)
182182

183183
## 2. Integrate Check Runs With CI/CD - Deploy After a Succesful Check Run
184184

@@ -256,4 +256,32 @@ test.describe('Danube WebShop Book Listing', () => {
256256
})
257257
```
258258

259-
Now we can run this same monitor against both our main line production environments and our canary deployments, with its behavior determined by environment variables.
259+
Now we can run this same monitor against both our Production environments and our canary deployments, with its behavior determined by environment variables.
260+
261+
For our API checks and other monitors that don't run Playwright, we can only control their behavior by setting environment variables at the group level, and we can't follow a 'multi-pathed' approach like we do above in our Browser check. The next section will cover using Groups to set environment variables in more detail.
262+
263+
### 3. Generate Canary Deployment Data With a Separate Check Group
264+
265+
If we can run a set of Checks such that they always 'see' the version of our service in a canary deployment, it would be nice to generate data for just that deployment. To create separate data in our Checkly web UI, and to manage the environment variables of these checks all at once, we can use a [Checkly Group](https://www.checklyhq.com/docs/groups/).
266+
267+
We'll start by defining our Group, and setting some default values for checks in that group:
268+
269+
```ts
270+
export const syntheticGroup = new CheckGroupV2('check-group-synthetics', {
271+
name: 'Synthetic Monitors Group',
272+
activated: true,
273+
muted: false,
274+
frequency: Frequency.EVERY_15M,
275+
locations: ['us-east-1', 'eu-west-1'],
276+
tags: ['synthetics'],
277+
// By setting an alertEscalationPolicy, these settings will override those on individual checks
278+
alertEscalationPolicy: AlertEscalationBuilder.runBasedEscalation(
279+
2, // Alert after 2 consecutive failures
280+
{ amount: 2, interval: 5 }, // Send 2 reminders, 5 minutes apart
281+
{ enabled: true, percentage: 50 } // Alert if 50% of parallel runs fail
282+
),
283+
alertChannels: [emailChannel, smsChannel],
284+
environmentVariables: [{ key: 'authorName', value: 'Fric Eromm' }],
285+
concurrency: 10
286+
})
287+
```

0 commit comments

Comments
 (0)