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

[Cloud Security] Fix flaky metering tests #197950

Merged
merged 3 commits into from
Oct 29, 2024
Merged
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 @@ -43,8 +43,7 @@ export default function (providerContext: FtrProviderContext) {
The task manager is running by default in security serverless project in the background and sending usage API requests to the usage API.
This test mocks the usage API server and intercepts the usage API request sent by the metering background task manager.
*/
// FLAKY: https://github.com/elastic/kibana/issues/188829
describe.skip('Intercept the usage API request sent by the metering background task manager', function () {
describe('Intercept the usage API request sent by the metering background task manager', function () {
this.tags(['skipMKI']);

let mockUsageApiServer: http.Server;
Expand Down Expand Up @@ -118,16 +117,15 @@ export default function (providerContext: FtrProviderContext) {

let interceptedRequestBody: UsageRecord[] = [];
await retry.try(async () => {
interceptedRequestBody = getInterceptedRequestPayload();
expect(interceptedRequestBody.length).to.greaterThan(0);
if (interceptedRequestBody.length > 0) {
interceptedRequestBody = getInterceptedRequestPayload();
expect(interceptedRequestBody.length).to.greaterThan(0);
const usageSubTypes = interceptedRequestBody.map((record) => record.usage.sub_type);
expect(usageSubTypes).to.contain('cspm');
expect(interceptedRequestBody[0].usage.type).to.be('cloud_security');
expect(interceptedRequestBody[0].usage.quantity).to.be(billableFindings.length);
}
});

expect(interceptedRequestBody[0].usage.type).to.be('cloud_security');
expect(interceptedRequestBody[0].usage.quantity).to.be(billableFindings.length);
});

it('Should intercept usage API request for KSPM', async () => {
Expand Down Expand Up @@ -159,16 +157,15 @@ export default function (providerContext: FtrProviderContext) {
let interceptedRequestBody: UsageRecord[] = [];

await retry.try(async () => {
interceptedRequestBody = getInterceptedRequestPayload();
expect(interceptedRequestBody.length).to.greaterThan(0);
if (interceptedRequestBody.length > 0) {
interceptedRequestBody = getInterceptedRequestPayload();
expect(interceptedRequestBody.length).to.greaterThan(0);
const usageSubTypes = interceptedRequestBody.map((record) => record.usage.sub_type);
expect(usageSubTypes).to.contain('kspm');
expect(interceptedRequestBody[0].usage.type).to.be('cloud_security');
expect(interceptedRequestBody[0].usage.quantity).to.be(billableFindings.length);
}
});

expect(interceptedRequestBody[0].usage.type).to.be('cloud_security');
expect(interceptedRequestBody[0].usage.quantity).to.be(billableFindings.length);
});

it('Should intercept usage API request for CNVM', async () => {
Expand Down Expand Up @@ -199,11 +196,10 @@ export default function (providerContext: FtrProviderContext) {
if (interceptedRequestBody.length > 0) {
const usageSubTypes = interceptedRequestBody.map((record) => record.usage.sub_type);
expect(usageSubTypes).to.contain('cnvm');
expect(interceptedRequestBody[0].usage.type).to.be('cloud_security');
expect(interceptedRequestBody[0].usage.quantity).to.be(billableFindings.length);
}
});

expect(interceptedRequestBody[0].usage.type).to.be('cloud_security');
expect(interceptedRequestBody[0].usage.quantity).to.be(billableFindings.length);
});

it('Should intercept usage API request for Defend for Containers', async () => {
Expand Down Expand Up @@ -237,11 +233,10 @@ export default function (providerContext: FtrProviderContext) {
if (interceptedRequestBody.length > 0) {
const usageSubTypes = interceptedRequestBody.map((record) => record.usage.sub_type);
expect(usageSubTypes).to.contain('cloud_defend');
expect(interceptedRequestBody.length).to.be(blockActionEnabledHeartbeats.length);
expect(interceptedRequestBody[0].usage.type).to.be('cloud_security');
}
});

expect(interceptedRequestBody.length).to.be(blockActionEnabledHeartbeats.length);
expect(interceptedRequestBody[0].usage.type).to.be('cloud_security');
});

it('Should intercept usage API request with all integrations usage records', async () => {
Expand Down Expand Up @@ -329,18 +324,17 @@ export default function (providerContext: FtrProviderContext) {
expect(usageSubTypes).to.contain('kspm');
expect(usageSubTypes).to.contain('cnvm');
expect(usageSubTypes).to.contain('cloud_defend');
const totalUsageQuantity = interceptedRequestBody.reduce(
(acc, record) => acc + record.usage.quantity,
0
);
expect(totalUsageQuantity).to.be(
billableFindingsCSPM.length +
billableFindingsKSPM.length +
billableFindingsCNVM.length +
blockActionEnabledHeartbeats.length
);
});

const totalUsageQuantity = interceptedRequestBody.reduce(
(acc, record) => acc + record.usage.quantity,
0
);
expect(totalUsageQuantity).to.be(
billableFindingsCSPM.length +
billableFindingsKSPM.length +
billableFindingsCNVM.length +
blockActionEnabledHeartbeats.length
);
});
});
}