Skip to content

Commit

Permalink
[7.x] [APM] Local UI filters (#41588) (#43336)
Browse files Browse the repository at this point in the history
* Add snapshot tests for query search params

* Use projections to fetch data

* Add configuration and aggregations for local filters

* Add endpoints for local filters

* UseLocalUIFilters hook

* Parse Local UI filters from URL params

* LocalUIFilters component

* TransactionTypeFilter

* replace useServiceTransactionTypes with useTransactionTypes

* Support transactionType for trace projection/api

* Configure Local UI Filters

* Use units instead of hardcoded px

* Fix i18n error

* Remove unused labels from translation files

* Update URL of API integration test for transaction_types API call

* Revert "replace useServiceTransactionTypes with useTransactionTypes"

This reverts commit bae7fa44a0fc1ace0b498cc78626fabb2d310437.

* Revert "Support transactionType for trace projection/api"

This reverts commit 2edb32cf04ca2c38885c457ba57ce0a1547fd199.

* Remove transaction type filter for traces,error groups

* Address review feedback

* Don't clone in mergeProjection; add tests

* Address review feedback

* Revert transaction_types API path in functional tests

* More review feedback

* More review feedback:

- Add transactions projection
- Merge traces/transaction groups projections

* Don't persist local UI filters in HistoryTabs

* Move projections to server folder

* Move transactionName into options

* Use pod name instead of pod uid
  • Loading branch information
dgieselaar authored Aug 15, 2019
1 parent d106a4b commit 838bb39
Show file tree
Hide file tree
Showing 67 changed files with 4,679 additions and 325 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions x-pack/legacy/plugins/apm/common/elasticsearch_fieldnames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ export const METRIC_JAVA_NON_HEAP_MEMORY_COMMITTED =
'jvm.memory.non_heap.committed';
export const METRIC_JAVA_NON_HEAP_MEMORY_USED = 'jvm.memory.non_heap.used';
export const METRIC_JAVA_THREAD_COUNT = 'jvm.thread.count';

export const HOST_NAME = 'host.hostname';
export const CONTAINER_ID = 'container.id';
export const POD_NAME = 'kubernetes.pod.name';
46 changes: 46 additions & 0 deletions x-pack/legacy/plugins/apm/common/projections/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.
*/

import { Setup } from '../../server/lib/helpers/setup_request';
import {
PROCESSOR_EVENT,
SERVICE_NAME,
ERROR_GROUP_ID
} from '../elasticsearch_fieldnames';
import { rangeFilter } from '../../server/lib/helpers/range_filter';

export function getErrorGroupsProjection({
setup,
serviceName
}: {
setup: Setup;
serviceName: string;
}) {
const { start, end, uiFiltersES, config } = setup;

return {
index: config.get<string>('apm_oss.errorIndices'),
body: {
query: {
bool: {
filter: [
{ term: { [SERVICE_NAME]: serviceName } },
{ term: { [PROCESSOR_EVENT]: 'error' } },
{ range: rangeFilter(start, end) },
...uiFiltersES
]
}
},
aggs: {
error_groups: {
terms: {
field: ERROR_GROUP_ID
}
}
}
}
};
}
37 changes: 37 additions & 0 deletions x-pack/legacy/plugins/apm/common/projections/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.
*/

import { Setup } from '../../server/lib/helpers/setup_request';
import { SERVICE_NAME, PROCESSOR_EVENT } from '../elasticsearch_fieldnames';
import { rangeFilter } from '../../server/lib/helpers/range_filter';

export function getMetricsProjection({
setup,
serviceName
}: {
setup: Setup;
serviceName: string;
}) {
const { start, end, uiFiltersES, config } = setup;

return {
index: config.get<string>('apm_oss.metricsIndices'),
body: {
query: {
bool: {
filter: [
{ term: { [SERVICE_NAME]: serviceName } },
{ term: { [PROCESSOR_EVENT]: 'metric' } },
{
range: rangeFilter(start, end)
},
...uiFiltersES
]
}
}
}
};
}
42 changes: 42 additions & 0 deletions x-pack/legacy/plugins/apm/common/projections/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.
*/

import { Setup } from '../../server/lib/helpers/setup_request';
import { SERVICE_NAME, PROCESSOR_EVENT } from '../elasticsearch_fieldnames';
import { rangeFilter } from '../../server/lib/helpers/range_filter';

export function getServicesProjection({ setup }: { setup: Setup }) {
const { start, end, uiFiltersES, config } = setup;

return {
index: [
config.get<string>('apm_oss.metricsIndices'),
config.get<string>('apm_oss.errorIndices'),
config.get<string>('apm_oss.transactionIndices')
],
body: {
size: 0,
query: {
bool: {
filter: [
{
terms: { [PROCESSOR_EVENT]: ['transaction', 'error', 'metric'] }
},
{ range: rangeFilter(start, end) },
...uiFiltersES
]
}
},
aggs: {
services: {
terms: {
field: SERVICE_NAME
}
}
}
}
};
}
46 changes: 46 additions & 0 deletions x-pack/legacy/plugins/apm/common/projections/transaction_groups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.
*/
import { omit } from 'lodash';
import { Setup } from '../../server/lib/helpers/setup_request';
import { TRANSACTION_NAME, PARENT_ID } from '../elasticsearch_fieldnames';
import { Options } from '../../server/lib/transaction_groups/fetcher';
import { getTransactionsProjection } from './transactions';
import { mergeProjection } from './util/merge_projection';

export function getTransactionGroupsProjection({
setup,
options
}: {
setup: Setup;
options: Options;
}) {
const transactionsProjection = getTransactionsProjection({
setup,
...(omit(options, 'type') as Omit<typeof options, 'type'>)
});

const bool =
options.type === 'top_traces'
? {
must_not: [{ exists: { field: PARENT_ID } }]
}
: {};

return mergeProjection(transactionsProjection, {
body: {
query: {
bool
},
aggs: {
transactions: {
terms: {
field: TRANSACTION_NAME
}
}
}
}
});
}
58 changes: 58 additions & 0 deletions x-pack/legacy/plugins/apm/common/projections/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.
*/

import { Setup } from '../../server/lib/helpers/setup_request';
import {
SERVICE_NAME,
TRANSACTION_TYPE,
PROCESSOR_EVENT,
TRANSACTION_NAME
} from '../elasticsearch_fieldnames';
import { rangeFilter } from '../../server/lib/helpers/range_filter';

export function getTransactionsProjection({
setup,
serviceName,
transactionName,
transactionType
}: {
setup: Setup;
serviceName?: string;
transactionName?: string;
transactionType?: string;
}) {
const { start, end, uiFiltersES, config } = setup;

const transactionNameFilter = transactionName
? [{ term: { [TRANSACTION_NAME]: transactionName } }]
: [];
const transactionTypeFilter = transactionType
? [{ term: { [TRANSACTION_TYPE]: transactionType } }]
: [];
const serviceNameFilter = serviceName
? [{ term: { [SERVICE_NAME]: serviceName } }]
: [];

const bool = {
filter: [
{ range: rangeFilter(start, end) },
{ term: { [PROCESSOR_EVENT]: 'transaction' } },
...transactionNameFilter,
...transactionTypeFilter,
...serviceNameFilter,
...uiFiltersES
]
};

return {
index: config.get<string>('apm_oss.transactionIndices'),
body: {
query: {
bool
}
}
};
}
28 changes: 28 additions & 0 deletions x-pack/legacy/plugins/apm/common/projections/typings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

import { SearchParams } from 'elasticsearch';

export type Projection = Omit<SearchParams, 'body' | 'aggs'> & {
body: {
query: any;
} & {
aggs?: {
[key: string]: {
terms: any;
};
};
};
};

export enum PROJECTION {
SERVICES = 'services',
TRANSACTION_GROUPS = 'transactionGroups',
TRACES = 'traces',
TRANSACTIONS = 'transactions',
METRICS = 'metrics',
ERROR_GROUPS = 'errorGroups'
}
Loading

0 comments on commit 838bb39

Please sign in to comment.