Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {
deleteAllRules,
deleteAllAlerts,
waitForRuleFailure,
waitForRulePartialFailure,
routeWithNamespace,
} from '../../../../../../../common/utils/security_solution';
import { FtrProviderContext } from '../../../../../../ftr_provider_context';
Expand Down Expand Up @@ -254,30 +253,30 @@ export default ({ getService }: FtrProviderContext) => {

it('parses shard failures for EQL event query', async () => {
await esArchiver.load(packetBeatPath);
await setBrokenRuntimeField({ es, index: 'packetbeat-*' });

// sometimes we would hit max signals on the good shard
// and never search the shard with the bad runtime field
// by changing the logic to be "and" broken == 1
// we ensure that both shards are searched
// which I believe was the cause of the test being flakey.
const rule: EqlRuleCreateProps = {
...getEqlRuleForAlertTesting(['auditbeat-*', 'packetbeat-*']),
query: 'any where agent.type == "packetbeat" or broken == 1',
query: 'any where agent.type == "packetbeat" and broken == 1',
};
await setBrokenRuntimeField({ es, index: 'auditbeat-*' });
const createdRule = await createRule(supertest, log, rule);
const createdRuleId = createdRule.id;
await waitForRulePartialFailure({ supertest, log, id: createdRuleId });
const route = routeWithNamespace(DETECTION_ENGINE_RULES_URL);
const response = await supertest
.get(route)
.set('kbn-xsrf', 'true')
.set('elastic-api-version', '2023-10-31')
.query({ id: createdRule.id })
.expect(200);

const ruleResponse = response.body;
expect(
ruleResponse.execution_summary.last_execution.message.includes(
'The EQL event query was only executed on the available shards. The query failed to run successfully on the following shards:'
)
).eql(true);

await unsetBrokenRuntimeField({ es, index: 'auditbeat-*' });
const { logs } = await previewRule({ supertest, rule });
expect_(logs).toEqual(
expect_.arrayContaining([
expect_.objectContaining({
warnings: expect_.arrayContaining([
expect_.stringContaining(
'The EQL event query was only executed on the available shards. The query failed to run successfully on the following shards:'
),
]),
}),
])
);
await unsetBrokenRuntimeField({ es, index: 'packetbeat-*' });
await esArchiver.unload(packetBeatPath);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const setBrokenRuntimeField = async ({ es, index }: UpdateMappingsProps)
},
index,
});
await es.indices.refresh({
index,
});
};

export const unsetBrokenRuntimeField = async ({ es, index }: UpdateMappingsProps) => {
Expand All @@ -36,4 +39,7 @@ export const unsetBrokenRuntimeField = async ({ es, index }: UpdateMappingsProps
},
index,
});
await es.indices.refresh({
index,
});
};