Skip to content

Commit

Permalink
[eem] _count guards against no valid sources (elastic#204224)
Browse files Browse the repository at this point in the history
The query generation expects at least 1 source to be passed
  • Loading branch information
klacabane authored Dec 14, 2024
1 parent 7e4e859 commit 9a8ed0d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export class EntityClient {
errors: results.filter(isRejectedResult).map((result) => result.reason.message as string),
}));

if (validSources.length === 0) {
return { type, value: 0, errors };
}

const { query, filter } = getEntityCountQuery({
sources: validSources,
filters,
Expand Down
43 changes: 42 additions & 1 deletion x-pack/test/api_integration/apis/entity_manager/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export default function ({ getService }: FtrProviderContext) {
});
});

it('is resilient to invalid sources', async () => {
it('is resilient to partially valid sources', async () => {
await createEntityTypeDefinition(supertest, {
type: { id: 'chumble', display_name: 'chumble' },
});
Expand Down Expand Up @@ -417,5 +417,46 @@ export default function ({ getService }: FtrProviderContext) {
],
});
});

it('is resilient to no valid sources', async () => {
await createEntityTypeDefinition(supertest, {
type: { id: 'chumble', display_name: 'chumble' },
});
await Promise.all([
createEntitySourceDefinition(supertest, {
source: {
id: 'source1-with-chumbles',
type_id: 'chumble',
index_patterns: ['index-1-with-chumbles'],
identity_fields: ['service.name'],
metadata_fields: [],
filters: [],
},
}),
createEntitySourceDefinition(supertest, {
source: {
id: 'source2-with-chumbles',
type_id: 'chumble',
index_patterns: ['index-2-with-chumbles'],
identity_fields: ['service.name'],
metadata_fields: [],
filters: [],
},
}),
]);

const result = await countEntities(supertest, {}, 200);

expect(result).toEqual({
total: 0,
types: {
chumble: 0,
},
errors: [
'No index found for source [source: source1-with-chumbles, type: chumble] with index patterns [index-1-with-chumbles]',
'No index found for source [source: source2-with-chumbles, type: chumble] with index patterns [index-2-with-chumbles]',
],
});
});
});
}

0 comments on commit 9a8ed0d

Please sign in to comment.