2019-08-15 10:53:20 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
2020-10-02 09:45:50 +02:00
|
|
|
import { Setup, SetupTimeRange } from '../../server/lib/helpers/setup_request';
|
2019-10-15 13:30:51 +02:00
|
|
|
import {
|
|
|
|
SERVICE_NAME,
|
2020-05-22 09:08:58 +02:00
|
|
|
SERVICE_NODE_NAME,
|
2020-07-31 15:22:04 +02:00
|
|
|
} from '../../common/elasticsearch_fieldnames';
|
|
|
|
import { rangeFilter } from '../../common/utils/range_filter';
|
|
|
|
import { SERVICE_NODE_NAME_MISSING } from '../../common/service_nodes';
|
|
|
|
import { ProcessorEvent } from '../../common/processor_event';
|
2019-10-15 13:30:51 +02:00
|
|
|
|
|
|
|
function getServiceNodeNameFilters(serviceNodeName?: string) {
|
|
|
|
if (!serviceNodeName) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serviceNodeName === SERVICE_NODE_NAME_MISSING) {
|
|
|
|
return [{ bool: { must_not: [{ exists: { field: SERVICE_NODE_NAME } }] } }];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [{ term: { [SERVICE_NODE_NAME]: serviceNodeName } }];
|
|
|
|
}
|
2019-08-15 10:53:20 +02:00
|
|
|
|
|
|
|
export function getMetricsProjection({
|
|
|
|
setup,
|
2019-10-03 17:41:45 +02:00
|
|
|
serviceName,
|
2020-05-22 09:08:58 +02:00
|
|
|
serviceNodeName,
|
2019-08-15 10:53:20 +02:00
|
|
|
}: {
|
2020-10-02 09:45:50 +02:00
|
|
|
setup: Setup & SetupTimeRange;
|
2019-08-15 10:53:20 +02:00
|
|
|
serviceName: string;
|
2019-10-03 17:41:45 +02:00
|
|
|
serviceNodeName?: string;
|
2019-08-15 10:53:20 +02:00
|
|
|
}) {
|
2020-10-02 09:45:50 +02:00
|
|
|
const { start, end, esFilter } = setup;
|
2019-08-15 10:53:20 +02:00
|
|
|
|
2019-10-15 13:30:51 +02:00
|
|
|
const filter = [
|
|
|
|
{ term: { [SERVICE_NAME]: serviceName } },
|
|
|
|
{ range: rangeFilter(start, end) },
|
|
|
|
...getServiceNodeNameFilters(serviceNodeName),
|
2020-10-02 09:45:50 +02:00
|
|
|
...esFilter,
|
2019-10-15 13:30:51 +02:00
|
|
|
];
|
2019-10-03 17:41:45 +02:00
|
|
|
|
2019-08-15 10:53:20 +02:00
|
|
|
return {
|
2020-07-31 15:22:04 +02:00
|
|
|
apm: {
|
|
|
|
events: [ProcessorEvent.metric],
|
|
|
|
},
|
2019-08-15 10:53:20 +02:00
|
|
|
body: {
|
|
|
|
query: {
|
|
|
|
bool: {
|
2020-05-22 09:08:58 +02:00
|
|
|
filter,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-08-15 10:53:20 +02:00
|
|
|
};
|
|
|
|
}
|