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

[Alerting] Using new es client in alerting functional tests #102349

Merged
merged 16 commits into from
Jun 24, 2021
Merged
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
Prev Previous commit
Next Next commit
Updating functional test
ymao1 committed Jun 17, 2021
commit b399d91018a9b6a5df0c559beec105c7d288a38d
Original file line number Diff line number Diff line change
@@ -93,10 +93,12 @@ export class ESTestIndexTool {
async waitForDocs(source: string, reference: string, numDocs: number = 1) {
return await this.retry.try(async () => {
const searchResult = await this.search(source, reference);
if (searchResult.hits.total.value < numDocs) {
throw new Error(`Expected ${numDocs} but received ${searchResult.hits.total.value}.`);
if (searchResult.body.hits.total.valueOf < numDocs) {
throw new Error(
`Expected ${numDocs} but received ${searchResult.body.hits.total.valueOf}.`
);
}
return searchResult.hits.hits;
return searchResult.body.hits.hits;
});
}
}
Original file line number Diff line number Diff line change
@@ -45,8 +45,8 @@ export class TaskManagerUtils {
},
},
});
if (searchResult.hits.total.value) {
throw new Error(`Expected 0 tasks but received ${searchResult.hits.total.value}`);
if (searchResult.body.hits.total.valueOf) {
throw new Error(`Expected 0 tasks but received ${searchResult.body.hits.total.valueOf}`);
}
});
}
@@ -83,8 +83,10 @@ export class TaskManagerUtils {
},
},
});
if (searchResult.hits.total.value) {
throw new Error(`Expected 0 non-idle tasks but received ${searchResult.hits.total.value}`);
if (searchResult.body.hits.total.valueOf) {
throw new Error(
`Expected 0 non-idle tasks but received ${searchResult.body.hits.total.valueOf}`
);
}
});
}
@@ -114,9 +116,9 @@ export class TaskManagerUtils {
},
},
});
if (searchResult.hits.total.value) {
if (searchResult.body.hits.total.valueOf) {
throw new Error(
`Expected 0 action_task_params objects but received ${searchResult.hits.total.value}`
`Expected 0 action_task_params objects but received ${searchResult.body.hits.total.valueOf}`
);
}
});
Original file line number Diff line number Diff line change
@@ -57,5 +57,5 @@ async function getTestIndexItems(es: any) {
index: ES_TEST_INDEX_NAME,
});

