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

[SLO] [Alerting] deployment agnostic slo burn rate rule tests #187924

Merged
merged 38 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f495936
deployment agnostic slo burn rate rule tests
mgiota Jul 9, 2024
95feb99
merge main
dominiqueclarke Aug 12, 2024
647e38b
add burn rate tests to agnostic api test directory
dominiqueclarke Aug 12, 2024
4876a31
add builtkite config
dominiqueclarke Aug 12, 2024
2ee040b
remove unused directory
dominiqueclarke Aug 12, 2024
f28913a
update codeowners
dominiqueclarke Aug 12, 2024
fb4d553
adjust alerting api
dominiqueclarke Aug 12, 2024
f1d7143
Update x-pack/test/api_integration/services/index.ts
dominiqueclarke Aug 13, 2024
7d70b1a
sUpdate x-pack/test/api_integration/deployment_agnostic/oblt.stateful…
dominiqueclarke Aug 13, 2024
390ebb6
Update .eslintrc.js
dominiqueclarke Aug 13, 2024
ad12156
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 13, 2024
c02f861
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 13, 2024
145ed27
adjust tests
dominiqueclarke Aug 13, 2024
6ee3000
update service and test
dmlemeshko Aug 14, 2024
d43a0c7
Merge remote-tracking branch 'upstream/main' into slo_burn_rate_deplo…
dmlemeshko Aug 14, 2024
34fc89c
avoid loading stateful services
dmlemeshko Aug 14, 2024
770101b
remove duplicated service
dmlemeshko Aug 14, 2024
9356c2a
remove unused alerting_api service
dmlemeshko Aug 14, 2024
65e4e17
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 14, 2024
4978fe7
restore original services
dmlemeshko Aug 14, 2024
b7ae99a
Merge branch 'slo_burn_rate_deployment_agnostic_tests' of github.com:…
dmlemeshko Aug 14, 2024
1facfd1
fix type errors
dmlemeshko Aug 14, 2024
dea02c6
remove tags
dmlemeshko Aug 14, 2024
0be3024
Merge branch 'main' into slo_burn_rate_deployment_agnostic_tests
dmlemeshko Aug 14, 2024
7053b2b
fix test loading and move types
dmlemeshko Aug 15, 2024
daa1b8f
Merge branch 'slo_burn_rate_deployment_agnostic_tests' of github.com:…
dmlemeshko Aug 15, 2024
9b76f4f
add missing auth header
dmlemeshko Aug 15, 2024
c4cfa24
remove unused arg in alerting_api service
dmlemeshko Aug 15, 2024
5f9ae2c
Merge branch 'main' into slo_burn_rate_deployment_agnostic_tests
dmlemeshko Aug 15, 2024
7dd2649
fix types
dmlemeshko Aug 15, 2024
52ecd8d
Merge branch 'slo_burn_rate_deployment_agnostic_tests' of github.com:…
dmlemeshko Aug 15, 2024
dd8ee61
Merge branch 'main' into slo_burn_rate_deployment_agnostic_tests
dominiqueclarke Aug 20, 2024
ea47dbf
remove unused path
mgiota Aug 20, 2024
0a2b008
configs for deployment agnostic tests
mgiota Aug 20, 2024
91a4511
Merge branch 'main' into slo_burn_rate_deployment_agnostic_tests
dmlemeshko Aug 21, 2024
364eea3
Update x-pack/test/api_integration/deployment_agnostic/services/alert…
mgiota Aug 21, 2024
c3f0329
Merge branch 'main' into slo_burn_rate_deployment_agnostic_tests
elasticmachine Aug 21, 2024
85273a2
better error message
mgiota Aug 21, 2024
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
2 changes: 1 addition & 1 deletion .buildkite/ftr_oblt_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ enabled:
- x-pack/test/observability_ai_assistant_functional/enterprise/config.ts
- x-pack/test/profiling_api_integration/cloud/config.ts
- x-pack/test/functional/apps/apm/config.ts
# stateful config files that run deployment-agnostic tests
# stateful configs that run deployment-agnostic tests
- x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts
4 changes: 3 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,9 @@ x-pack/test/observability_ai_assistant_functional @elastic/obs-ai-assistant
/x-pack/test_serverless/**/test_suites/observability/custom_threshold_rule/ @elastic/obs-ux-management-team
/x-pack/test_serverless/**/test_suites/observability/slos/ @elastic/obs-ux-management-team
/x-pack/test_serverless/api_integration/test_suites/observability/es_query_rule @elastic/obs-ux-management-team
/x-pack/test_serverless/api_integration/test_suites/observability/burn_rate_rule @elastic/obs-ux-management-team
/x-pack/test/api_integration/deployment_agnostic/apis/observability/alerting/burn_rate_rule @elastic/obs-ux-management-team
/x-pack/test/api_integration/deployment_agnostic/services/alerting_api @elastic/obs-ux-management-team
/x-pack/test/api_integration/deployment_agnostic/services/slo_api @elastic/obs-ux-management-team
/x-pack/test_serverless/**/test_suites/observability/infra/ @elastic/obs-ux-infra_services-team

# Elastic Stack Monitoring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,41 @@
* 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 { cleanup, Dataset, generate, PartialConfig } from '@kbn/data-forge';
import { RoleCredentials, InternalRequestHeader } from '@kbn/ftr-common-functional-services';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { InternalRequestHeader, RoleCredentials } from '../../../../shared/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 esDeleteAllIndices = getService('esDeleteAllIndices');
const samlAuth = getService('samlAuth');
const supertestWithoutAuth = getService('supertestWithoutAuth');
const logger = getService('log');
const alertingApi = getService('alertingApi');
const dataViewApi = getService('dataViewApi');
const sloApi = getService('sloApi');
const svlUserManager = getService('svlUserManager');
const svlCommonApi = getService('svlCommonApi');
let roleAuthc: RoleCredentials;
let internalReqHeader: InternalRequestHeader;
const config = getService('config');
const isServerless = config.get('serverless');
const expectedConsumer = isServerless ? 'observability' : 'slo';

