Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring snoozeEndTime to AlertAttributesExcludedFromAAD #135602

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
5 changes: 5 additions & 0 deletions x-pack/plugins/alerting/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { isRuleExportable } from './is_rule_exportable';
import { RuleTypeRegistry } from '../rule_type_registry';
export { partiallyUpdateAlert } from './partially_update_alert';

// Use caution when removing items from this array! If the field
// exists in the rule SO, it needs to be included in this array to
// prevent decryption failures during migration.
export const AlertAttributesExcludedFromAAD = [
'scheduledTaskId',
'muteAll',
Expand All @@ -30,6 +33,7 @@ export const AlertAttributesExcludedFromAAD = [
'updatedAt',
'executionStatus',
'monitoring',
'snoozeEndTime',
'snoozeSchedule',
'isSnoozedUntil',
];
Expand All @@ -46,6 +50,7 @@ export type AlertAttributesExcludedFromAADType =
| 'updatedAt'
| 'executionStatus'
| 'monitoring'
| 'snoozeEndTime'
| 'snoozeSchedule'
| 'isSnoozedUntil';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,22 @@ export default function createGetTests({ getService }: FtrProviderContext) {
expect(response.statusCode).to.equal(200);
expect(response.body._source?.alert?.tags).to.eql(['test-tag-1', 'foo-tag']);
});

it('8.3.0 removes snoozeEndTime in favor of snoozeSchedule', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't seem to be working.
I commented out the return of the snoozeEndTime field in the AlertAttributesExcludedFromAAD variable and this test is still passing - it should be failing.

I know there's more work to be done by @mikecote today, so this might be a known issue, but I wanted to flag just in case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is because the migration will succeed even if decryption fails. I left a comment that we should add an expect here to ensure the api key still exists after migration but that can't be done until this (loading the test data in the correct manner)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant, thanks, I'll work with Mike to get that sorted asap.

const response = await es.get<{ alert: RawRule }>(
{
index: '.kibana',
id: 'alert:734def70-f8b1-11ec-b8e0-c99fab63aaae',
},
{ meta: true }
);

expect(response.statusCode).to.equal(200);
expect(response.body._source?.alert?.snoozeEndTime).to.be(undefined);
expect(response.body._source?.alert?.snoozeSchedule).not.to.be(undefined);

const snoozeSchedule = response.body._source?.alert.snoozeSchedule!;
expect(snoozeSchedule.length).to.eql(1);
Copy link
Contributor Author

@ymao1 ymao1 Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should add expect(response.body._source?.alert?.apiKey).not.to.be(undefined);

});
});
}
60 changes: 60 additions & 0 deletions x-pack/test/functional/es_archives/alerts/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,3 +1041,63 @@
}
}
}

{
"type":"doc",
"value":{
"id":"alert:734def70-f8b1-11ec-b8e0-c99fab63aaae",
"index":".kibana_1",
"source":{
"alert":{
"name":"Test rule with snoozeEndTime",
"alertTypeId":".index-threshold",
"consumer":"alerts",
"params" : {
"aggType" : "count",
"termSize" : 5,
"thresholdComparator" : ">",
"timeWindowSize" : 5,
"timeWindowUnit" : "d",
"groupBy" : "all",
"threshold" : [
0
],
"index" : [
".test-test-test"
],
"timeField" : "@timestamp"
},
"schedule":{
"interval":"1m"
},
"enabled":true,
"actions":[

],
"throttle":null,
"notifyWhen" : "onActiveAlert",
"apiKeyOwner" : "elastic",
"apiKey" : "y86eFOuG06GNd4p/90Zh4V4C+4wF8rFHiLcOeNqHQFFAbagYCXIuggq/N/AB0HBncCsWrh5PsCs4RiX53+LP2o+oLtoQkdTK9m+iv0BnzP6aavoypIudKtnElN3SotI3XpIRm7c3MEdM/C/zZXHgCmn4UMExhkulOO1S/Q//FwvIr2/SKw/mp8Vx5qP41hqDX4YFfSMoFkPSLw==",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a correct-er way to generate this data so that the api key can be decrypted by the functional test server. This is just one I've copied from local data and it gives a decryption error during the test :(

"createdBy":"elastic",
"updatedBy":"elastic",
"createdAt":"2021-07-27T20:42:55.896Z",
"muteAll":false,
"mutedInstanceIds":[

],
"snoozeEndTime" : "2022-06-30T23:18:17.740Z",
"scheduledTaskId":"734def70-f8b1-11ec-b8e0-c99fab63aaae",
"tags":[
]
},
"type":"alert",
"migrationVersion":{
"alert":"8.2.0"
},
"updated_at":"2021-08-13T23:00:11.985Z",
"references":[

]
}
}
}
6 changes: 6 additions & 0 deletions x-pack/test/functional/es_archives/alerts/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
},
"type": "text"
},
"notifyWhen": {
"type": "keyword"
},
Comment on lines +153 to +155
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary here? Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any field that's inside a document in data.json needs to have a mapping defined. It just so happened that none of the other rule SO examples in data.json had notifyWhen but the SO I just added does, so I added the mapping. It's not strictly needed for this PR, I could remove it from the new doc I added to data.json

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh gotcha.
Thanks Ying.... enjoy the weekend! ;)

"params": {
"enabled": false,
"type": "object"
Expand All @@ -164,6 +167,9 @@
"scheduledTaskId": {
"type": "keyword"
},
"snoozeEndTime": {
"type": "keyword"
},
"tags": {
"type": "keyword"
},
Expand Down