Skip to content

Commit

Permalink
[Alerting] add functional tests for index threshold alertType (#60597)
Browse files Browse the repository at this point in the history
resolves #58902
  • Loading branch information
pmuellr authored Mar 19, 2020
1 parent d1aaa44 commit d5989e8
Show file tree
Hide file tree
Showing 6 changed files with 447 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export function getAlertType(service: Service): AlertType {
timeWindowUnit: params.timeWindowUnit,
interval: undefined,
};
// console.log(`index_threshold: query: ${JSON.stringify(queryParams, null, 4)}`);
const result = await service.indexThreshold.timeSeriesQuery({
logger,
callCluster,
Expand All @@ -121,6 +122,7 @@ export function getAlertType(service: Service): AlertType {
logger.debug(`alert ${ID}:${alertId} "${name}" query result: ${JSON.stringify(result)}`);

const groupResults = result.results || [];
// console.log(`index_threshold: response: ${JSON.stringify(groupResults, null, 4)}`);
for (const groupResult of groupResults) {
const instanceId = groupResult.group;
const value = groupResult.metrics[0][1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
* you may not use this file except in compliance with the Elastic License.
*/

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

export class ESTestIndexTool {
private readonly es: any;
private readonly retry: any;

constructor(es: any, retry: any) {
this.es = es;
this.retry = retry;
}
constructor(
private readonly es: any,
private readonly retry: any,
private readonly index: string = ES_TEST_INDEX_NAME
) {}

async setup() {
return await this.es.indices.create({
index: ES_TEST_INDEX_NAME,
index: this.index,
body: {
mappings: {
properties: {
Expand Down Expand Up @@ -56,12 +54,13 @@ export class ESTestIndexTool {
}

async destroy() {
return await this.es.indices.delete({ index: ES_TEST_INDEX_NAME, ignore: [404] });
return await this.es.indices.delete({ index: this.index, ignore: [404] });
}

async search(source: string, reference: string) {
return await this.es.search({
index: ES_TEST_INDEX_NAME,
index: this.index,
size: 1000,
body: {
query: {
bool: {
Expand All @@ -86,7 +85,7 @@ 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) {
if (searchResult.hits.total.value < numDocs) {
throw new Error(`Expected ${numDocs} but received ${searchResult.hits.total.value}.`);
}
return searchResult.hits.hits;
Expand Down
Loading

0 comments on commit d5989e8

Please sign in to comment.