describe('Burn rate rule', () => {
const RULE_TYPE_ID = 'slo.rules.burnRate';
const DATA_VIEW = 'kbn-data-forge-fake_hosts.fake_hosts-*';
const RULE_ALERT_INDEX = '.alerts-observability.slo.alerts-default';

const ALERT_ACTION_INDEX = 'alert-action-slo';
const DATA_VIEW_ID = 'data-view-id';
let dataForgeConfig: PartialConfig;
let dataForgeIndices: string[];
let actionId: string;
let ruleId: string;
let adminRoleAuthc: RoleCredentials;
let internalHeaders: InternalRequestHeader;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dominiqueclarke all the api calls are tested with Admin role, just to confirm: these APIs are not available with lower privileges e.g. Editor?

internalHeaders = samlAuth.getInternalRequestHeader();
dataForgeConfig = {
schedule: [
{
Expand All @@ -60,37 +55,49 @@ export default function ({ getService }: FtrProviderContext) {
indexing: { dataset: 'fake_hosts' as Dataset, eventsPerCycle: 1, interval: 10000 },
};
dataForgeIndices = await generate({ client: esClient, config: dataForgeConfig, logger });
await alertingApi.waitForDocumentInIndex({ indexName: DATA_VIEW, docCountTarget: 360 });
await alertingApi.waitForDocumentInIndex({
indexName: DATA_VIEW,
docCountTarget: 360,
});
await dataViewApi.create({
roleAuthc: adminRoleAuthc,
name: DATA_VIEW,
id: DATA_VIEW_ID,
title: DATA_VIEW,
});
roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin');
});

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(internalHeaders);
await supertestWithoutAuth
.delete(`/api/actions/connector/${actionId}`)
.set(adminRoleAuthc.apiKeyHeader)
.set(internalHeaders);
await esClient.deleteByQuery({
index: '.kibana-event-log-*',
query: { term: { 'rule.id': ruleId } },
conflicts: 'proceed',
});
await dataViewApi.delete({
roleAuthc: adminRoleAuthc,
id: DATA_VIEW_ID,
});
await supertest.delete('/api/observability/slos/my-custom-id').set(internalReqHeader);

await supertestWithoutAuth
.delete('/api/observability/slos/my-custom-id')
.set(adminRoleAuthc.apiKeyHeader)
.set(internalHeaders);
await esDeleteAllIndices([ALERT_ACTION_INDEX, ...dataForgeIndices]);
await cleanup({ client: esClient, config: dataForgeConfig, logger });
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: Slo Burn rate API test',
indexName: ALERT_ACTION_INDEX,
});
Expand Down Expand Up @@ -119,13 +126,13 @@ export default function ({ getService }: FtrProviderContext) {
},
groupBy: '*',
},
roleAuthc
adminRoleAuthc
);

const dependencyRule = await alertingApi.createRule({
roleAuthc,
roleAuthc: adminRoleAuthc,
tags: ['observability'],
consumer: 'observability',
consumer: expectedConsumer,
name: 'SLO Burn Rate rule - Dependency',
ruleTypeId: RULE_TYPE_ID,
schedule: {
Expand Down Expand Up @@ -196,9 +203,9 @@ export default function ({ getService }: FtrProviderContext) {
});

const createdRule = await alertingApi.createRule({
roleAuthc,
roleAuthc: adminRoleAuthc,
tags: ['observability'],
consumer: 'observability',
consumer: expectedConsumer,
name: 'SLO Burn Rate rule',
ruleTypeId: RULE_TYPE_ID,
schedule: {
Expand Down Expand Up @@ -279,7 +286,7 @@ export default function ({ getService }: FtrProviderContext) {

it('should be active', async () => {
const executionStatus = await alertingApi.waitForRuleStatus({
roleAuthc,
roleAuthc: adminRoleAuthc,
ruleId,
expectedStatus: 'active',
});
Expand All @@ -299,9 +306,9 @@ export default function ({ getService }: FtrProviderContext) {
});

it('should find the created rule with correct information about the consumer', async () => {
const match = await alertingApi.findRule(roleAuthc, ruleId);
const match = await alertingApi.findRule(ruleId, adminRoleAuthc);
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
@@ -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 { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';

export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) {
describe('Slo - Burn rate rule', () => {
loadTestFile(require.resolve('./burn_rate_rule'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext)
loadTestFile(require.resolve('../../apis/console'));
loadTestFile(require.resolve('../../apis/core'));
loadTestFile(require.resolve('../../apis/painless_lab'));
loadTestFile(require.resolve('../../apis/observability/alerting'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import { DeploymentAgnosticFtrProviderContext } from '../../ftr_provider_context';

export default function ({}: DeploymentAgnosticFtrProviderContext) {
export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) {
describe('apis', () => {
// load new oblt deployment-agnostic test here
loadTestFile(require.resolve('../../apis/observability/alerting'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import { createStatefulTestConfig } from '../../default_configs/stateful.config.
export default createStatefulTestConfig({
testFiles: [require.resolve('./oblt.index.ts')],
junit: {
reportName: 'Observibility Stateful - Deployment-agnostic API Integration Tests',
reportName: 'Stateful Observability - Deployment-agnostic API Integration Tests',
},
});
Loading