Skip to content

Commit

Permalink
[APM] Performance fix for 'cardinality' telemetry task (#144061)
Browse files Browse the repository at this point in the history
* Performance fix for 'cardinality' telemetry task

* Make timeout/index required for telemetry searches

* Fix tests

Co-authored-by: Dario Gieselaar <dario.gieselaar@elastic.co>
  • Loading branch information
Colton Myers and dgieselaar authored Oct 27, 2022
1 parent 756916d commit a5c8ebe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ type ISavedObjectsClient = Pick<SavedObjectsClient, 'find'>;

type TelemetryTaskExecutor = (params: {
indices: ApmIndicesConfig;
search<TSearchRequest extends ESSearchRequest>(
search<
TSearchRequest extends ESSearchRequest & { index: string | string[] } & {
body: { timeout: string };
}
>(
params: TSearchRequest
): Promise<ESSearchResponse<unknown, TSearchRequest>>;
indicesStats(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ describe('data telemetry collection tasks', () => {
}
});

expect(await task?.executor({ search } as any)).toEqual({
expect(await task?.executor({ search, indices } as any)).toEqual({
cardinality: {
client: { geo: { country_iso_code: { rum: { '1d': 5 } } } },
transaction: { name: { all_agents: { '1d': 3 }, rum: { '1d': 1 } } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const tasks: TelemetryTask[] = [
await search({
index: indices.transaction,
body: {
timeout,
query: {
bool: {
filter: [
Expand Down Expand Up @@ -355,6 +356,7 @@ export const tasks: TelemetryTask[] = [
const response = await search({
index: [indices.transaction],
body: {
timeout,
query: {
bool: {
filter: [{ range: { '@timestamp': { gte: 'now-1d' } } }],
Expand Down Expand Up @@ -1032,8 +1034,9 @@ export const tasks: TelemetryTask[] = [
},
{
name: 'cardinality',
executor: async ({ search }) => {
executor: async ({ indices, search }) => {
const allAgentsCardinalityResponse = await search({
index: [indices.transaction],
body: {
size: 0,
timeout,
Expand All @@ -1058,6 +1061,7 @@ export const tasks: TelemetryTask[] = [
});

const rumAgentCardinalityResponse = await search({
index: [indices.transaction],
body: {
size: 0,
timeout,
Expand Down

0 comments on commit a5c8ebe

Please sign in to comment.