[APM] Query for service metadata always uses transaction documents (#87622)

* using metrics over transaction index

* addressing PR comments

* addressing PR comments

* addressing PR comments

* removing uiFilters from metadata apis

* addressing PR comments

* addressing PR comments

* removing terminateAfter

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Cauê Marcondes 2021-01-19 09:24:54 +01:00 committed by GitHub
parent a43d609b09
commit f7d9212c34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 75 additions and 71 deletions

View file

@ -33,8 +33,6 @@ exports[`Error CLOUD_REGION 1`] = `"europe-west1"`;
exports[`Error CLS_FIELD 1`] = `undefined`;
exports[`Error CONTAINER 1`] = `undefined`;
exports[`Error CONTAINER_ID 1`] = `undefined`;
exports[`Error DESTINATION_ADDRESS 1`] = `undefined`;
@ -69,6 +67,8 @@ Object {
exports[`Error HOST_NAME 1`] = `"my hostname"`;
exports[`Error HOST_OS_PLATFORM 1`] = `undefined`;
exports[`Error HTTP_REQUEST_METHOD 1`] = `undefined`;
exports[`Error HTTP_RESPONSE_STATUS_CODE 1`] = `undefined`;
@ -246,8 +246,6 @@ exports[`Span CLOUD_REGION 1`] = `"europe-west1"`;
exports[`Span CLS_FIELD 1`] = `undefined`;
exports[`Span CONTAINER 1`] = `undefined`;
exports[`Span CONTAINER_ID 1`] = `undefined`;
exports[`Span DESTINATION_ADDRESS 1`] = `undefined`;
@ -278,6 +276,8 @@ exports[`Span HOST 1`] = `undefined`;
exports[`Span HOST_NAME 1`] = `undefined`;
exports[`Span HOST_OS_PLATFORM 1`] = `undefined`;
exports[`Span HTTP_REQUEST_METHOD 1`] = `undefined`;
exports[`Span HTTP_RESPONSE_STATUS_CODE 1`] = `undefined`;
@ -451,8 +451,6 @@ exports[`Transaction CLOUD_REGION 1`] = `"europe-west1"`;
exports[`Transaction CLS_FIELD 1`] = `undefined`;
exports[`Transaction CONTAINER 1`] = `"container1234567890abcdef"`;
exports[`Transaction CONTAINER_ID 1`] = `"container1234567890abcdef"`;
exports[`Transaction DESTINATION_ADDRESS 1`] = `undefined`;
@ -487,6 +485,8 @@ Object {
exports[`Transaction HOST_NAME 1`] = `"my hostname"`;
exports[`Transaction HOST_OS_PLATFORM 1`] = `undefined`;
exports[`Transaction HTTP_REQUEST_METHOD 1`] = `"GET"`;
exports[`Transaction HTTP_RESPONSE_STATUS_CODE 1`] = `200`;

View file

@ -108,7 +108,7 @@ export const LABEL_NAME = 'labels.name';
export const HOST = 'host';
export const HOST_NAME = 'host.hostname';
export const CONTAINER = 'container.id';
export const HOST_OS_PLATFORM = 'host.os.platform';
export const CONTAINER_ID = 'container.id';
export const KUBERNETES = 'kubernetes';
export const POD_NAME = 'kubernetes.pod.name';

View file

@ -56,7 +56,6 @@ interface PopoverItem {
export function ServiceIcons({ serviceName }: Props) {
const {
urlParams: { start, end },
uiFilters,
} = useUrlParams();
const [
selectedIconPopover,
@ -70,12 +69,12 @@ export function ServiceIcons({ serviceName }: Props) {
endpoint: 'GET /api/apm/services/{serviceName}/metadata/icons',
params: {
path: { serviceName },
query: { start, end, uiFilters: JSON.stringify(uiFilters) },
query: { start, end },
},
});
}
},
[serviceName, start, end, uiFilters]
[serviceName, start, end]
);
const { data: details, status: detailsFetchStatus } = useFetcher(
@ -86,12 +85,12 @@ export function ServiceIcons({ serviceName }: Props) {
endpoint: 'GET /api/apm/services/{serviceName}/metadata/details',
params: {
path: { serviceName },
query: { start, end, uiFilters: JSON.stringify(uiFilters) },
query: { start, end },
},
});
}
},
[selectedIconPopover, serviceName, start, end, uiFilters]
[selectedIconPopover, serviceName, start, end]
);
const isLoading = !icons && iconsFetchStatus === FETCH_STATUS.LOADING;

