-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
529 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
x-pack/test/api_integration/apis/all_deployments/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { FtrConfigProviderContext } from '@kbn/test'; | ||
|
||
export default async function ({ readConfigFile }: FtrConfigProviderContext) { | ||
const baseIntegrationTestsConfig = await readConfigFile(require.resolve('../../config.ts')); | ||
|
||
return { | ||
...baseIntegrationTestsConfig.getAll(), | ||
testFiles: [ | ||
require.resolve('../../../../test_all_deployments/api_integration/test_suites/observability'), | ||
], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { | ||
AggregationsAggregate, | ||
SearchResponse, | ||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
|
||
import { MetricThresholdParams } from '@kbn/infra-plugin/common/alerting/metrics'; | ||
import { ThresholdParams } from '@kbn/observability-plugin/common/custom_threshold_rule/types'; | ||
import { SloBurnRateRuleParams } from './slo'; | ||
import { FtrProviderContext } from '../ftr_provider_context'; | ||
|
||
export function AlertingApiProvider({ getService }: FtrProviderContext) { | ||
const retry = getService('retry'); | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
const requestTimeout = 30 * 1000; | ||
const retryTimeout = 120 * 1000; | ||
const logger = getService('log'); | ||
|
||
return { | ||
async waitForRuleStatus({ | ||
ruleId, | ||
expectedStatus, | ||
}: { | ||
ruleId: string; | ||
expectedStatus: string; | ||
}) { | ||
if (!ruleId) { | ||
throw new Error(`'ruleId' is undefined`); | ||
} | ||
return await retry.tryForTime(retryTimeout, async () => { | ||
const response = await supertest | ||
.get(`/api/alerting/rule/${ruleId}`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo') | ||
.timeout(requestTimeout); | ||
const { execution_status: executionStatus } = response.body || {}; | ||
const { status } = executionStatus || {}; | ||
if (status !== expectedStatus) { | ||
throw new Error(`waitForStatus(${expectedStatus}): got ${status}`); | ||
} | ||
return executionStatus?.status; | ||
}); | ||
}, | ||
|
||
async waitForDocumentInIndex<T>({ | ||
indexName, | ||
docCountTarget = 1, | ||
}: { | ||
indexName: string; | ||
docCountTarget?: number; | ||
}): Promise<SearchResponse<T, Record<string, AggregationsAggregate>>> { | ||
return await retry.tryForTime(retryTimeout, async () => { | ||
const response = await es.search<T>({ | ||
index: indexName, | ||
rest_total_hits_as_int: true, | ||
}); | ||
logger.debug(`Found ${response.hits.total} docs, looking for atleast ${docCountTarget}.`); | ||
if (!response.hits.total || response.hits.total < docCountTarget) { | ||
throw new Error('No hits found'); | ||
} | ||
return response; | ||
}); | ||
}, | ||
|
||
async waitForAlertInIndex<T>({ | ||
indexName, | ||
ruleId, | ||
}: { | ||
indexName: string; | ||
ruleId: string; | ||
}): Promise<SearchResponse<T, Record<string, AggregationsAggregate>>> { | ||
if (!ruleId) { | ||
throw new Error(`'ruleId' is undefined`); | ||
} | ||
return await retry.tryForTime(retryTimeout, async () => { | ||
const response = await es.search<T>({ | ||
index: indexName, | ||
body: { | ||
query: { | ||
term: { | ||
'kibana.alert.rule.uuid': ruleId, | ||
}, | ||
}, | ||
}, | ||
}); | ||
if (response.hits.hits.length === 0) { | ||
throw new Error('No hits found'); | ||
} | ||
return response; | ||
}); | ||
}, | ||
|
||
async createIndexConnector({ name, indexName }: { name: string; indexName: string }) { | ||
const { body } = await supertest | ||
.post(`/api/actions/connector`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo') | ||
.send({ | ||
name, | ||
config: { | ||
index: indexName, | ||
refresh: true, | ||
}, | ||
connector_type_id: '.index', | ||
}); | ||
return body.id as string; | ||
}, | ||
|
||
async createRule({ | ||
name, | ||
ruleTypeId, | ||
params, | ||
actions = [], | ||
tags = [], | ||
schedule, | ||
consumer, | ||
}: { | ||
ruleTypeId: string; | ||
name: string; | ||
params: MetricThresholdParams | ThresholdParams | SloBurnRateRuleParams; | ||
actions?: any[]; | ||
tags?: any[]; | ||
schedule?: { interval: string }; | ||
consumer: string; | ||
}) { | ||
const { body } = await supertest | ||
.post(`/api/alerting/rule`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo') | ||
.send({ | ||
params, | ||
consumer, | ||
schedule: schedule || { | ||
interval: '5m', | ||
}, | ||
tags, | ||
name, | ||
rule_type_id: ruleTypeId, | ||
actions, | ||
}); | ||
return body; | ||
}, | ||
|
||
async findRule(ruleId: string) { | ||
if (!ruleId) { | ||
throw new Error(`'ruleId' is undefined`); | ||
} | ||
const response = await supertest | ||
.get('/api/alerting/rules/_find') | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo'); | ||
return response.body.data.find((obj: any) => obj.id === ruleId); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
x-pack/test_all_deployments/api_integration/ftr_provider_context.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { GenericFtrProviderContext } from '@kbn/test'; | ||
|
||
// eslint-disable-next-line @kbn/imports/no_boundary_crossing | ||
import { services } from '../../test/api_integration/services'; | ||
|
||
export type FtrProviderContext = GenericFtrProviderContext<typeof services, {}>; |
14 changes: 14 additions & 0 deletions
14
x-pack/test_all_deployments/api_integration/test_suites/observability/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { FtrProviderContext } from '../../ftr_provider_context'; | ||
|
||
export default function ({ loadTestFile }: FtrProviderContext) { | ||
describe('all deployments observability API', function () { | ||
loadTestFile(require.resolve('./slo/burn_rate_rule')); | ||
}); | ||
} |
Oops, something went wrong.