Skip to content

Commit 5b15235

Browse files
committed
fix(datadog): compare downtime targets after parsing, not before
A whitespace-only Monitor ID is truthy as a raw string but parses to no monitor, so the oneOf conflict guard rejected a valid tag-targeted downtime whenever the untouched Monitor ID field carried blank text. Both sides are now compared after parsing.
1 parent 769d986 commit 5b15235

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

apps/sim/tools/datadog/create_downtime.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,21 @@ export const createDowntimeTool: ToolConfig<CreateDowntimeParams, CreateDowntime
102102
if (params.end) schedule.end = new Date(params.end * 1000).toISOString()
103103

104104
const monitorTags = splitCommaList(params.monitorTags)
105+
const monitorId = parseMonitorIds(params.monitorId)?.[0]
105106

106107
/**
107108
* `monitor_identifier` is required and is a `oneOf`: a downtime targets either a
108109
* single monitor or a tag set, never both. Accepting both silently would drop one
109-
* of them and mute a different set of monitors than the caller asked for.
110+
* of them and mute a different set of monitors than the caller asked for. Both
111+
* sides are compared after parsing so a blank or whitespace-only input, which is
112+
* how an untouched field arrives, does not read as a chosen target.
110113
*/
111-
if (params.monitorId && monitorTags) {
114+
if (monitorId !== undefined && monitorTags) {
112115
throw new Error(
113116
'Supply either a monitor ID or monitor tags, not both — a downtime targets one or the other'
114117
)
115118
}
116119

117-
const monitorId = parseMonitorIds(params.monitorId)?.[0]
118-
119120
// Datadog expresses "every monitor in scope" as the `*` monitor tag, which is the
120121
// fallback when no monitor is named.
121122
const monitorIdentifier =

apps/sim/tools/datadog/datadog.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,17 @@ describe('create_downtime monitor targeting', () => {
416416
expect(body.data.attributes.monitor_identifier).toEqual({ monitor_id: 123 })
417417
})
418418

419+
/** A blank monitor ID is how an untouched field arrives; it is not a chosen target. */
420+
it('does not treat a whitespace-only monitor id as a conflicting target', () => {
421+
const body = callBody(createDowntimeTool, {
422+
...auth,
423+
scope: '*',
424+
monitorId: ' ',
425+
monitorTags: 'team:backend',
426+
} as any)
427+
expect(body.data.attributes.monitor_identifier).toEqual({ monitor_tags: ['team:backend'] })
428+
})
429+
419430
it('accepts monitor tags that arrive as an array', () => {
420431
const body = callBody(createDowntimeTool, {
421432
...auth,

0 commit comments

Comments
 (0)