View file

@ -4,26 +4,27 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { ProcessorEvent } from '../../../common/processor_event';
import { SortOptions } from '../../../../../typings/elasticsearch';
import {
AGENT,
CLOUD,
CLOUD_AVAILABILITY_ZONE,
CLOUD_MACHINE_TYPE,
CONTAINER,
CONTAINER_ID,
HOST,
KUBERNETES,
PROCESSOR_EVENT,
SERVICE,
SERVICE_NAME,
SERVICE_NODE_NAME,
SERVICE_VERSION,
} from '../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../common/processor_event';
import { ContainerType } from '../../../common/service_metadata';
import { rangeFilter } from '../../../common/utils/range_filter';
import { TransactionRaw } from '../../../typings/es_schemas/raw/transaction_raw';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { should } from './get_service_metadata_icons';
type ServiceMetadataDetailsRaw = Pick<
TransactionRaw,
@ -60,34 +61,32 @@ interface ServiceMetadataDetails {
export async function getServiceMetadataDetails({
serviceName,
setup,
searchAggregatedTransactions,
}: {
serviceName: string;
setup: Setup & SetupTimeRange;
searchAggregatedTransactions: boolean;
}): Promise<ServiceMetadataDetails> {
const { start, end, apmEventClient } = setup;
const filter = [
{ term: { [SERVICE_NAME]: serviceName } },
{ term: { [PROCESSOR_EVENT]: ProcessorEvent.transaction } },
{ range: rangeFilter(start, end) },
...setup.esFilter,
];
const should = [
{ exists: { field: CONTAINER } },
{ exists: { field: KUBERNETES } },
{ exists: { field: CLOUD } },
{ exists: { field: HOST } },
{ exists: { field: AGENT } },
];
const params = {
apm: {
events: [ProcessorEvent.transaction],
events: [
getProcessorEventForAggregatedTransactions(
searchAggregatedTransactions
),
ProcessorEvent.error,
ProcessorEvent.metric,
],
},
body: {
size: 1,
_source: [SERVICE, AGENT, HOST, CONTAINER, KUBERNETES, CLOUD],
_source: [SERVICE, AGENT, HOST, CONTAINER_ID, KUBERNETES, CLOUD],
query: { bool: { filter, should } },
aggs: {
serviceVersions: {

View file

@ -4,18 +4,20 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { ProcessorEvent } from '../../../common/processor_event';
import {
AGENT_NAME,
CLOUD_PROVIDER,
CONTAINER_ID,
KUBERNETES,
PROCESSOR_EVENT,
SERVICE_NAME,
POD_NAME,
HOST_OS_PLATFORM,
} from '../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../common/processor_event';
import { ContainerType } from '../../../common/service_metadata';
import { rangeFilter } from '../../../common/utils/range_filter';
import { TransactionRaw } from '../../../typings/es_schemas/raw/transaction_raw';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
type ServiceMetadataIconsRaw = Pick<
@ -29,31 +31,44 @@ interface ServiceMetadataIcons {
cloudProvider?: string;
}
export const should = [
{ exists: { field: CONTAINER_ID } },
{ exists: { field: POD_NAME } },
{ exists: { field: CLOUD_PROVIDER } },
{ exists: { field: HOST_OS_PLATFORM } },
{ exists: { field: AGENT_NAME } },
];
export async function getServiceMetadataIcons({
serviceName,
setup,
searchAggregatedTransactions,
}: {
serviceName: string;
setup: Setup & SetupTimeRange;
searchAggregatedTransactions: boolean;
}): Promise<ServiceMetadataIcons> {
const { start, end, apmEventClient } = setup;
const filter = [
{ term: { [SERVICE_NAME]: serviceName } },
{ term: { [PROCESSOR_EVENT]: ProcessorEvent.transaction } },
{ range: rangeFilter(start, end) },
...setup.esFilter,
];
const params = {
apm: {
events: [ProcessorEvent.transaction],
events: [
getProcessorEventForAggregatedTransactions(
searchAggregatedTransactions
),
ProcessorEvent.error,
ProcessorEvent.metric,
],
},
terminateAfter: 1,
body: {
size: 1,
_source: [KUBERNETES, CLOUD_PROVIDER, CONTAINER_ID, AGENT_NAME],
query: { bool: { filter } },
query: { bool: { filter, should } },
},
};

View file

@ -52,14 +52,22 @@ export const serviceMetadataDetailsRoute = createRoute({
endpoint: 'GET /api/apm/services/{serviceName}/metadata/details',
params: t.type({
path: t.type({ serviceName: t.string }),
query: t.intersection([uiFiltersRt, rangeRt]),
query: rangeRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName } = context.params.path;
return getServiceMetadataDetails({ serviceName, setup });
const searchAggregatedTransactions = await getSearchAggregatedTransactions(
setup
);
return getServiceMetadataDetails({
serviceName,
setup,
searchAggregatedTransactions,
});
},
});
@ -67,14 +75,22 @@ export const serviceMetadataIconsRoute = createRoute({
endpoint: 'GET /api/apm/services/{serviceName}/metadata/icons',
params: t.type({
path: t.type({ serviceName: t.string }),
query: t.intersection([uiFiltersRt, rangeRt]),
query: rangeRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName } = context.params.path;
return getServiceMetadataIcons({ serviceName, setup });
const searchAggregatedTransactions = await getSearchAggregatedTransactions(
setup
);
return getServiceMetadataIcons({
serviceName,
setup,
searchAggregatedTransactions,
});
},
});

View file

@ -165,14 +165,14 @@ export default function featureControlsTests({ getService }: FtrProviderContext)
},
{
req: {
url: `/api/apm/services/foo/metadata/details?start=${start}&end=${end}&uiFilters=%7B%7D`,
url: `/api/apm/services/foo/metadata/details?start=${start}&end=${end}`,
},
expectForbidden: expect403,
expectResponse: expect200,
},
{
req: {
url: `/api/apm/services/foo/metadata/icons?start=${start}&end=${end}&uiFilters=%7B%7D`,
url: `/api/apm/services/foo/metadata/icons?start=${start}&end=${end}`,
},
expectForbidden: expect403,
expectResponse: expect200,

View file

@ -22,11 +22,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const response = await supertest.get(
url.format({
pathname: `/api/apm/services/opbeans-java/metadata/details`,
query: {
start,
end,
uiFilters: '{}',
},
query: { start, end },
})
);
@ -43,11 +39,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const response = await supertest.get(
url.format({
pathname: `/api/apm/services/opbeans-java/metadata/details`,
query: {
start,
end,
uiFilters: '{}',
},
query: { start, end },
})
);
@ -67,7 +59,6 @@ export default function ApiTest({ getService }: FtrProviderContext) {
"name": "java",
"version": "1.19.1-SNAPSHOT.null",
},
"framework": "Servlet API",
"runtime": Object {
"name": "Java",
"version": "11.0.9.1",
@ -84,11 +75,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const response = await supertest.get(
url.format({
pathname: `/api/apm/services/opbeans-python/metadata/details`,
query: {
start,
end,
uiFilters: '{}',
},
query: { start, end },
})
);

View file

@ -22,11 +22,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const response = await supertest.get(
url.format({
pathname: `/api/apm/services/opbeans-java/metadata/icons`,
query: {
start,
end,
uiFilters: '{}',
},
query: { start, end },
})
);
@ -43,11 +39,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const response = await supertest.get(
url.format({
pathname: `/api/apm/services/opbeans-java/metadata/icons`,
query: {
start,
end,
uiFilters: '{}',
},
query: { start, end },
})
);
@ -65,11 +57,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const response = await supertest.get(
url.format({
pathname: `/api/apm/services/opbeans-python/metadata/icons`,
query: {
start,
end,
uiFilters: '{}',
},
query: { start, end },
})
);