Skip to content

Commit 656ba73

Browse files
♻️ refactor new datacenter workflow (#3964)
1 parent 6a74797 commit 656ba73

File tree

8 files changed

+71
-40
lines changed

8 files changed

+71
-40
lines changed

.gitlab/deploy-auto.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ stages:
1717
- VERSION=$(node -p -e "require('./lerna.json').version")
1818
- yarn
1919
- yarn build:bundle
20-
- node ./scripts/deploy/deploy-prod-dc.ts v${VERSION%%.*} $UPLOAD_PATH true
20+
- node ./scripts/deploy/deploy-prod-dc.ts v${VERSION%%.*} $UPLOAD_PATH --check-monitors
2121

2222
step-1_deploy-prod-minor-dcs:
2323
when: manual
@@ -26,7 +26,7 @@ step-1_deploy-prod-minor-dcs:
2626
- .base-configuration
2727
- .deploy-prod
2828
variables:
29-
UPLOAD_PATH: us3,us5,ap1,ap2
29+
UPLOAD_PATH: minor-dcs
3030

3131
step-2_deploy-prod-eu1:
3232
needs:

.gitlab/deploy-manual.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ stages:
1919
- VERSION=$(node -p -e "require('./lerna.json').version")
2020
- yarn
2121
- yarn build:bundle
22-
- node ./scripts/deploy/deploy-prod-dc.ts v${VERSION%%.*} $UPLOAD_PATH false
22+
- node ./scripts/deploy/deploy-prod-dc.ts v${VERSION%%.*} $UPLOAD_PATH --no-check-monitors
2323

2424
step-1_deploy-prod-minor-dcs:
2525
extends:
2626
- .base-configuration
2727
- .deploy-prod
2828
variables:
29-
UPLOAD_PATH: us3,us5,ap1,ap2
29+
UPLOAD_PATH: minor-dcs
3030

3131
step-2_deploy-prod-eu1:
3232
extends:
@@ -79,6 +79,13 @@ step-7_create-github-release:
7979
- yarn
8080
- node scripts/release/create-github-release.ts
8181

82+
# This step is used to deploy the SDK to a new datacenter.
83+
# the `UPLOAD_PATH` variable needs to be provided as an argument when starting the manual job
84+
optional_step-deploy-to-new-datacenter:
85+
extends:
86+
- .base-configuration
87+
- .deploy-prod
88+
8289
########################################################################################################################
8390
# Notify
8491
########################################################################################################################

scripts/deploy/check-monitors.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,15 @@
55
*/
66
import { printLog, runMain, fetchHandlingError } from '../lib/executionUtils.ts'
77
import { getTelemetryOrgApiKey, getTelemetryOrgApplicationKey } from '../lib/secrets.ts'
8-
import { siteByDatacenter } from '../lib/datadogSites.ts'
9-
10-
interface MonitorsByDatacenter {
11-
[datacenter: string]: number[]
12-
}
13-
14-
const monitorIdsByDatacenter: MonitorsByDatacenter = {
15-
us1: [72055549, 68975047, 110519972],
16-
eu1: [5855803, 5663834, 9896387],
17-
us3: [164368, 160677, 329066],
18-
us5: [22388, 20646, 96049],
19-
ap1: [858, 859, 2757030],
20-
ap2: [1234, 1235, 1236],
21-
}
22-
23-
type Datacenter = keyof typeof siteByDatacenter
8+
import { monitorIdsByDatacenter, siteByDatacenter } from '../lib/datacenter.ts'
249

2510
interface MonitorStatus {
2611
id: number
2712
name: string
2813
overall_state: string
2914
}
3015

31-
const datacenters = process.argv[2].split(',') as Datacenter[]
16+
const datacenters = process.argv[2].split(',')
3217

3318
runMain(async () => {
3419
for (const datacenter of datacenters) {

scripts/deploy/deploy-prod-dc.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { parseArgs } from 'node:util'
12
import { printLog, runMain, timeout } from '../lib/executionUtils.ts'
23
import { command } from '../lib/command.ts'
4+
import { siteByDatacenter } from '../lib/datacenter.ts'
35

46
/**
57
* Orchestrate the deployments of the artifacts for specific DCs
@@ -10,19 +12,35 @@ const ONE_MINUTE_IN_SECOND = 60
1012
const GATE_DURATION = 30 * ONE_MINUTE_IN_SECOND
1113
const GATE_INTERVAL = ONE_MINUTE_IN_SECOND
1214

13-
const version: string = process.argv[2]
14-
const uploadPath: string = process.argv[3]
15-
const withMonitorChecks: boolean = process.argv[4] === 'true'
15+
const {
16+
values: { 'check-monitors': checkMonitors },
17+
positionals,
18+
} = parseArgs({
19+
allowPositionals: true,
20+
allowNegative: true,
21+
options: {
22+
'check-monitors': {
23+
type: 'boolean',
24+
},
25+
},
26+
})
27+
28+
const version = positionals[0]
29+
const uploadPath = positionals[1] === 'minor-dcs' ? getAllMinorDcs().join(',') : positionals[1]
30+
31+
if (!uploadPath) {
32+
throw new Error('UPLOAD_PATH argument is required')
33+
}
1634

1735
runMain(async () => {
18-
if (withMonitorChecks) {
36+
if (checkMonitors) {
1937
command`node ./scripts/deploy/check-monitors.ts ${uploadPath}`.withLogs().run()
2038
}
2139

2240
command`node ./scripts/deploy/deploy.ts prod ${version} ${uploadPath}`.withLogs().run()
2341
command`node ./scripts/deploy/upload-source-maps.ts ${version} ${uploadPath}`.withLogs().run()
2442

25-
if (withMonitorChecks && uploadPath !== 'root') {
43+
if (checkMonitors && uploadPath !== 'root') {
2644
await gateMonitors(uploadPath)
2745
}
2846
})
@@ -36,3 +54,12 @@ async function gateMonitors(uploadPath: string): Promise<void> {
3654
}
3755
printLog() // new line
3856
}
57+
58+
// Major DCs are the ones that are deployed last.
59+
// They have their own step jobs in `deploy-manual.yml` and `deploy-auto.yml`.
60+
const MAJOR_DCS = ['root', 'us1', 'eu1']
61+
62+
// Minor DCs are all the DCs from `siteByDatacenter` that are not in `MAJOR_DCS`.
63+
function getAllMinorDcs(): string[] {
64+
return Object.keys(siteByDatacenter).filter((dc) => !MAJOR_DCS.includes(dc))
65+
}

scripts/deploy/upload-source-maps.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from 'node:assert/strict'
22
import path from 'node:path'
33
import { beforeEach, before, describe, it, mock } from 'node:test'
4-
import { siteByDatacenter } from '../lib/datadogSites.ts'
4+
import { siteByDatacenter } from '../lib/datacenter.ts'
55
import { mockModule, mockCommandImplementation, replaceChunkHashes } from './lib/testHelpers.ts'
66

77
const FAKE_API_KEY = 'FAKE_API_KEY'

scripts/deploy/upload-source-maps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { printLog, runMain } from '../lib/executionUtils.ts'
33
import { command } from '../lib/command.ts'
44
import { getBuildEnvValue } from '../lib/buildEnv.ts'
55
import { getTelemetryOrgApiKey } from '../lib/secrets.ts'
6-
import { siteByDatacenter } from '../lib/datadogSites.ts'
6+
import { siteByDatacenter } from '../lib/datacenter.ts'
77
import { forEachFile } from '../lib/filesUtils.ts'
88
import { buildRootUploadPath, buildDatacenterUploadPath, buildBundleFolder, packages } from './lib/deploymentUtils.ts'
99

scripts/lib/datacenter.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const siteByDatacenter: Record<string, string> = {
2+
us1: 'datadoghq.com',
3+
eu1: 'datadoghq.eu',
4+
us3: 'us3.datadoghq.com',
5+
us5: 'us5.datadoghq.com',
6+
ap1: 'ap1.datadoghq.com',
7+
ap2: 'ap2.datadoghq.com',
8+
pr00test: 'pr00test.staging.dog',
9+
}
10+
11+
/**
12+
* Each datacenter has 3 monitor IDs:
13+
* - Telemetry errors
14+
* - Telemetry errors on specific org
15+
* - Telemetry errors on specific message
16+
*/
17+
export const monitorIdsByDatacenter: Record<string, [number, number, number]> = {
18+
us1: [72055549, 68975047, 110519972],
19+
eu1: [5855803, 5663834, 9896387],
20+
us3: [164368, 160677, 329066],
21+
us5: [22388, 20646, 96049],
22+
ap1: [858, 859, 2757030],
23+
ap2: [1234, 1235, 1236],
24+
}

scripts/lib/datadogSites.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)