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

[7.x] [Alerting] add functional tests for index threshold alertType (#60597) #60707

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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