-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcheck-group-v2.ts
More file actions
168 lines (152 loc) · 5.36 KB
/
check-group-v2.ts
File metadata and controls
168 lines (152 loc) · 5.36 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
import { PrivateLocation, PrivateLocationRef } from './private-location'
import type { Region } from '..'
import {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type RetryStrategyBuilder, // Used for @links in comments.
} from './retry-strategy'
import {
AlertEscalation,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type AlertEscalationBuilder, // Used for @links in comments.
} from './alert-escalation-policy'
import { Diagnostics } from './diagnostics'
import { CheckGroupV1, CheckGroupV1Props, GroupRetryStrategy } from './check-group-v1'
import { validateRemovedDoubleCheck } from './internal/common-diagnostics'
export interface CheckGroupV2Props extends Omit<CheckGroupV1Props, 'alertEscalationPolicy'> {
/**
* This property is no longer supported; use {@link retryStrategy} instead.
*
* To match the behavior of `doubleCheck: true`, use:
*
* retryStrategy: RetryStrategyBuilder.fixedStrategy({
* maxRetries: 1,
* baseBackoffSeconds: 0,
* maxDurationSeconds: 600,
* sameRegion: false,
* })
*
* To match the behavior of `doubleCheck: false`, use:
*
* retryStrategy: RetryStrategyBuilder.noRetries()
*
* @deprecated Use {@link CheckGroupV2Props.retryStrategy} instead.
*/
doubleCheck?: boolean
/**
* An array of one or more data center locations where to run the checks.
*
* If either {@link CheckGroupV2Props.locations} or
* {@link CheckGroupV2Props.privateLocations} is set to a non-empty value, all
* checks in the group will use those values instead of their own.
*/
locations?: (keyof Region)[]
/**
* An array of one or more private locations where to run the checks.
*
* If either {@link CheckGroupV2Props.locations} or
* {@link CheckGroupV2Props.privateLocations} is set to a non-empty value, all
* checks in the group will use those values instead of their own.
*/
privateLocations?: (string | PrivateLocation | PrivateLocationRef)[]
/**
* When {@link AlertEscalation}, all checks in the group will use the
* group's alert escalation policy. Use {@link AlertEscalationBuilder} to
* build a suitable policy.
*
* When `"global"`, all checks in the group will use the global alert
* escalation policy.
*
* If not set, individual check settings are used.
*/
alertEscalationPolicy?: AlertEscalation | 'global'
/**
* Sets a retry policy for the group. Use {@link RetryStrategyBuilder} to
* create a retry policy.
*
* If set, all checks in the group use the group's retry strategy.
*
* If not set, individual check settings are used.
*/
retryStrategy?: GroupRetryStrategy
/**
* Determines whether the checks in the group should run on all selected
* locations in parallel or round-robin.
*
* When `true`, all checks in the group run in parallel regardless of their
* individual setting.
*
* When `false`, all checks in the group run in round-robin regardless of
* their individual setting.
*
* If not set, individual check settings are used.
*
* See https://www.checklyhq.com/docs/concepts/locations/ to learn
* more about scheduling strategies.
*/
runParallel?: boolean
}
/**
* Creates a Check Group (v2).
*
* The following properties have changed since CheckGroupV1:
*
* - {@link CheckGroupV2Props.alertEscalationPolicy}
* - The implicit default for this property has been removed, allowing
* individual check settings to take effect.
* - Can be set to `"global"` to match the earlier default behavior.
* - {@link CheckGroupV2Props.retryStrategy}
* - The implicit default for this property has been removed, allowing
* individual check settings to take effect.
* - {@link CheckGroupV2Props.runParallel}
* - The implicit default for this property has been removed, allowing
* individual check settings to take effect.
*/
export class CheckGroupV2 extends CheckGroupV1 {
constructor (logicalId: string, props: CheckGroupV2Props) {
const { alertEscalationPolicy, useGlobalAlertSettings } = (() => {
const { alertEscalationPolicy } = props
// Do we want to always use the global policy?
if (alertEscalationPolicy === 'global') {
return {
alertEscalationPolicy: undefined,
useGlobalAlertSettings: true,
}
}
// Do we want to let checks keep their own policies?
if (alertEscalationPolicy === undefined) {
return {
alertEscalationPolicy,
useGlobalAlertSettings: undefined,
}
}
// The group policy will always apply.
return {
alertEscalationPolicy,
useGlobalAlertSettings: false,
}
})()
super(logicalId, {
...props,
alertEscalationPolicy,
})
// Must override; the V1 constructor will not give us the desired behavior.
this.useGlobalAlertSettings = useGlobalAlertSettings
}
describe (): string {
return `CheckGroupV2:${this.logicalId}`
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async onBeforeValidate (diagnostics: Diagnostics): Promise<void> {
// No-op
}
protected async validateDoubleCheck (diagnostics: Diagnostics): Promise<void> {
await validateRemovedDoubleCheck(diagnostics, this)
}
synthesize () {
return {
...super.synthesize(),
doubleCheck: undefined,
v: 2,
}
}
}