mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[APM] Add termQuery
helper (#117655)
This commit is contained in:
parent
14287912e2
commit
27f127d581
19 changed files with 126 additions and 220 deletions
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { rangeQuery } from '../../../../../observability/server';
|
||||
import { rangeQuery, termQuery } from '../../../../../observability/server';
|
||||
import {
|
||||
SERVICE_NAME,
|
||||
TRANSACTION_TYPE,
|
||||
|
@ -46,10 +46,8 @@ export async function getTransactionDurationChartPreview({
|
|||
const query = {
|
||||
bool: {
|
||||
filter: [
|
||||
...(serviceName ? [{ term: { [SERVICE_NAME]: serviceName } }] : []),
|
||||
...(transactionType
|
||||
? [{ term: { [TRANSACTION_TYPE]: transactionType } }]
|
||||
: []),
|
||||
...termQuery(SERVICE_NAME, serviceName),
|
||||
...termQuery(TRANSACTION_TYPE, transactionType),
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { SERVICE_NAME } from '../../../../common/elasticsearch_fieldnames';
|
||||
import { ProcessorEvent } from '../../../../common/processor_event';
|
||||
import { AlertParams } from '../../../routes/alerts/chart_preview';
|
||||
import { rangeQuery } from '../../../../../observability/server';
|
||||
import { rangeQuery, termQuery } from '../../../../../observability/server';
|
||||
import { environmentQuery } from '../../../../common/utils/environment_query';
|
||||
import { Setup } from '../../helpers/setup_request';
|
||||
|
||||
|
@ -25,7 +25,7 @@ export async function getTransactionErrorCountChartPreview({
|
|||
const query = {
|
||||
bool: {
|
||||
filter: [
|
||||
...(serviceName ? [{ term: { [SERVICE_NAME]: serviceName } }] : []),
|
||||
...termQuery(SERVICE_NAME, serviceName),
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
],
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { rangeQuery } from '../../../../../observability/server';
|
||||
import { rangeQuery, termQuery } from '../../../../../observability/server';
|
||||
import {
|
||||
SERVICE_NAME,
|
||||
TRANSACTION_TYPE,
|
||||
|
@ -52,10 +52,8 @@ export async function getTransactionErrorRateChartPreview({
|
|||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
...(serviceName ? [{ term: { [SERVICE_NAME]: serviceName } }] : []),
|
||||
...(transactionType
|
||||
? [{ term: { [TRANSACTION_TYPE]: transactionType } }]
|
||||
: []),
|
||||
...termQuery(SERVICE_NAME, serviceName),
|
||||
...termQuery(TRANSACTION_TYPE, transactionType),
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...getDocumentTypeFilterForTransactions(
|
||||
|
|
|
@ -41,6 +41,7 @@ import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
|
|||
import { apmActionVariables } from './action_variables';
|
||||
import { alertingEsClient } from './alerting_es_client';
|
||||
import { RegisterRuleDependencies } from './register_apm_alerts';
|
||||
import { termQuery } from '../../../../observability/server';
|
||||
|
||||
const ALERT_EVALUATION_THRESHOLD: typeof ALERT_EVALUATION_THRESHOLD_TYPED =
|
||||
ALERT_EVALUATION_THRESHOLD_NON_TYPED;
|
||||
|
@ -113,9 +114,7 @@ export function registerErrorCountAlertType({
|
|||
},
|
||||
},
|
||||
{ term: { [PROCESSOR_EVENT]: ProcessorEvent.error } },
|
||||
...(alertParams.serviceName
|
||||
? [{ term: { [SERVICE_NAME]: alertParams.serviceName } }]
|
||||
: []),
|
||||
...termQuery(SERVICE_NAME, alertParams.serviceName),
|
||||
...environmentQuery(alertParams.environment),
|
||||
],
|
||||
},
|
||||
|
|
|
@ -46,6 +46,7 @@ import {
|
|||
getEnvironmentEsField,
|
||||
getEnvironmentLabel,
|
||||
} from '../../../common/environment_filter_values';
|
||||
import { termQuery } from '../../../../observability/server';
|
||||
|
||||
const ALERT_EVALUATION_THRESHOLD: typeof ALERT_EVALUATION_THRESHOLD_TYPED =
|
||||
ALERT_EVALUATION_THRESHOLD_NON_TYPED;
|
||||
|
@ -157,24 +158,11 @@ export function registerTransactionDurationAnomalyAlertType({
|
|||
},
|
||||
},
|
||||
},
|
||||
...(alertParams.serviceName
|
||||
? [
|
||||
{
|
||||
term: {
|
||||
partition_field_value: alertParams.serviceName,
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(alertParams.transactionType
|
||||
? [
|
||||
{
|
||||
term: {
|
||||
by_field_value: alertParams.transactionType,
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...termQuery(
|
||||
'partition_field_value',
|
||||
alertParams.serviceName
|
||||
),
|
||||
...termQuery('by_field_value', alertParams.transactionType),
|
||||
] as QueryDslQueryContainer[],
|
||||
},
|
||||
},
|
||||
|
|
|
@ -48,6 +48,7 @@ import { RegisterRuleDependencies } from './register_apm_alerts';
|
|||
import { SearchAggregatedTransactionSetting } from '../../../common/aggregated_transactions';
|
||||
import { getDocumentTypeFilterForTransactions } from '../helpers/transactions';
|
||||
import { asPercent } from '../../../../observability/common/utils/formatters';
|
||||
import { termQuery } from '../../../../observability/server';
|
||||
|
||||
const ALERT_EVALUATION_THRESHOLD: typeof ALERT_EVALUATION_THRESHOLD_TYPED =
|
||||
ALERT_EVALUATION_THRESHOLD_NON_TYPED;
|
||||
|
@ -142,18 +143,8 @@ export function registerTransactionErrorRateAlertType({
|
|||
],
|
||||
},
|
||||
},
|
||||
...(alertParams.serviceName
|
||||
? [{ term: { [SERVICE_NAME]: alertParams.serviceName } }]
|
||||
: []),
|
||||
...(alertParams.transactionType
|
||||
? [
|
||||
{
|
||||
term: {
|
||||
[TRANSACTION_TYPE]: alertParams.transactionType,
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...termQuery(SERVICE_NAME, alertParams.serviceName),
|
||||
...termQuery(TRANSACTION_TYPE, alertParams.transactionType),
|
||||
...environmentQuery(alertParams.environment),
|
||||
],
|
||||
},
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { termQuery } from '../../../../observability/server';
|
||||
import { ProcessorEvent } from '../../../common/processor_event';
|
||||
import { Setup } from '../helpers/setup_request';
|
||||
import {
|
||||
|
@ -37,11 +38,6 @@ export async function getAllEnvironments({
|
|||
|
||||
const { apmEventClient } = setup;
|
||||
|
||||
// omit filter for service.name if "All" option is selected
|
||||
const serviceNameFilter = serviceName
|
||||
? [{ term: { [SERVICE_NAME]: serviceName } }]
|
||||
: [];
|
||||
|
||||
const params = {
|
||||
apm: {
|
||||
events: [
|
||||
|
@ -57,7 +53,7 @@ export async function getAllEnvironments({
|
|||
size: 0,
|
||||
query: {
|
||||
bool: {
|
||||
filter: [...serviceNameFilter],
|
||||
filter: [...termQuery(SERVICE_NAME, serviceName)],
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
} from '../../../common/elasticsearch_fieldnames';
|
||||
import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values';
|
||||
import { ProcessorEvent } from '../../../common/processor_event';
|
||||
import { rangeQuery } from '../../../../observability/server';
|
||||
import { rangeQuery, termQuery } from '../../../../observability/server';
|
||||
import { getProcessorEventForTransactions } from '../helpers/transactions';
|
||||
import { Setup } from '../helpers/setup_request';
|
||||
|
||||
|
@ -40,14 +40,6 @@ export async function getEnvironments({
|
|||
|
||||
const { apmEventClient } = setup;
|
||||
|
||||
const filter = rangeQuery(start, end);
|
||||
|
||||
if (serviceName) {
|
||||
filter.push({
|
||||
term: { [SERVICE_NAME]: serviceName },
|
||||
});
|
||||
}
|
||||
|
||||
const params = {
|
||||
apm: {
|
||||
events: [
|
||||
|
@ -60,7 +52,10 @@ export async function getEnvironments({
|
|||
size: 0,
|
||||
query: {
|
||||
bool: {
|
||||
filter,
|
||||
filter: [
|
||||
...rangeQuery(start, end),
|
||||
...termQuery(SERVICE_NAME, serviceName),
|
||||
],
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
|
|
|
@ -5,13 +5,16 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { ESFilter } from '../../../../../../../src/core/types/elasticsearch';
|
||||
import {
|
||||
ERROR_GROUP_ID,
|
||||
SERVICE_NAME,
|
||||
} from '../../../../common/elasticsearch_fieldnames';
|
||||
import { ProcessorEvent } from '../../../../common/processor_event';
|
||||
import { rangeQuery, kqlQuery } from '../../../../../observability/server';
|
||||
import {
|
||||
rangeQuery,
|
||||
kqlQuery,
|
||||
termQuery,
|
||||
} from '../../../../../observability/server';
|
||||
import { environmentQuery } from '../../../../common/utils/environment_query';
|
||||
import { Setup } from '../../helpers/setup_request';
|
||||
|
||||
|
@ -35,16 +38,6 @@ export async function getBuckets({
|
|||
end: number;
|
||||
}) {
|
||||
const { apmEventClient } = setup;
|
||||
const filter: ESFilter[] = [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...kqlQuery(kuery),
|
||||
];
|
||||
|
||||
if (groupId) {
|
||||
filter.push({ term: { [ERROR_GROUP_ID]: groupId } });
|
||||
}
|
||||
|
||||
const params = {
|
||||
apm: {
|
||||
|
@ -54,7 +47,13 @@ export async function getBuckets({
|
|||
size: 0,
|
||||
query: {
|
||||
bool: {
|
||||
filter,
|
||||
filter: [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...kqlQuery(kuery),
|
||||
...termQuery(ERROR_GROUP_ID, groupId),
|
||||
],
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
|
||||
import { Logger } from 'kibana/server';
|
||||
import { chunk } from 'lodash';
|
||||
import { ProcessorEvent } from '../../../common/processor_event';
|
||||
import { rangeQuery, termQuery } from '../../../../observability/server';
|
||||
import { PromiseReturnType } from '../../../../observability/typings/common';
|
||||
import {
|
||||
AGENT_NAME,
|
||||
SERVICE_ENVIRONMENT,
|
||||
SERVICE_NAME,
|
||||
} from '../../../common/elasticsearch_fieldnames';
|
||||
import { getServicesProjection } from '../../projections/services';
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
import { environmentQuery } from '../../../common/utils/environment_query';
|
||||
import { withApmSpan } from '../../utils/with_apm_span';
|
||||
import { Setup } from '../helpers/setup_request';
|
||||
|
@ -26,6 +26,7 @@ import { getServiceMapFromTraceIds } from './get_service_map_from_trace_ids';
|
|||
import { getTraceSampleIds } from './get_trace_sample_ids';
|
||||
import { transformServiceMapResponses } from './transform_service_map_responses';
|
||||
import { ENVIRONMENT_ALL } from '../../../common/environment_filter_values';
|
||||
import { getProcessorEventForTransactions } from '../helpers/transactions';
|
||||
|
||||
export interface IEnvOptions {
|
||||
setup: Setup;
|
||||
|
@ -94,40 +95,29 @@ async function getServicesData(options: IEnvOptions) {
|
|||
const { environment, setup, searchAggregatedTransactions, start, end } =
|
||||
options;
|
||||
|
||||
const projection = getServicesProjection({
|
||||
setup,
|
||||
searchAggregatedTransactions,
|
||||
kuery: '',
|
||||
start,
|
||||
end,
|
||||
});
|
||||
|
||||
let filter = [
|
||||
...projection.body.query.bool.filter,
|
||||
...environmentQuery(environment),
|
||||
];
|
||||
|
||||
if (options.serviceName) {
|
||||
filter = filter.concat({
|
||||
term: {
|
||||
[SERVICE_NAME]: options.serviceName,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const params = mergeProjection(projection, {
|
||||
const params = {
|
||||
apm: {
|
||||
events: [
|
||||
getProcessorEventForTransactions(searchAggregatedTransactions),
|
||||
ProcessorEvent.metric as const,
|
||||
ProcessorEvent.error as const,
|
||||
],
|
||||
},
|
||||
body: {
|
||||
size: 0,
|
||||
query: {
|
||||
bool: {
|
||||
...projection.body.query.bool,
|
||||
filter,
|
||||
filter: [
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...termQuery(SERVICE_NAME, options.serviceName),
|
||||
],
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
services: {
|
||||
terms: {
|
||||
field: projection.body.aggs.services.terms.field,
|
||||
field: SERVICE_NAME,
|
||||
size: 500,
|
||||
},
|
||||
aggs: {
|
||||
|
@ -140,7 +130,7 @@ async function getServicesData(options: IEnvOptions) {
|
|||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const { apmEventClient } = setup;
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import { Setup } from '../helpers/setup_request';
|
||||
import { ESFilter } from '../../../../../../src/core/types/elasticsearch';
|
||||
import { rangeQuery, kqlQuery } from '../../../../observability/server';
|
||||
import { environmentQuery } from '../../../common/utils/environment_query';
|
||||
import { ProcessorEvent } from '../../../common/processor_event';
|
||||
|
@ -33,13 +32,6 @@ export const getServiceInfrastructure = async ({
|
|||
}) => {
|
||||
const { apmEventClient } = setup;
|
||||
|
||||
const filter: ESFilter[] = [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...kqlQuery(kuery),
|
||||
];
|
||||
|
||||
const response = await apmEventClient.search('get_service_infrastructure', {
|
||||
apm: {
|
||||
events: [ProcessorEvent.metric],
|
||||
|
@ -48,7 +40,12 @@ export const getServiceInfrastructure = async ({
|
|||
size: 0,
|
||||
query: {
|
||||
bool: {
|
||||
filter,
|
||||
filter: [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...kqlQuery(kuery),
|
||||
],
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
|
|
|
@ -6,13 +6,16 @@
|
|||
*/
|
||||
|
||||
import { AggregationsDateInterval } from '@elastic/elasticsearch/lib/api/types';
|
||||
import { ESFilter } from '../../../../../../src/core/types/elasticsearch';
|
||||
import {
|
||||
SERVICE_NAME,
|
||||
TRANSACTION_NAME,
|
||||
TRANSACTION_TYPE,
|
||||
} from '../../../common/elasticsearch_fieldnames';
|
||||
import { kqlQuery, rangeQuery } from '../../../../observability/server';
|
||||
import {
|
||||
kqlQuery,
|
||||
rangeQuery,
|
||||
termQuery,
|
||||
} from '../../../../observability/server';
|
||||
import { environmentQuery } from '../../../common/utils/environment_query';
|
||||
import {
|
||||
getDocumentTypeFilterForTransactions,
|
||||
|
@ -49,30 +52,27 @@ export async function getThroughput({
|
|||
}: Options) {
|
||||
const { apmEventClient } = setup;
|
||||
|
||||
const filter: ESFilter[] = [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
{ term: { [TRANSACTION_TYPE]: transactionType } },
|
||||
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...kqlQuery(kuery),
|
||||
];
|
||||
|
||||
if (transactionName) {
|
||||
filter.push({
|
||||
term: {
|
||||
[TRANSACTION_NAME]: transactionName,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const params = {
|
||||
apm: {
|
||||
events: [getProcessorEventForTransactions(searchAggregatedTransactions)],
|
||||
},
|
||||
body: {
|
||||
size: 0,
|
||||
query: { bool: { filter } },
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
{ term: { [TRANSACTION_TYPE]: transactionType } },
|
||||
...getDocumentTypeFilterForTransactions(
|
||||
searchAggregatedTransactions
|
||||
),
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...kqlQuery(kuery),
|
||||
...termQuery(TRANSACTION_NAME, transactionName),
|
||||
],
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
timeseries: {
|
||||
date_histogram: {
|
||||
|
|
|
@ -10,7 +10,11 @@ import { sortBy } from 'lodash';
|
|||
import moment from 'moment';
|
||||
import { Unionize } from 'utility-types';
|
||||
import { AggregationOptionsByType } from '../../../../../../src/core/types/elasticsearch';
|
||||
import { kqlQuery, rangeQuery } from '../../../../observability/server';
|
||||
import {
|
||||
kqlQuery,
|
||||
rangeQuery,
|
||||
termQuery,
|
||||
} from '../../../../observability/server';
|
||||
import {
|
||||
PARENT_ID,
|
||||
SERVICE_NAME,
|
||||
|
@ -69,10 +73,6 @@ function getRequest(topTraceOptions: TopTraceOptions) {
|
|||
end,
|
||||
} = topTraceOptions;
|
||||
|
||||
const transactionNameFilter = transactionName
|
||||
? [{ term: { [TRANSACTION_NAME]: transactionName } }]
|
||||
: [];
|
||||
|
||||
return {
|
||||
apm: {
|
||||
events: [getProcessorEventForTransactions(searchAggregatedTransactions)],
|
||||
|
@ -82,7 +82,7 @@ function getRequest(topTraceOptions: TopTraceOptions) {
|
|||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
...transactionNameFilter,
|
||||
...termQuery(TRANSACTION_NAME, transactionName),
|
||||
...getDocumentTypeFilterForTransactions(
|
||||
searchAggregatedTransactions
|
||||
),
|
||||
|
|
|
@ -13,7 +13,11 @@ import {
|
|||
} from '../../../common/elasticsearch_fieldnames';
|
||||
import { EventOutcome } from '../../../common/event_outcome';
|
||||
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
|
||||
import { kqlQuery, rangeQuery } from '../../../../observability/server';
|
||||
import {
|
||||
kqlQuery,
|
||||
rangeQuery,
|
||||
termQuery,
|
||||
} from '../../../../observability/server';
|
||||
import { environmentQuery } from '../../../common/utils/environment_query';
|
||||
import { Coordinate } from '../../../typings/timeseries';
|
||||
import {
|
||||
|
@ -54,13 +58,6 @@ export async function getErrorRate({
|
|||
}> {
|
||||
const { apmEventClient } = setup;
|
||||
|
||||
const transactionNamefilter = transactionName
|
||||
? [{ term: { [TRANSACTION_NAME]: transactionName } }]
|
||||
: [];
|
||||
const transactionTypefilter = transactionType
|
||||
? [{ term: { [TRANSACTION_TYPE]: transactionType } }]
|
||||
: [];
|
||||
|
||||
const filter = [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
{
|
||||
|
@ -68,8 +65,8 @@ export async function getErrorRate({
|
|||
[EVENT_OUTCOME]: [EventOutcome.failure, EventOutcome.success],
|
||||
},
|
||||
},
|
||||
...transactionNamefilter,
|
||||
...transactionTypefilter,
|
||||
...termQuery(TRANSACTION_NAME, transactionName),
|
||||
...termQuery(TRANSACTION_TYPE, transactionType),
|
||||
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { ESFilter } from '../../../../../../../src/core/types/elasticsearch';
|
||||
import { PromiseReturnType } from '../../../../../observability/typings/common';
|
||||
import {
|
||||
SERVICE_NAME,
|
||||
|
@ -14,7 +13,11 @@ import {
|
|||
} from '../../../../common/elasticsearch_fieldnames';
|
||||
import { LatencyAggregationType } from '../../../../common/latency_aggregation_types';
|
||||
import { offsetPreviousPeriodCoordinates } from '../../../../common/utils/offset_previous_period_coordinate';
|
||||
import { kqlQuery, rangeQuery } from '../../../../../observability/server';
|
||||
import {
|
||||
kqlQuery,
|
||||
rangeQuery,
|
||||
termQuery,
|
||||
} from '../../../../../observability/server';
|
||||
import { environmentQuery } from '../../../../common/utils/environment_query';
|
||||
import {
|
||||
getDocumentTypeFilterForTransactions,
|
||||
|
@ -61,22 +64,6 @@ function searchLatency({
|
|||
searchAggregatedTransactions,
|
||||
});
|
||||
|
||||
const filter: ESFilter[] = [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...kqlQuery(kuery),
|
||||
];
|
||||
|
||||
if (transactionName) {
|
||||
filter.push({ term: { [TRANSACTION_NAME]: transactionName } });
|
||||
}
|
||||
|
||||
if (transactionType) {
|
||||
filter.push({ term: { [TRANSACTION_TYPE]: transactionType } });
|
||||
}
|
||||
|
||||
const transactionDurationField = getTransactionDurationFieldForTransactions(
|
||||
searchAggregatedTransactions
|
||||
);
|
||||
|
@ -87,7 +74,21 @@ function searchLatency({
|
|||
},
|
||||
body: {
|
||||
size: 0,
|
||||
query: { bool: { filter } },
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
...getDocumentTypeFilterForTransactions(
|
||||
searchAggregatedTransactions
|
||||
),
|
||||
...rangeQuery(start, end),
|
||||
...environmentQuery(environment),
|
||||
...kqlQuery(kuery),
|
||||
...termQuery(TRANSACTION_NAME, transactionName),
|
||||
...termQuery(TRANSACTION_TYPE, transactionType),
|
||||
],
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
latencyTimeseries: {
|
||||
date_histogram: {
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
TRACE_ID,
|
||||
TRANSACTION_ID,
|
||||
} from '../../../../common/elasticsearch_fieldnames';
|
||||
import { rangeQuery } from '../../../../../observability/server';
|
||||
import { rangeQuery, termQuery } from '../../../../../observability/server';
|
||||
import { Setup } from '../../helpers/setup_request';
|
||||
import { ProcessorEvent } from '../../../../common/processor_event';
|
||||
import { asMutableArray } from '../../../../common/utils/as_mutable_array';
|
||||
|
@ -39,7 +39,7 @@ export async function getTransaction({
|
|||
bool: {
|
||||
filter: asMutableArray([
|
||||
{ term: { [TRANSACTION_ID]: transactionId } },
|
||||
...(traceId ? [{ term: { [TRACE_ID]: traceId } }] : []),
|
||||
...termQuery(TRACE_ID, traceId),
|
||||
...(start && end ? rangeQuery(start, end) : []),
|
||||
]),
|
||||
},
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* 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 { Setup } from '../../server/lib/helpers/setup_request';
|
||||
import { SERVICE_NAME } from '../../common/elasticsearch_fieldnames';
|
||||
import { rangeQuery, kqlQuery } from '../../../observability/server';
|
||||
import { ProcessorEvent } from '../../common/processor_event';
|
||||
import { getProcessorEventForTransactions } from '../lib/helpers/transactions';
|
||||
|
||||
export function getServicesProjection({
|
||||
kuery,
|
||||
setup,
|
||||
searchAggregatedTransactions,
|
||||
start,
|
||||
end,
|
||||
}: {
|
||||
kuery: string;
|
||||
setup: Setup;
|
||||
searchAggregatedTransactions: boolean;
|
||||
start: number;
|
||||
end: number;
|
||||
}) {
|
||||
return {
|
||||
apm: {
|
||||
events: [
|
||||
getProcessorEventForTransactions(searchAggregatedTransactions),
|
||||
ProcessorEvent.metric as const,
|
||||
ProcessorEvent.error as const,
|
||||
],
|
||||
},
|
||||
body: {
|
||||
size: 0,
|
||||
query: {
|
||||
bool: {
|
||||
filter: [...rangeQuery(start, end), ...kqlQuery(kuery)],
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
services: {
|
||||
terms: {
|
||||
field: SERVICE_NAME,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
|
@ -17,7 +17,7 @@ import {
|
|||
unwrapEsResponse,
|
||||
WrappedElasticsearchClientError,
|
||||
} from '../common/utils/unwrap_es_response';
|
||||
export { rangeQuery, kqlQuery } from './utils/queries';
|
||||
export { rangeQuery, kqlQuery, termQuery } from './utils/queries';
|
||||
export { getInspectResponse } from '../common/utils/get_inspect_response';
|
||||
|
||||
export * from './types';
|
||||
|
|
|
@ -8,6 +8,14 @@
|
|||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
|
||||
|
||||
export function termQuery<T extends string>(field: T, value: string | undefined) {
|
||||
if (!value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [{ term: { [field]: value } as Record<T, string> }];
|
||||
}
|
||||
|
||||
export function rangeQuery(
|
||||
start?: number,
|
||||
end?: number,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue