Skip to content

Commit

Permalink
[APM] Logs tab seems to show logs from incorrect service(s) (#110484)
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes authored Aug 30, 2021
1 parent 30f1974 commit a165067
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { getInfrastructureKQLFilter } from './';

describe('service logs', () => {
describe('getInfrastructureKQLFilter', () => {
it('filter by container id', () => {
expect(
getInfrastructureKQLFilter({
serviceInfrastructure: {
containerIds: ['foo', 'bar'],
hostNames: ['baz', `quz`],
},
})
).toEqual('container.id: "foo" or container.id: "bar"');
});
it('filter by host names', () => {
expect(
getInfrastructureKQLFilter({
serviceInfrastructure: {
containerIds: [],
hostNames: ['baz', `quz`],
},
})
).toEqual('host.name: "baz" or host.name: "quz"');
});
});
});
17 changes: 7 additions & 10 deletions x-pack/plugins/apm/public/components/app/service_logs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { APIReturnType } from '../../../services/rest/createCallApmApi';
import {
CONTAINER_ID,
HOSTNAME,
POD_NAME,
} from '../../../../common/elasticsearch_fieldnames';
import { useApmParams } from '../../../hooks/use_apm_params';
import { useTimeRange } from '../../../hooks/use_time_range';
Expand Down Expand Up @@ -55,8 +54,7 @@ export function ServiceLogs() {
const noInfrastructureData = useMemo(() => {
return (
isEmpty(data?.serviceInfrastructure?.containerIds) &&
isEmpty(data?.serviceInfrastructure?.hostNames) &&
isEmpty(data?.serviceInfrastructure?.podNames)
isEmpty(data?.serviceInfrastructure?.hostNames)
);
}, [data]);

Expand Down Expand Up @@ -93,16 +91,15 @@ export function ServiceLogs() {
);
}

const getInfrastructureKQLFilter = (
export const getInfrastructureKQLFilter = (
data?: APIReturnType<'GET /api/apm/services/{serviceName}/infrastructure'>
) => {
const containerIds = data?.serviceInfrastructure?.containerIds ?? [];
const hostNames = data?.serviceInfrastructure?.hostNames ?? [];
const podNames = data?.serviceInfrastructure?.podNames ?? [];

return [
...containerIds.map((id) => `${CONTAINER_ID}: "${id}"`),
...hostNames.map((id) => `${HOSTNAME}: "${id}"`),
...podNames.map((id) => `${POD_NAME}: "${id}"`),
].join(' or ');
const kqlFilter = containerIds.length
? containerIds.map((id) => `${CONTAINER_ID}: "${id}"`)
: hostNames.map((id) => `${HOSTNAME}: "${id}"`);

return kqlFilter.join(' or ');
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
SERVICE_NAME,
CONTAINER_ID,
HOSTNAME,
POD_NAME,
} from '../../../common/elasticsearch_fieldnames';

export const getServiceInfrastructure = async ({
Expand Down Expand Up @@ -61,26 +60,18 @@ export const getServiceInfrastructure = async ({
size: 500,
},
},
podNames: {
terms: {
field: POD_NAME,
size: 500,
},
},
},
},
});

return {
containerIds:
response.aggregations?.containerIds?.buckets.map(
(bucket) => bucket.key
(bucket) => bucket.key as string
) ?? [],
hostNames:
response.aggregations?.hostNames?.buckets.map((bucket) => bucket.key) ??
[],
podNames:
response.aggregations?.podNames?.buckets.map((bucket) => bucket.key) ??
[],
response.aggregations?.hostNames?.buckets.map(
(bucket) => bucket.key as string
) ?? [],
};
};

0 comments on commit a165067

Please sign in to comment.