Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
44910cc
initial commit
js-jankisalvi Mar 3, 2025
24eda2d
add integration tests, add checks for schedule id in rules client
js-jankisalvi Mar 4, 2025
840e8d1
clean up
js-jankisalvi Mar 5, 2025
00cce88
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Mar 5, 2025
ae34c60
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Mar 5, 2025
fa71994
handle errors at route level
js-jankisalvi Mar 6, 2025
0873c40
Merge remote-tracking branch 'upstream' into delete-snooze-api
js-jankisalvi Mar 14, 2025
24372d8
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Mar 14, 2025
2b48e86
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Mar 14, 2025
0e6fb9b
fix tests, update docs, add availability for the route
js-jankisalvi Mar 14, 2025
2996d95
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Mar 14, 2025
e2335e2
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Mar 14, 2025
2260737
Edit parameter and operation descriptions
lcawl Mar 14, 2025
791f3dd
Regenerate output
lcawl Mar 14, 2025
04ea1ca
Merge branch 'main' into delete-snooze-api
lcawl Mar 14, 2025
4df2139
Merge branch 'main' into delete-snooze-api
js-jankisalvi Mar 17, 2025
6b790a7
Merge branch 'main' into delete-snooze-api
js-jankisalvi Mar 17, 2025
c6fee5a
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Mar 17, 2025
a253955
throw 404 when no schedule found for scheduleId
js-jankisalvi Mar 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions oas_docs/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -5261,6 +5261,59 @@
]
}
},
"/api/alerting/rule/{ruleId}/snooze_schedule/{scheduleId}": {
"delete": {
"operationId": "delete-alerting-rule-ruleid-snooze-schedule-scheduleid",
"parameters": [
{
"description": "A required header to protect against CSRF attacks",
"in": "header",
"name": "kbn-xsrf",
"required": true,
"schema": {
"example": "true",
"type": "string"
}
},
{
"description": "The identifier for the rule.",
"in": "path",
"name": "ruleId",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "The identifier for the snooze schedule.",
"in": "path",
"name": "scheduleId",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given id does not exist."
}
},
"summary": "Delete a snooze schedule for a rule",
"tags": [
"alerting"
]
}
},
"/api/alerting/rule/{rule_id}/alert/{alert_id}/_mute": {
"post": {
"operationId": "post-alerting-rule-rule-id-alert-alert-id-mute",
Expand Down
53 changes: 53 additions & 0 deletions oas_docs/bundle.serverless.json
Original file line number Diff line number Diff line change
Expand Up @@ -5261,6 +5261,59 @@
]
}
},
"/api/alerting/rule/{ruleId}/snooze_schedule/{scheduleId}": {
"delete": {
"operationId": "delete-alerting-rule-ruleid-snooze-schedule-scheduleid",
"parameters": [
{
"description": "A required header to protect against CSRF attacks",
"in": "header",
"name": "kbn-xsrf",
"required": true,
"schema": {
"example": "true",
"type": "string"
}
},
{
"description": "The identifier for the rule.",
"in": "path",
"name": "ruleId",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "The identifier for the snooze schedule.",
"in": "path",
"name": "scheduleId",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given id does not exist."
}
},
"summary": "Delete a snooze schedule for a rule",
"tags": [
"alerting"
]
}
},
"/api/alerting/rule/{rule_id}/alert/{alert_id}/_mute": {
"post": {
"operationId": "post-alerting-rule-rule-id-alert-alert-id-mute",
Expand Down
36 changes: 36 additions & 0 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4173,6 +4173,42 @@ paths:
tags:
- alerting
x-beta: true
/api/alerting/rule/{ruleId}/snooze_schedule/{scheduleId}:
delete:
operationId: delete-alerting-rule-ruleid-snooze-schedule-scheduleid
parameters:
- description: A required header to protect against CSRF attacks
in: header
name: kbn-xsrf
required: true
schema:
example: 'true'
type: string
- description: The identifier for the rule.
in: path
name: ruleId
required: true
schema:
type: string
- description: The identifier for the snooze schedule.
in: path
name: scheduleId
required: true
schema:
type: string
responses:
'204':
description: Indicates a successful call.
'400':
description: Indicates an invalid schema.
'403':
description: Indicates that this call is forbidden.
'404':
description: Indicates a rule with the given id does not exist.
summary: Delete a snooze schedule for a rule
tags:
- alerting
x-beta: true
/api/alerting/rules/_find:
get:
operationId: get-alerting-rules-find
Expand Down
35 changes: 35 additions & 0 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4524,6 +4524,41 @@ paths:
summary: Unmute an alert
tags:
- alerting
/api/alerting/rule/{ruleId}/snooze_schedule/{scheduleId}:
delete:
operationId: delete-alerting-rule-ruleid-snooze-schedule-scheduleid
parameters:
- description: A required header to protect against CSRF attacks
in: header
name: kbn-xsrf
required: true
schema:
example: 'true'
type: string
- description: The identifier for the rule.
in: path
name: ruleId
required: true
schema:
type: string
- description: The identifier for the snooze schedule.
in: path
name: scheduleId
required: true
schema:
type: string
responses:
'204':
description: Indicates a successful call.
'400':
description: Indicates an invalid schema.
'403':
description: Indicates that this call is forbidden.
'404':
description: Indicates a rule with the given id does not exist.
summary: Delete a snooze schedule for a rule
tags:
- alerting
/api/alerting/rules/_find:
get:
operationId: get-alerting-rules-find
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { schema } from '@kbn/config-schema';

export const unsnoozeParamsSchema = schema.object({
ruleId: schema.string({meta: { description: 'The identifier for the rule.'}}),
scheduleId: schema.string({
meta: { description: 'The identifier for the snooze schedule.'}
}),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { TypeOf } from '@kbn/config-schema';
import type { unsnoozeParamsSchemaV1 } from '../..';

export type UnsnoozeParams = TypeOf<typeof unsnoozeParamsSchemaV1>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
* 2.0.
*/

export { unsnoozeParamsSchema, unsnoozeBodySchema } from './schemas/latest';
export {
unsnoozeParamsInternalSchema,
unsnoozeBodyInternalSchema,
} from './internal/schemas/latest';
export { unsnoozeParamsSchema } from './external/schemas/latest';
export type { UnsnoozeParams } from './external/types/latest';

export {
unsnoozeParamsSchema as unsnoozeParamsSchemaV1,
unsnoozeBodySchema as unsnoozeBodySchemaV1,
} from './schemas/v1';
unsnoozeParamsInternalSchema as unsnoozeParamsInternalSchemaV1,
unsnoozeBodyInternalSchema as unsnoozeBodyInternalSchemaV1,
} from './internal/schemas/v1';
export { unsnoozeParamsSchema as unsnoozeParamsSchemaV1 } from './external/schemas/v1';
export type { UnsnoozeParams as UnsnoozeParamsV1 } from './external/types/v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './v1';
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import { schema } from '@kbn/config-schema';

export const unsnoozeParamsSchema = schema.object({
export const unsnoozeParamsInternalSchema = schema.object({
id: schema.string(),
});

const scheduleIdsSchema = schema.maybe(schema.arrayOf(schema.string()));

export const unsnoozeBodySchema = schema.object({
export const unsnoozeBodyInternalSchema = schema.object({
schedule_ids: scheduleIdsSchema,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { RulesClientContext } from '../../../../rules_client';
import { unsnoozeRule } from './unsnooze_rule';
import { savedObjectsRepositoryMock } from '@kbn/core-saved-objects-api-server-mocks';

const loggerErrorMock = jest.fn();
const getBulkMock = jest.fn();

const savedObjectsMock = savedObjectsRepositoryMock.create();
savedObjectsMock.get = jest.fn().mockReturnValue({
attributes: {
actions: [],
snoozeSchedule: [
{
duration: 600000,
rRule: {
interval: 1,
freq: 3,
dtstart: '2025-03-01T06:30:37.011Z',
tzid: 'UTC',
},
id: 'snooze_schedule_1',
},
],
},
version: '9.0.0',
});

const context = {
logger: { error: loggerErrorMock },
getActionsClient: () => {
return {
getBulk: getBulkMock,
};
},
unsecuredSavedObjectsClient: savedObjectsMock,
authorization: { ensureAuthorized: async () => {} },
ruleTypeRegistry: {
ensureRuleTypeEnabled: () => {},
},
getUserName: async () => {},
} as unknown as RulesClientContext;

describe('validate unsnooze params', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('should validate params correctly', async () => {
await expect(
unsnoozeRule(context, { id: '123', scheduleIds: ['snooze_schedule_1'] })
).resolves.toBeUndefined();
});

it('should validate params with empty schedule ids correctly', async () => {
await expect(unsnoozeRule(context, { id: '123', scheduleIds: [] })).resolves.toBeUndefined();
});

it('should throw bad request for invalid params', async () => {
// @ts-expect-error: testing invalid params
await expect(unsnoozeRule(context, {})).rejects.toThrowErrorMatchingInlineSnapshot(
`"Error validating unsnooze params - [id]: expected value of type [string] but got [undefined]"`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { unmuteAlertRoute } from './rule/apis/unmute_alert/unmute_alert_route';
import { updateRuleApiKeyRoute } from './rule/apis/update_api_key/update_rule_api_key_route';
import { bulkEditInternalRulesRoute } from './rule/apis/bulk_edit/bulk_edit_rules_route';
import { snoozeRuleInternalRoute, snoozeRuleRoute } from './rule/apis/snooze';
import { unsnoozeRuleRoute } from './rule/apis/unsnooze';
import { unsnoozeRuleRoute, unsnoozeRuleInternalRoute } from './rule/apis/unsnooze';
import { runSoonRoute } from './run_soon';
import { bulkDeleteRulesRoute } from './rule/apis/bulk_delete/bulk_delete_rules_route';
import { bulkEnableRulesRoute } from './rule/apis/bulk_enable/bulk_enable_rules_route';
Expand Down Expand Up @@ -124,6 +124,7 @@ export function defineRoutes(opts: RouteOptions) {
snoozeRuleInternalRoute(router, licenseState);
snoozeRuleRoute(router, licenseState);
unsnoozeRuleRoute(router, licenseState);
unsnoozeRuleInternalRoute(router, licenseState);
cloneRuleRoute(router, licenseState);
getRuleTagsRoute(router, licenseState);
registerRulesValueSuggestionsRoute(router, licenseState, config$!);
Expand Down
Loading