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

[FTR] Collapse Alerting API Helpers Impl #192216

Merged
merged 18 commits into from
Sep 16, 2024
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
2 changes: 1 addition & 1 deletion packages/kbn-ftr-common-functional-services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { KibanaServerProvider } from './services/kibana_server';
export { KibanaServerProvider } from './services/kibana_server';
export type KibanaServer = ProvidedType<typeof KibanaServerProvider>;

export { RetryService } from './services/retry';
export { RetryService, type TryWithRetriesOptions } from './services/retry';

import { EsArchiverProvider } from './services/es_archiver';
export type EsArchiver = ProvidedType<typeof EsArchiverProvider>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { RetryService } from './retry';
export { RetryService, type TryWithRetriesOptions } from './retry';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FtrService } from '../ftr_provider_context';
import { retryForSuccess } from './retry_for_success';
import { retryForTruthy } from './retry_for_truthy';

interface TryWithRetriesOptions {
export interface TryWithRetriesOptions {
retryCount: number;
retryDelay?: number;
timeout?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function retryForSuccess<T>(log: ToolingLog, options: Options<T>) {
if (lastError && onFailureBlock) {
const before = await runAttempt(onFailureBlock);
if ('error' in before) {
log.debug(`--- onRetryBlock error: ${before.error.message}`);
log.debug(`--- onRetryBlock error: ${before.error.message} - Attempt #: ${attemptCounter}`);
Copy link
Member

Choose a reason for hiding this comment

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

Could you share a before vs. after snapshot of logs to better understand how the failure will look like?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add it to the description!

}
}

Expand All @@ -104,9 +104,13 @@ export async function retryForSuccess<T>(log: ToolingLog, options: Options<T>) {

if ('error' in attempt) {
if (lastError && lastError.message === attempt.error.message) {
log.debug(`--- ${methodName} failed again with the same message...`);
log.debug(
`--- ${methodName} failed again with the same message... - Attempt #: ${attemptCounter}`
);
} else {
log.debug(`--- ${methodName} error: ${attempt.error.message}`);
log.debug(
`--- ${methodName} error: ${attempt.error.message} - Attempt #: ${attemptCounter}`
);
}

lastError = attempt.error;
Expand Down
176 changes: 0 additions & 176 deletions x-pack/test_serverless/api_integration/services/alerting_api.ts

This file was deleted.

2 changes: 0 additions & 2 deletions x-pack/test_serverless/api_integration/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { GenericFtrProviderContext } from '@kbn/test';
import { services as deploymentAgnosticSharedServices } from '../../shared/services/deployment_agnostic_services';
import { services as svlSharedServices } from '../../shared/services';

import { AlertingApiProvider } from './alerting_api';
import { SamlToolsProvider } from './saml_tools';
import { SvlCasesServiceProvider } from './svl_cases';
import { SloApiProvider } from './slo_api';
Expand All @@ -35,7 +34,6 @@ export const services = {

// serverless FTR services
...svlSharedServices,
alertingApi: AlertingApiProvider,
samlTools: SamlToolsProvider,
svlCases: SvlCasesServiceProvider,
sloApi: SloApiProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,18 @@ import {
ALERT_PREVIOUS_ACTION_GROUP,
} from '@kbn/rule-data-utils';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { createEsQueryRule } from './helpers/alerting_api_helper';
import { waitForAlertInIndex, waitForNumRuleRuns } from './helpers/alerting_wait_for_helpers';
import { ObjectRemover } from '../../../../shared/lib';
import { InternalRequestHeader, RoleCredentials } from '../../../../shared/services';
import { RoleCredentials } from '../../../../shared/services';

const OPEN_OR_ACTIVE = new Set(['open', 'active']);

export default function ({ getService }: FtrProviderContext) {
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
const supertestWithoutAuth = getService('supertestWithoutAuth');
let roleAdmin: RoleCredentials;
let internalReqHeader: InternalRequestHeader;
const supertest = getService('supertest');
const esClient = getService('es');
const objectRemover = new ObjectRemover(supertest);
const alertingApi = getService('alertingApi');

describe('Alert documents', function () {
// Timeout of 360000ms exceeded
Expand All @@ -68,7 +64,6 @@ export default function ({ getService }: FtrProviderContext) {

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

afterEach(async () => {
Expand All @@ -80,10 +75,8 @@ export default function ({ getService }: FtrProviderContext) {
});

it('should generate an alert document for an active alert', async () => {
const createdRule = await createEsQueryRule({
supertestWithoutAuth,
const createdRule = await alertingApi.helpers.createEsQueryRule({
roleAuthc: roleAdmin,
internalReqHeader,
consumer: 'alerts',
name: 'always fire',
ruleTypeId: RULE_TYPE_ID,
Expand All @@ -103,17 +96,15 @@ export default function ({ getService }: FtrProviderContext) {

// get the first alert document written
const testStart1 = new Date();
await waitForNumRuleRuns({
supertestWithoutAuth,
await alertingApi.helpers.waitForNumRuleRuns({
roleAuthc: roleAdmin,
internalReqHeader,
numOfRuns: 1,
ruleId,
esClient,
testStart: testStart1,
});

const alResp1 = await waitForAlertInIndex({
const alResp1 = await alertingApi.helpers.waitForAlertInIndex({
esClient,
filter: testStart1,
indexName: ALERT_INDEX,
Expand Down Expand Up @@ -206,10 +197,8 @@ export default function ({ getService }: FtrProviderContext) {
});

it('should update an alert document for an ongoing alert', async () => {
const createdRule = await createEsQueryRule({
supertestWithoutAuth,
const createdRule = await alertingApi.helpers.createEsQueryRule({
roleAuthc: roleAdmin,
internalReqHeader,
consumer: 'alerts',
name: 'always fire',
ruleTypeId: RULE_TYPE_ID,
Expand All @@ -229,17 +218,15 @@ export default function ({ getService }: FtrProviderContext) {

// get the first alert document written
const testStart1 = new Date();
await waitForNumRuleRuns({
supertestWithoutAuth,
await alertingApi.helpers.waitForNumRuleRuns({
roleAuthc: roleAdmin,
internalReqHeader,
numOfRuns: 1,
ruleId,
esClient,
testStart: testStart1,
});

const alResp1 = await waitForAlertInIndex({
const alResp1 = await alertingApi.helpers.waitForAlertInIndex({
esClient,
filter: testStart1,
indexName: ALERT_INDEX,
Expand All @@ -249,17 +236,15 @@ export default function ({ getService }: FtrProviderContext) {

// wait for another run, get the updated alert document
const testStart2 = new Date();
await waitForNumRuleRuns({
supertestWithoutAuth,
await alertingApi.helpers.waitForNumRuleRuns({
roleAuthc: roleAdmin,
internalReqHeader,
numOfRuns: 1,
ruleId,
esClient,
testStart: testStart2,
});

const alResp2 = await waitForAlertInIndex({
const alResp2 = await alertingApi.helpers.waitForAlertInIndex({
esClient,
filter: testStart2,
indexName: ALERT_INDEX,
Expand Down
Loading