return result.hits.hits;
return result.body.hits.hits;
}
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ export default function ({ getService }: FtrProviderContext) {
'action:test.index-record',
reference
);
expect(searchResult.body.hits.total.value).to.eql(1);
expect(searchResult.body.hits.total.valueOf).to.eql(1);
const indexedRecord = searchResult.body.hits.hits[0];
expect(indexedRecord._source).to.eql({
params: {
Original file line number Diff line number Diff line change
@@ -134,11 +134,11 @@ export default function alertTests({ getService }: FtrProviderContext) {
'alert:test.always-firing',
reference
);
expect(alertSearchResult.hits.total.value).to.eql(1);
const alertSearchResultWithoutDates = omit(alertSearchResult.hits.hits[0]._source, [
'alertInfo.createdAt',
'alertInfo.updatedAt',
]);
expect(alertSearchResult.body.hits.total.valueOf).to.eql(1);
const alertSearchResultWithoutDates = omit(
alertSearchResult.body.hits.hits[0]._source,
['alertInfo.createdAt', 'alertInfo.updatedAt']
);
expect(alertSearchResultWithoutDates).to.eql({
source: 'alert:test.always-firing',
reference,
@@ -177,10 +177,10 @@ export default function alertTests({ getService }: FtrProviderContext) {
ruleTypeName: 'Test: Always Firing',
},
});
expect(alertSearchResult.hits.hits[0]._source.alertInfo.createdAt).to.match(
expect(alertSearchResult.body.hits.hits[0]._source.alertInfo.createdAt).to.match(
/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/
);
expect(alertSearchResult.hits.hits[0]._source.alertInfo.updatedAt).to.match(
expect(alertSearchResult.body.hits.hits[0]._source.alertInfo.updatedAt).to.match(
/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/
);

@@ -189,8 +189,8 @@ export default function alertTests({ getService }: FtrProviderContext) {
'action:test.index-record',
reference
);
expect(actionSearchResult.hits.total.value).to.eql(1);
expect(actionSearchResult.hits.hits[0]._source).to.eql({
expect(actionSearchResult.body.hits.total.valueOf).to.eql(1);
expect(actionSearchResult.body.hits.hits[0]._source).to.eql({
config: {
unencrypted: `This value shouldn't get encrypted`,
},
@@ -281,11 +281,11 @@ instanceStateValue: true
'alert:test.always-firing',
reference
);
expect(alertSearchResult.hits.total.value).to.eql(1);
const alertSearchResultWithoutDates = omit(alertSearchResult.hits.hits[0]._source, [
'alertInfo.createdAt',
'alertInfo.updatedAt',
]);
expect(alertSearchResult.body.hits.total.valueOf).to.eql(1);
const alertSearchResultWithoutDates = omit(
alertSearchResult.body.hits.hits[0]._source,
['alertInfo.createdAt', 'alertInfo.updatedAt']
);
expect(alertSearchResultWithoutDates).to.eql({
source: 'alert:test.always-firing',
reference,
@@ -325,19 +325,19 @@ instanceStateValue: true
},
});

expect(alertSearchResult.hits.hits[0]._source.alertInfo.createdAt).to.match(
expect(alertSearchResult.body.hits.hits[0]._source.alertInfo.createdAt).to.match(
/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/
);
expect(alertSearchResult.hits.hits[0]._source.alertInfo.updatedAt).to.match(
expect(alertSearchResult.body.hits.hits[0]._source.alertInfo.updatedAt).to.match(
/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/
);
// Ensure only 1 action executed with proper params
const actionSearchResult = await esTestIndexTool.search(
'action:test.index-record',
reference
);
expect(actionSearchResult.hits.total.value).to.eql(1);
expect(actionSearchResult.hits.hits[0]._source).to.eql({
expect(actionSearchResult.body.hits.total.valueOf).to.eql(1);
expect(actionSearchResult.body.hits.hits[0]._source).to.eql({
config: {
unencrypted: 'ignored-but-required',
},
@@ -416,9 +416,9 @@ instanceStateValue: true
reference2
);

expect(alertSearchResult.hits.total.value).to.be.greaterThan(0);
expect(alertSearchResult.body.hits.total.valueOf).to.be.greaterThan(0);
const alertSearchResultInfoWithoutDates = omit(
alertSearchResult.hits.hits[0]._source.alertInfo,
alertSearchResult.body.hits.hits[0]._source.alertInfo,
['createdAt', 'updatedAt']
);
expect(alertSearchResultInfoWithoutDates).to.eql({
@@ -451,10 +451,10 @@ instanceStateValue: true
ruleTypeName: 'Test: Always Firing',
});

expect(alertSearchResult.hits.hits[0]._source.alertInfo.createdAt).to.match(
expect(alertSearchResult.body.hits.hits[0]._source.alertInfo.createdAt).to.match(
/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/
);
expect(alertSearchResult.hits.hits[0]._source.alertInfo.updatedAt).to.match(
expect(alertSearchResult.body.hits.hits[0]._source.alertInfo.updatedAt).to.match(
/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/
);
});
@@ -630,21 +630,21 @@ instanceStateValue: true

// Ensure only 1 document exists with proper params
searchResult = await esTestIndexTool.search('alert:test.authorization', reference);
expect(searchResult.hits.total.value).to.eql(1);
expect(searchResult.hits.hits[0]._source.state).to.eql({
expect(searchResult.body.hits.total.valueOf).to.eql(1);
expect(searchResult.body.hits.hits[0]._source.state).to.eql({
callClusterSuccess: false,
callScopedClusterSuccess: false,
savedObjectsClientSuccess: false,
callClusterError: {
...searchResult.hits.hits[0]._source.state.callClusterError,
...searchResult.body.hits[0]._source.state.callClusterError,
},
callScopedClusterError: {
...searchResult.hits.hits[0]._source.state.callScopedClusterError,
...searchResult.body.hits.hits[0]._source.state.callScopedClusterError,
},
savedObjectsClientError: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError,
...searchResult.body.hits.hits[0]._source.state.savedObjectsClientError,
output: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError.output,
...searchResult.body.hits.hits[0]._source.state.savedObjectsClientError.output,
statusCode: 403,
},
},
@@ -661,15 +661,15 @@ instanceStateValue: true

// Ensure only 1 document exists with proper params
searchResult = await esTestIndexTool.search('alert:test.authorization', reference);
expect(searchResult.hits.total.value).to.eql(1);
expect(searchResult.hits.hits[0]._source.state).to.eql({
expect(searchResult.body.hits.total.valueOf).to.eql(1);
expect(searchResult.body.hits.hits[0]._source.state).to.eql({
callClusterSuccess: true,
callScopedClusterSuccess: true,
savedObjectsClientSuccess: false,
savedObjectsClientError: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError,
...searchResult.body.hits.hits[0]._source.state.savedObjectsClientError,
output: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError.output,
...searchResult.body.hits.hits[0]._source.state.savedObjectsClientError.output,
statusCode: 404,
},
},
@@ -747,21 +747,21 @@ instanceStateValue: true

// Ensure only 1 document with proper params exists
searchResult = await esTestIndexTool.search('action:test.authorization', reference);
expect(searchResult.hits.total.value).to.eql(1);
expect(searchResult.hits.hits[0]._source.state).to.eql({
expect(searchResult.body.total.valueOf).to.eql(1);
expect(searchResult.body.hits.hits[0]._source.state).to.eql({
callClusterSuccess: false,
callScopedClusterSuccess: false,
savedObjectsClientSuccess: false,
callClusterError: {
...searchResult.hits.hits[0]._source.state.callClusterError,
...searchResult.body.hits.hits[0]._source.state.callClusterError,
},
callScopedClusterError: {
...searchResult.hits.hits[0]._source.state.callScopedClusterError,
...searchResult.body.hits.hits[0]._source.state.callScopedClusterError,
},
savedObjectsClientError: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError,
...searchResult.body.hits.hits[0]._source.state.savedObjectsClientError,
output: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError.output,
...searchResult.body.hits.hits[0]._source.state.savedObjectsClientError.output,
statusCode: 403,
},
},
@@ -786,15 +786,15 @@ instanceStateValue: true

// Ensure only 1 document with proper params exists
searchResult = await esTestIndexTool.search('action:test.authorization', reference);
expect(searchResult.hits.total.value).to.eql(1);
expect(searchResult.hits.hits[0]._source.state).to.eql({
expect(searchResult.body.hits.total.valueOf).to.eql(1);
expect(searchResult.body.hits.hits[0]._source.state).to.eql({
callClusterSuccess: true,
callScopedClusterSuccess: true,
savedObjectsClientSuccess: false,
savedObjectsClientError: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError,
...searchResult.body.hits.hits[0]._source.state.savedObjectsClientError,
output: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError.output,
...searchResult.body.hits.hits[0]._source.state.savedObjectsClientError.output,
statusCode: 404,
},
},
@@ -852,7 +852,7 @@ instanceStateValue: true
'action:test.index-record',
reference
);
expect(searchResult.hits.total.value).to.eql(1);
expect(searchResult.body.hits.total.valueOf).to.eql(1);
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
@@ -931,8 +931,8 @@ instanceStateValue: true
'action:test.index-record',
reference
);
expect(searchResult.hits.total.value).to.eql(2);
const messages: string[] = searchResult.hits.hits.map(
expect(searchResult.body.hits.total.valueOf).to.eql(2);
const messages: string[] = searchResult.body.hits.hits.map(
(hit: { _source: { params: { message: string } } }) => hit._source.params.message
);
expect(messages.sort()).to.eql(['from:default', 'from:other']);
@@ -1005,8 +1005,8 @@ instanceStateValue: true
'action:test.index-record',
reference
);
expect(searchResult.hits.total.value).to.eql(2);
const messages: string[] = searchResult.hits.hits.map(
expect(searchResult.body.hits.total.valueOf).to.eql(2);
const messages: string[] = searchResult.body.hits.hits.map(
(hit: { _source: { params: { message: string } } }) => hit._source.params.message
);
expect(messages.sort()).to.eql(['from:default:next', 'from:default:prev']);
@@ -1068,7 +1068,7 @@ instanceStateValue: true
'action:test.index-record',
reference
);
expect(searchResult.hits.total.value).to.eql(2);
expect(searchResult.body.hits.total.valueOf).to.eql(2);
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
@@ -1126,7 +1126,7 @@ instanceStateValue: true
'action:test.index-record',
reference
);
expect(executedActionsResult.hits.total.value).to.eql(0);
expect(executedActionsResult.body.hits.total.valueOf).to.eql(0);
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
@@ -1184,7 +1184,7 @@ instanceStateValue: true
'action:test.index-record',
reference
);
expect(executedActionsResult.hits.total.value).to.eql(0);
expect(executedActionsResult.body.hits.total.valueOf).to.eql(0);
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
@@ -1243,7 +1243,7 @@ instanceStateValue: true
'action:test.index-record',
reference
);
expect(searchResult.hits.total.value).to.eql(1);
expect(searchResult.body.hits.total.valueOf).to.eql(1);
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
Original file line number Diff line number Diff line change
@@ -204,11 +204,11 @@ export default function alertTests({ getService }: FtrProviderContext) {
// ensure the alert still runs and that it can schedule actions
const numberOfAlertExecutions = (
await esTestIndexTool.search('alert:test.always-firing', reference)
).hits.total.value;
).body.hits.total.valueOf;

const numberOfActionExecutions = (
await esTestIndexTool.search('action:test.index-record', reference)
).hits.total.value;
).body.hits.total.valueOf;

// wait for alert to execute and for its action to be scheduled and run
await retry.try(async () => {
@@ -222,8 +222,10 @@ export default function alertTests({ getService }: FtrProviderContext) {
reference
);

expect(alertSearchResult.hits.total.value).to.be.greaterThan(numberOfAlertExecutions);
expect(actionSearchResult.hits.total.value).to.be.greaterThan(
expect(alertSearchResult.body.hits.total.valueOf).to.be.greaterThan(
numberOfAlertExecutions
);
expect(actionSearchResult.body.hits.total.valueOf).to.be.greaterThan(
numberOfActionExecutions
);
});
Original file line number Diff line number Diff line change
@@ -298,7 +298,7 @@ instanceStateValue: true
await taskManagerUtils.waitForActionTaskParamsToBeCleanedUp(testStart);

const actionTestRecord = await esTestIndexTool.search('action:test.index-record', reference);
expect(actionTestRecord.hits.total.value).to.eql(0);
expect(actionTestRecord.body.hits.total.valueOf).to.eql(0);
objectRemover.add(space.id, alertId, 'rule', 'alerting');
});