Skip to content

Commit

Permalink
[EEM] Add limits to ES|QL queries (elastic#209247)
Browse files Browse the repository at this point in the history
To suppress deprecation warnings in Kibana logs.
  • Loading branch information
miltonhultgren authored Feb 3, 2025
1 parent 1d1599e commit 73d46c7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function storeSourceDefinition({

const sources = await runESQLQuery('fetch source definition for conflict check', {
esClient,
query: `FROM ${DEFINITIONS_ALIAS} METADATA _id | WHERE definition_type == "source" AND _id == "${source.type_id}:${source.id}" | KEEP _id`,
query: `FROM ${DEFINITIONS_ALIAS} METADATA _id | WHERE definition_type == "source" AND _id == "${source.type_id}:${source.id}" | KEEP _id | LIMIT 1000`,
logger,
});

Expand Down Expand Up @@ -88,7 +88,7 @@ export async function readSourceDefinitions(
'fetch all source definitions',
{
esClient,
query: `FROM ${DEFINITIONS_ALIAS} METADATA _source | WHERE definition_type == "source" ${typeFilter} | KEEP _source`,
query: `FROM ${DEFINITIONS_ALIAS} METADATA _source | WHERE definition_type == "source" ${typeFilter} | KEEP _source | LIMIT 1000`,
logger,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function storeTypeDefinition({

const types = await runESQLQuery('fetch type definition for conflict check', {
esClient,
query: `FROM ${DEFINITIONS_ALIAS} METADATA _id | WHERE definition_type == "type" AND _id == "${type.id}" | KEEP _id`,
query: `FROM ${DEFINITIONS_ALIAS} METADATA _id | WHERE definition_type == "type" AND _id == "${type.id}" | KEEP _id | LIMIT 1000`,
logger,
});

Expand Down Expand Up @@ -65,7 +65,7 @@ export async function readTypeDefinitions(
'fetch all type definitions',
{
esClient,
query: `FROM ${DEFINITIONS_ALIAS} METADATA _source | WHERE definition_type == "type" | KEEP _source`,
query: `FROM ${DEFINITIONS_ALIAS} METADATA _source | WHERE definition_type == "type" | KEEP _source | LIMIT 1000`,
logger,
}
);
Expand All @@ -84,7 +84,7 @@ export async function readTypeDefinitionById(
'fetch type definition by ID',
{
esClient,
query: `FROM ${DEFINITIONS_ALIAS} METADATA _id,_source | WHERE definition_type == "type" AND _id == "${id}" | KEEP _source`,
query: `FROM ${DEFINITIONS_ALIAS} METADATA _id,_source | WHERE definition_type == "type" AND _id == "${id}" | KEEP _source | LIMIT 1000`,
logger,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ describe('getEntityCountQuery', () => {
end: '2024-11-20T20:00:00.000Z',
});

expect(query).toEqual('FROM logs-* | STATS BY service.name::keyword | STATS count = COUNT()');
expect(query).toEqual(
'FROM logs-* | STATS BY service.name::keyword | STATS count = COUNT() | LIMIT 1000'
);

expect(filter).toEqual({
bool: {
Expand Down Expand Up @@ -147,7 +149,8 @@ describe('getEntityCountQuery', () => {
'EVAL entity.id = CASE(is_source_0, service_name::keyword, is_source_1, service.name::keyword) | ' +
'WHERE entity.id IS NOT NULL | ' +
'STATS BY entity.id | ' +
'STATS count = COUNT()'
'STATS count = COUNT() | ' +
'LIMIT 1000'
);

expect(filter).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export function getEntityCountQuery({
idEvalCommand({ sources }),
whereCommand({ sources }),
statsCommand({ sources }),
`LIMIT 1000`,
]);

const filter = dslFilter({ sources, filters, start, end });
Expand Down

0 comments on commit 73d46c7

Please sign in to comment.