Skip to content

Commit

Permalink
[8.x] migrate es query rule tests to the deployment agnostic framework (
Browse files Browse the repository at this point in the history
#195715) (#198919)

# Backport

This will backport the following commits from `main` to `8.x`:
- migrate es query rule tests to the deployment agnostic framework
(#195715) (512bfcc)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Panagiota
Mitsopoulou","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-24T07:23:15Z","message":"migrate
es query rule tests to the deployment agnostic framework
(#195715)\n\nFixes
https://github.com/elastic/kibana/issues/183395\r\n\r\nThis PR migrates
the ES query rule tests to the [deployment
agnostic\r\nframework](https://github.com/elastic/kibana/tree/main/x-pack/test/api_integration/deployment_agnostic)\r\n\r\n###
TODO\r\n\r\n- [x] Migrate ES rule tests into the deployment agnostic
solution\r\n- [ ] Test in MKI before merging\r\n\r\n### How to run tests
locally\r\n\r\nTo run serverless\r\n```\r\nnode
scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts
--grep=\"ElasticSearch query rule\"\r\n```\r\n\r\nTo run
stateful\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts
--grep=\"ElasticSearch query rule\"\r\n```\r\n\r\n### How to run tests
on MKI\r\n\r\nAccording to
this\r\n[discussion](https://github.com/elastic/observability-dev/issues/3519#issuecomment-2379914274),\r\nwe
should test in MKI environment before merging. For details on how
to\r\nrun in MKI, see [this section of
the\r\ndocument](https://docs.google.com/document/d/1tiax7xoDYwFXYZjRTgVKkVMjN-SQzBWk4yn1JY6Z5UY/edit#heading=h.ece2z8p74izh)\r\nand
[this\r\nreadme](https://github.com/elastic/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki).\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>\r\nCo-authored-by: Maryam
Saeidi
<[email protected]>","sha":"512bfccd7187c1107ec143498daf980a1422fb4d"},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[]}]
BACKPORT-->
  • Loading branch information
mgiota authored Nov 5, 2024
1 parent 5d663c6 commit 4af104c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
/*
* 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 expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { InternalRequestHeader, RoleCredentials } from '../../../../shared/services';
import { RoleCredentials, InternalRequestHeader } from '@kbn/ftr-common-functional-services';
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
const esClient = getService('es');
const supertest = getService('supertest');
const samlAuth = getService('samlAuth');
const supertestWithoutAuth = getService('supertestWithoutAuth');
const esDeleteAllIndices = getService('esDeleteAllIndices');
const alertingApi = getService('alertingApi');
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
let roleAuthc: RoleCredentials;
const config = getService('config');
const isServerless = config.get('serverless');
const expectedConsumer = isServerless ? 'observability' : 'logs';

let adminRoleAuthc: RoleCredentials;
let internalReqHeader: InternalRequestHeader;

describe('ElasticSearch query rule', () => {
Expand All @@ -31,34 +29,40 @@ export default function ({ getService }: FtrProviderContext) {
let ruleId: string;

before(async () => {
roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin');
internalReqHeader = svlCommonApi.getInternalRequestHeader();
adminRoleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('admin');
internalReqHeader = samlAuth.getInternalRequestHeader();
});

after(async () => {
await supertest.delete(`/api/alerting/rule/${ruleId}`).set(internalReqHeader);
await supertest.delete(`/api/actions/connector/${actionId}`).set(internalReqHeader);
await supertestWithoutAuth
.delete(`/api/alerting/rule/${ruleId}`)
.set(adminRoleAuthc.apiKeyHeader)
.set(internalReqHeader);
await supertestWithoutAuth
.delete(`/api/actions/connector/${actionId}`)
.set(adminRoleAuthc.apiKeyHeader)
.set(internalReqHeader);

await esClient.deleteByQuery({
index: '.kibana-event-log-*',
query: { term: { 'rule.id': ruleId } },
conflicts: 'proceed',
});
await esDeleteAllIndices([ALERT_ACTION_INDEX]);
await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc);
await samlAuth.invalidateM2mApiKeyWithRoleScope(adminRoleAuthc);
});

describe('Rule creation', () => {
it('creates rule successfully', async () => {
actionId = await alertingApi.createIndexConnector({
roleAuthc,
roleAuthc: adminRoleAuthc,
name: 'Index Connector: Alerting API test',
indexName: ALERT_ACTION_INDEX,
});

const createdRule = await alertingApi.helpers.createEsQueryRule({
roleAuthc,
consumer: 'observability',
roleAuthc: adminRoleAuthc,
consumer: expectedConsumer,
name: 'always fire',
ruleTypeId: RULE_TYPE_ID,
params: {
Expand Down Expand Up @@ -104,17 +108,17 @@ export default function ({ getService }: FtrProviderContext) {

it('should be active', async () => {
const executionStatus = await alertingApi.waitForRuleStatus({
roleAuthc,
roleAuthc: adminRoleAuthc,
ruleId,
expectedStatus: 'active',
});
expect(executionStatus).to.be('active');
});

it('should find the created rule with correct information about the consumer', async () => {
const match = await alertingApi.findInRules(roleAuthc, ruleId);
const match = await alertingApi.findInRules(adminRoleAuthc, ruleId);
expect(match).not.to.be(undefined);
expect(match.consumer).to.be('observability');
expect(match.consumer).to.be(expectedConsumer);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';

export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) {
describe('SLO - Burn rate rule', () => {
describe('Observability Alerting', () => {
loadTestFile(require.resolve('./burn_rate_rule'));
loadTestFile(require.resolve('./custom_threshold'));
loadTestFile(require.resolve('./es_query_rule'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./apm_api_integration/service_maps/service_maps'));
loadTestFile(require.resolve('./apm_api_integration/traces/critical_path'));
loadTestFile(require.resolve('./cases'));
loadTestFile(require.resolve('./es_query_rule/es_query_rule'));
loadTestFile(require.resolve('./slos'));
loadTestFile(require.resolve('./synthetics'));
loadTestFile(require.resolve('./dataset_quality_api_integration'));
Expand Down

0 comments on commit 4af104c

Please sign in to comment.