Skip to content

Commit 31a28bc

Browse files
committed
feat: validate that monitors are configured for single retry only
1 parent b306941 commit 31a28bc

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
* Configuration for check retry behavior.
@@ -15,6 +15,7 @@ export interface RetryStrategy {
1515
* - FIXED: Same delay for all retries
1616
* - LINEAR: Base value that increases linearly (baseBackoffSeconds * attempt)
1717
* - EXPONENTIAL: Base value that increases exponentially (baseBackoffSeconds ^ attempt)
18+
* - SINGLE: The delay for the first and only retry
1819
*
1920
* @defaultValue 60
2021
* @example
@@ -27,6 +28,9 @@ export interface RetryStrategy {
2728
*
2829
* // Exponential: 5s, 25s, 125s
2930
* baseBackoffSeconds: 5
31+
*
32+
* // Single: 10s
33+
* baseBackoffSeconds: 10
3034
* ```
3135
*/
3236
baseBackoffSeconds?: number,
@@ -63,6 +67,18 @@ export interface RetryStrategy {
6367
*/
6468
export type RetryStrategyOptions = Pick<RetryStrategy, 'baseBackoffSeconds' | 'maxRetries' | 'maxDurationSeconds' | 'sameRegion'>
6569

70+
/**
71+
* Configuration for single retry behavior.
72+
*/
73+
export interface SingleRetryStrategy extends Pick<RetryStrategy, 'baseBackoffSeconds' | 'sameRegion'> {
74+
type: 'SINGLE'
75+
}
76+
77+
/**
78+
* Options for configuring single retry strategy behavior.
79+
*/
80+
export type SingleRetryStrategyOptions = Pick<RetryStrategyOptions, 'baseBackoffSeconds' | 'sameRegion'>
81+
6682
/**
6783
* Builder class for creating retry strategies.
6884
* Provides convenient methods to create different types of retry strategies.
@@ -129,6 +145,16 @@ export class RetryStrategyBuilder {
129145
return RetryStrategyBuilder.retryStrategy('EXPONENTIAL', options)
130146
}
131147

148+
/**
149+
* A single retry will be performed.
150+
*/
151+
static singleRetry (options?: SingleRetryStrategyOptions): RetryStrategy {
152+
return RetryStrategyBuilder.retryStrategy('SINGLE', {
153+
baseBackoffSeconds: options?.baseBackoffSeconds,
154+
sameRegion: options?.sameRegion,
155+
})
156+
}
157+
132158
/**
133159
* No retries are performed.
134160
*/

0 commit comments

Comments
 (0)