Skip to content

Commit 17f2dba

Browse files
rylnddhurley14kibanamachine
authored
[8.19] [Security Solution] [Detections] Fix flakey EQL shard test (#215757) (#233535)
# Backport This will backport the following commits from `main` to `8.19`: - [[Security Solution] [Detections] Fix flakey EQL shard test (#215757)](#215757) Closes #209024; details can be found there. <!--- Backport version: 10.0.1 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Devin W. Hurley","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-03-28T18:47:15Z","message":"[Security Solution] [Detections] Fix flakey EQL shard test (#215757)\n\n## Summary\n\nRef: https://github.com/elastic/kibana/issues/209024\n\nFlake caused by occasionally hitting max signals on the \"good\" shard and\nnever triggering the error from the runtime field on the \"bad\" shard. By\nmoving the bad runtime field to the `packetbeat` index and changing the\nrule query in the test to an `and` we can ensure the rule queries both\ngood and bad shards.\n\n### Checklist\n\n- [x] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed","sha":"d869d472f0b9b55c635580c4d7d15faff8b8c215","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["review","release_note:skip","v9.0.0","Team:Detection Engine","backport:version","v9.1.0","v9.0.1"],"title":"[Security Solution] [Detections] Fix flakey EQL shard test","number":215757,"url":"https://github.com/elastic/kibana/pull/215757","mergeCommit":{"message":"[Security Solution] [Detections] Fix flakey EQL shard test (#215757)\n\n## Summary\n\nRef: https://github.com/elastic/kibana/issues/209024\n\nFlake caused by occasionally hitting max signals on the \"good\" shard and\nnever triggering the error from the runtime field on the \"bad\" shard. By\nmoving the bad runtime field to the `packetbeat` index and changing the\nrule query in the test to an `and` we can ensure the rule queries both\ngood and bad shards.\n\n### Checklist\n\n- [x] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed","sha":"d869d472f0b9b55c635580c4d7d15faff8b8c215"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/216375","number":216375,"state":"MERGED","mergeCommit":{"sha":"a2002e0bd3692dd9dfeca80d0dbc38dd3a2af18a","message":"[9.0] [Security Solution] [Detections] Fix flakey EQL shard test (#215757) (#216375)\n\n# Backport\n\nThis will backport the following commits from `main` to `9.0`:\n- [[Security Solution] [Detections] Fix flakey EQL shard test\n(#215757)](https://github.com/elastic/kibana/pull/215757)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n"}},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215757","number":215757,"mergeCommit":{"message":"[Security Solution] [Detections] Fix flakey EQL shard test (#215757)\n\n## Summary\n\nRef: https://github.com/elastic/kibana/issues/209024\n\nFlake caused by occasionally hitting max signals on the \"good\" shard and\nnever triggering the error from the runtime field on the \"bad\" shard. By\nmoving the bad runtime field to the `packetbeat` index and changing the\nrule query in the test to an `and` we can ensure the rule queries both\ngood and bad shards.\n\n### Checklist\n\n- [x] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed","sha":"d869d472f0b9b55c635580c4d7d15faff8b8c215"}}]}] BACKPORT--> --------- Co-authored-by: Devin W. Hurley <[email protected]> Co-authored-by: kibanamachine <[email protected]>
1 parent ee692db commit 17f2dba

File tree

2 files changed

+27
-22
lines changed
  • x-pack/test/security_solution_api_integration/test_suites/detections_response
    • detection_engine/rule_execution_logic/eql/trial_license_complete_tier
    • utils

2 files changed

+27
-22
lines changed

x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/rule_execution_logic/eql/trial_license_complete_tier/eql.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import {
5454
deleteAllRules,
5555
deleteAllAlerts,
5656
waitForRuleFailure,
57-
waitForRulePartialFailure,
5857
routeWithNamespace,
5958
} from '../../../../../../../common/utils/security_solution';
6059
import { FtrProviderContext } from '../../../../../../ftr_provider_context';
@@ -254,30 +253,30 @@ export default ({ getService }: FtrProviderContext) => {
254253

255254
it('parses shard failures for EQL event query', async () => {
256255
await esArchiver.load(packetBeatPath);
256+
await setBrokenRuntimeField({ es, index: 'packetbeat-*' });
257+
258+
// sometimes we would hit max signals on the good shard
259+
// and never search the shard with the bad runtime field
260+
// by changing the logic to be "and" broken == 1
261+
// we ensure that both shards are searched
262+
// which I believe was the cause of the test being flakey.
257263
const rule: EqlRuleCreateProps = {
258264
...getEqlRuleForAlertTesting(['auditbeat-*', 'packetbeat-*']),
259-
query: 'any where agent.type == "packetbeat" or broken == 1',
265+
query: 'any where agent.type == "packetbeat" and broken == 1',
260266
};
261-
await setBrokenRuntimeField({ es, index: 'auditbeat-*' });
262-
const createdRule = await createRule(supertest, log, rule);
263-
const createdRuleId = createdRule.id;
264-
await waitForRulePartialFailure({ supertest, log, id: createdRuleId });
265-
const route = routeWithNamespace(DETECTION_ENGINE_RULES_URL);
266-
const response = await supertest
267-
.get(route)
268-
.set('kbn-xsrf', 'true')
269-
.set('elastic-api-version', '2023-10-31')
270-
.query({ id: createdRule.id })
271-
.expect(200);
272-
273-
const ruleResponse = response.body;
274-
expect(
275-
ruleResponse.execution_summary.last_execution.message.includes(
276-
'The EQL event query was only executed on the available shards. The query failed to run successfully on the following shards:'
277-
)
278-
).eql(true);
279-
280-
await unsetBrokenRuntimeField({ es, index: 'auditbeat-*' });
267+
const { logs } = await previewRule({ supertest, rule });
268+
expect_(logs).toEqual(
269+
expect_.arrayContaining([
270+
expect_.objectContaining({
271+
warnings: expect_.arrayContaining([
272+
expect_.stringContaining(
273+
'The EQL event query was only executed on the available shards. The query failed to run successfully on the following shards:'
274+
),
275+
]),
276+
}),
277+
])
278+
);
279+
await unsetBrokenRuntimeField({ es, index: 'packetbeat-*' });
281280
await esArchiver.unload(packetBeatPath);
282281
});
283282

x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/runtime.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export const setBrokenRuntimeField = async ({ es, index }: UpdateMappingsProps)
2525
},
2626
index,
2727
});
28+
await es.indices.refresh({
29+
index,
30+
});
2831
};
2932

3033
export const unsetBrokenRuntimeField = async ({ es, index }: UpdateMappingsProps) => {
@@ -36,4 +39,7 @@ export const unsetBrokenRuntimeField = async ({ es, index }: UpdateMappingsProps
3639
},
3740
index,
3841
});
42+
await es.indices.refresh({
43+
index,
44+
});
3945
};

0 commit comments

Comments
 (0)