Skip to content

Commit c7df9c8

Browse files
authored
[Alerting] add functional tests for index threshold alertType (#60597) (#60707)
resolves #58902
1 parent b0f875d commit c7df9c8

File tree

6 files changed

+447
-49
lines changed

6 files changed

+447
-49
lines changed

x-pack/plugins/alerting_builtins/server/alert_types/index_threshold/alert_type.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export function getAlertType(service: Service): AlertType {
113113
timeWindowUnit: params.timeWindowUnit,
114114
interval: undefined,
115115
};
116+
// console.log(`index_threshold: query: ${JSON.stringify(queryParams, null, 4)}`);
116117
const result = await service.indexThreshold.timeSeriesQuery({
117118
logger,
118119
callCluster,
@@ -121,6 +122,7 @@ export function getAlertType(service: Service): AlertType {
121122
logger.debug(`alert ${ID}:${alertId} "${name}" query result: ${JSON.stringify(result)}`);
122123

123124
const groupResults = result.results || [];
125+
// console.log(`index_threshold: response: ${JSON.stringify(groupResults, null, 4)}`);
124126
for (const groupResult of groupResults) {
125127
const instanceId = groupResult.group;
126128
const value = groupResult.metrics[0][1];

x-pack/test/alerting_api_integration/common/lib/es_test_index_tool.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export const ES_TEST_INDEX_NAME = '.kibaka-alerting-test-data';
7+
export const ES_TEST_INDEX_NAME = '.kibana-alerting-test-data';
88

99
export class ESTestIndexTool {
10-
private readonly es: any;
11-
private readonly retry: any;
12-
13-
constructor(es: any, retry: any) {
14-
this.es = es;
15-
this.retry = retry;
16-
}
10+
constructor(
11+
private readonly es: any,
12+
private readonly retry: any,
13+
private readonly index: string = ES_TEST_INDEX_NAME
14+
) {}
1715

1816
async setup() {
1917
return await this.es.indices.create({
20-
index: ES_TEST_INDEX_NAME,
18+
index: this.index,
2119
body: {
2220
mappings: {
2321
properties: {
@@ -56,12 +54,13 @@ export class ESTestIndexTool {
5654
}
5755

5856
async destroy() {
59-
return await this.es.indices.delete({ index: ES_TEST_INDEX_NAME, ignore: [404] });
57+
return await this.es.indices.delete({ index: this.index, ignore: [404] });
6058
}
6159

6260
async search(source: string, reference: string) {
6361
return await this.es.search({
64-
index: ES_TEST_INDEX_NAME,
62+
index: this.index,
63+
size: 1000,
6564
body: {
6665
query: {
6766
bool: {
@@ -86,7 +85,7 @@ export class ESTestIndexTool {
8685
async waitForDocs(source: string, reference: string, numDocs: number = 1) {
8786
return await this.retry.try(async () => {
8887
const searchResult = await this.search(source, reference);
89-
if (searchResult.hits.total.value !== numDocs) {
88+
if (searchResult.hits.total.value < numDocs) {
9089
throw new Error(`Expected ${numDocs} but received ${searchResult.hits.total.value}.`);
9190
}
9291
return searchResult.hits.hits;

0 commit comments

Comments
 (0)