Skip to content

Commit 739ded9

Browse files
committed
feat: validate that monitors are configured for single retry only
1 parent cdb225f commit 739ded9

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

packages/cli/src/constructs/monitor.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ import { CheckGroupV2 } from './check-group-v2'
77
import { Frequency } from './frequency'
88
import { IncidentTrigger } from './incident'
99
import { PrivateLocation, PrivateLocationRef } from './private-location'
10-
import { RetryStrategy } from './retry-strategy'
10+
import { RetryStrategyType, SingleRetryStrategy } from './retry-strategy'
1111
import { Check, CheckProps } from './check'
1212
import { Diagnostics } from './diagnostics'
1313
import { validateRemovedDoubleCheck } from './internal/common-diagnostics'
14+
import { InvalidPropertyValueDiagnostic } from './construct-diagnostics'
15+
16+
/**
17+
* Retry strategies supported by monitors.
18+
*/
19+
export type MonitorRetryStrategy = SingleRetryStrategy
1420

1521
export interface MonitorProps extends Omit<CheckProps, 'doubleCheck'> {
1622
/**
@@ -74,8 +80,19 @@ export interface MonitorProps extends Omit<CheckProps, 'doubleCheck'> {
7480
/**
7581
* Sets a retry policy for the monitor. Use RetryStrategyBuilder to create a
7682
* suitable retry strategy.
83+
*
84+
* Note that monitors only support a single retry.
85+
*
86+
* @example
87+
* ```typescript
88+
* // Single retry
89+
* RetryStrategyBuilder.singleRetry()
90+
*
91+
* // No retries
92+
* RetryStrategyBuilder.noRetries()
93+
* ```
7794
*/
78-
retryStrategy?: RetryStrategy
95+
retryStrategy?: MonitorRetryStrategy
7996
/**
8097
* Determines whether the monitor should create and resolve an incident
8198
* based on its alert configuration.
@@ -95,6 +112,29 @@ export abstract class Monitor extends Check {
95112
await validateRemovedDoubleCheck(diagnostics, this)
96113
}
97114

115+
async validate (diagnostics: Diagnostics): Promise<void> {
116+
await super.validate(diagnostics)
117+
118+
if (this.retryStrategy) {
119+
const supported: RetryStrategyType[] = ['SINGLE', 'NO_RETRIES']
120+
if (!supported.includes(this.retryStrategy.type)) {
121+
diagnostics.add(new InvalidPropertyValueDiagnostic(
122+
'retryStrategy',
123+
new Error(
124+
`Monitors only support a single retry. The following options `
125+
+ `are available:`
126+
+ `\n\n`
127+
+ ` // Single retry\n`
128+
+ ` RetryStrategyBuilder.singleRetry()`
129+
+ `\n\n`
130+
+ ` // No retries\n`
131+
+ ` RetryStrategyBuilder.noRetries()`,
132+
),
133+
))
134+
}
135+
}
136+
}
137+
98138
synthesize () {
99139
return {
100140
...super.synthesize(),

packages/cli/src/constructs/retry-strategy.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** Available retry strategy types */
2-
export type RetryStrategyType = 'LINEAR' | 'EXPONENTIAL' | 'FIXED' | 'NO_RETRIES'
2+
export type RetryStrategyType = 'LINEAR' | 'EXPONENTIAL' | 'FIXED' | 'SINGLE' | 'NO_RETRIES'
33

44
/**
55
* Conditions can be used to limit when a retry strategy applies.
@@ -20,6 +20,7 @@ export interface RetryStrategy {
2020
* - FIXED: Same delay for all retries
2121
* - LINEAR: Base value that increases linearly (baseBackoffSeconds * attempt)
2222
* - EXPONENTIAL: Base value that increases exponentially (baseBackoffSeconds ^ attempt)
23+
* - SINGLE: The delay for the first and only retry
2324
*
2425
* @defaultValue 60
2526
* @example
@@ -32,6 +33,9 @@ export interface RetryStrategy {
3233
*
3334
* // Exponential: 5s, 25s, 125s
3435
* baseBackoffSeconds: 5
36+
*
37+
* // Single: 10s
38+
* baseBackoffSeconds: 10
3539
* ```
3640
*/
3741
baseBackoffSeconds?: number
@@ -78,6 +82,18 @@ export interface RetryStrategy {
7882
*/
7983
export type RetryStrategyOptions = Omit<RetryStrategy, 'type'>
8084

85+
/**
86+
* Configuration for single retry behavior.
87+
*/
88+
export interface SingleRetryStrategy extends Pick<RetryStrategy, 'baseBackoffSeconds' | 'sameRegion'> {
89+
type: 'SINGLE'
90+
}
91+
92+
/**
93+
* Options for configuring single retry strategy behavior.
94+
*/
95+
export type SingleRetryStrategyOptions = Pick<RetryStrategyOptions, 'baseBackoffSeconds' | 'sameRegion'>
96+
8197
/**
8298
* Builder class for creating retry strategies.
8399
* Provides convenient methods to create different types of retry strategies.
@@ -152,6 +168,16 @@ export class RetryStrategyBuilder {
152168
return RetryStrategyBuilder.retryStrategy('EXPONENTIAL', options)
153169
}
154170

171+
/**
172+
* A single retry will be performed.
173+
*/
174+
static singleRetry (options?: SingleRetryStrategyOptions): RetryStrategy {
175+
return RetryStrategyBuilder.retryStrategy('SINGLE', {
176+
baseBackoffSeconds: options?.baseBackoffSeconds,
177+
sameRegion: options?.sameRegion,
178+
})
179+
}
180+
155181
/**
156182
* No retries are performed.
157183
*/

0 commit comments

Comments
 (0)