diff --git a/x-pack/plugins/apm/public/components/shared/StickyProperties/StickyProperties.test.js b/x-pack/plugins/apm/public/components/shared/StickyProperties/StickyProperties.test.js index 4cc7d9b978a4..aa1ea0cb62d5 100644 --- a/x-pack/plugins/apm/public/components/shared/StickyProperties/StickyProperties.test.js +++ b/x-pack/plugins/apm/public/components/shared/StickyProperties/StickyProperties.test.js @@ -34,7 +34,7 @@ describe('StickyProperties', () => { { label: 'Handled', fieldName: 'error.exception.handled', - val: 'true' + val: true }, { label: 'User ID', diff --git a/x-pack/plugins/apm/public/components/shared/StickyProperties/index.tsx b/x-pack/plugins/apm/public/components/shared/StickyProperties/index.tsx index f4b58cf58ed7..be4ff1cf9eb7 100644 --- a/x-pack/plugins/apm/public/components/shared/StickyProperties/index.tsx +++ b/x-pack/plugins/apm/public/components/shared/StickyProperties/index.tsx @@ -101,7 +101,7 @@ function getPropertyValue({ ); } - return {val}; + return {String(val)}; } export function StickyProperties({ diff --git a/x-pack/plugins/apm/public/services/rest/apm/transaction_groups.ts b/x-pack/plugins/apm/public/services/rest/apm/transaction_groups.ts index a0e03ffd4a73..b6781e1405a9 100644 --- a/x-pack/plugins/apm/public/services/rest/apm/transaction_groups.ts +++ b/x-pack/plugins/apm/public/services/rest/apm/transaction_groups.ts @@ -40,6 +40,7 @@ export async function loadTransactionDistribution({ transactionName, transactionType = 'request', transactionId, + traceId, kuery }: Required) { return callApi({ @@ -50,6 +51,7 @@ export async function loadTransactionDistribution({ start, end, transactionId, + traceId, esFilterQuery: await getEncodedEsQuery(kuery) } }); diff --git a/x-pack/plugins/apm/public/services/rest/apm/transactions.ts b/x-pack/plugins/apm/public/services/rest/apm/transactions.ts index 3702b96d16c0..141a9939f5b8 100644 --- a/x-pack/plugins/apm/public/services/rest/apm/transactions.ts +++ b/x-pack/plugins/apm/public/services/rest/apm/transactions.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { KFetchError } from 'ui/kfetch/kfetch_error'; import { TransactionAPIResponse } from 'x-pack/plugins/apm/server/lib/transactions/get_transaction'; import { SpanListAPIResponse } from 'x-pack/plugins/apm/server/lib/transactions/spans/get_spans'; import { Span } from 'x-pack/plugins/apm/typings/es_schemas/Span'; @@ -43,20 +44,31 @@ export async function loadTransaction({ traceId, kuery }: IUrlParams) { - const result = await callApi( - { - pathname: `/api/apm/services/${serviceName}/transactions/${transactionId}`, - query: { - traceId, - start, - end, - esFilterQuery: await getEncodedEsQuery(kuery) + try { + const result = await callApi( + { + pathname: `/api/apm/services/${serviceName}/transactions/${transactionId}`, + query: { + traceId, + start, + end, + esFilterQuery: await getEncodedEsQuery(kuery) + } + }, + { + camelcase: false } - }, - { - camelcase: false - } - ); + ); + return addVersion(result); + } catch (e) { + const err: KFetchError = e; - return addVersion(result); + // swallow 404 errors + if (err.res.status === 404) { + return; + } + + // re-throw all other errors + throw err; + } } diff --git a/x-pack/plugins/apm/public/store/reactReduxRequest/transactionDistribution.tsx b/x-pack/plugins/apm/public/store/reactReduxRequest/transactionDistribution.tsx index 0e140bb0fe85..b4232de6a9db 100644 --- a/x-pack/plugins/apm/public/store/reactReduxRequest/transactionDistribution.tsx +++ b/x-pack/plugins/apm/public/store/reactReduxRequest/transactionDistribution.tsx @@ -47,6 +47,7 @@ export function TransactionDistributionRequest({ serviceName, transactionType, transactionId, + traceId, start, end, transactionName, @@ -66,6 +67,7 @@ export function TransactionDistributionRequest({ serviceName, transactionType, transactionId, + traceId, start, end, transactionName, diff --git a/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/fetcher.ts b/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/fetcher.ts index 0cf35f5a6f57..b716fe95ef67 100644 --- a/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/fetcher.ts +++ b/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/fetcher.ts @@ -45,6 +45,7 @@ export function bucketFetcher( transactionName: string, transactionType: string, transactionId: string, + traceId: string, bucketSize: number, setup: Setup ): Promise { @@ -77,6 +78,7 @@ export function bucketFetcher( bool: { filter, should: [ + { term: { [TRACE_ID]: traceId } }, { term: { [TRANSACTION_ID]: transactionId } }, { term: { [TRANSACTION_SAMPLED]: true } } ] diff --git a/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts b/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts index 8b5ffce6c1b1..f5cc252fc68f 100644 --- a/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts +++ b/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts @@ -13,6 +13,7 @@ export async function getBuckets( transactionName: string, transactionType: string, transactionId: string, + traceId: string, bucketSize: number, setup: Setup ) { @@ -21,6 +22,7 @@ export async function getBuckets( transactionName, transactionType, transactionId, + traceId, bucketSize, setup ); diff --git a/x-pack/plugins/apm/server/lib/transactions/distribution/index.ts b/x-pack/plugins/apm/server/lib/transactions/distribution/index.ts index 16e46191b5f4..73e4e988a97d 100644 --- a/x-pack/plugins/apm/server/lib/transactions/distribution/index.ts +++ b/x-pack/plugins/apm/server/lib/transactions/distribution/index.ts @@ -21,6 +21,7 @@ export async function getDistribution( transactionName: string, transactionType: string, transactionId: string, + traceId: string, setup: Setup ): Promise { const bucketSize = await calculateBucketSize( @@ -35,6 +36,7 @@ export async function getDistribution( transactionName, transactionType, transactionId, + traceId, bucketSize, setup ); diff --git a/x-pack/plugins/apm/server/lib/transactions/get_transaction/index.ts b/x-pack/plugins/apm/server/lib/transactions/get_transaction/index.ts index 325ca6836244..08142ec2704d 100644 --- a/x-pack/plugins/apm/server/lib/transactions/get_transaction/index.ts +++ b/x-pack/plugins/apm/server/lib/transactions/get_transaction/index.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SearchParams } from 'elasticsearch'; +import { ESFilter } from 'elasticsearch'; import { oc } from 'ts-optchain'; import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction'; import { @@ -23,38 +23,40 @@ export async function getTransaction( ): Promise { const { start, end, esFilterQuery, client, config } = setup; - const params: SearchParams = { - index: config.get('apm_oss.transactionIndices'), + const filter: ESFilter[] = [ + { term: { [PROCESSOR_EVENT]: 'transaction' } }, + { term: { [TRANSACTION_ID]: transactionId } }, + { + range: { + '@timestamp': { + gte: start, + lte: end, + format: 'epoch_millis' + } + } + } + ]; + + if (esFilterQuery) { + filter.push(esFilterQuery); + } + + if (traceId) { + filter.push({ term: { [TRACE_ID]: traceId } }); + } + + const params = { + index: config.get('apm_oss.transactionIndices'), body: { size: 1, query: { bool: { - filter: [ - { term: { [PROCESSOR_EVENT]: 'transaction' } }, - { term: { [TRANSACTION_ID]: transactionId } }, - { - range: { - '@timestamp': { - gte: start, - lte: end, - format: 'epoch_millis' - } - } - } - ] + filter } } } }; - if (esFilterQuery) { - params.body.query.bool.filter.push(esFilterQuery); - } - - if (traceId) { - params.body.query.bool.filter.push({ term: { [TRACE_ID]: traceId } }); - } - const resp = await client('search', params); return oc(resp).hits.hits[0]._source(); } diff --git a/x-pack/plugins/apm/server/lib/transactions/spans/get_spans.ts b/x-pack/plugins/apm/server/lib/transactions/spans/get_spans.ts index 5a384c5acf83..983e16ae4867 100644 --- a/x-pack/plugins/apm/server/lib/transactions/spans/get_spans.ts +++ b/x-pack/plugins/apm/server/lib/transactions/spans/get_spans.ts @@ -14,6 +14,7 @@ import { Setup } from '../../helpers/setup_request'; export type SpanListAPIResponse = Span[]; +// Deprecated and will be removed in 7.0. Only needed for backwards compatability pre 6.5 (introducition of v2 API and distributed tracing) export async function getSpans( transactionId: string, setup: Setup diff --git a/x-pack/plugins/apm/server/routes/__test__/routeFailures.test.ts b/x-pack/plugins/apm/server/routes/__test__/routeFailures.test.ts index 7c3087ec4fcf..162e0810801c 100644 --- a/x-pack/plugins/apm/server/routes/__test__/routeFailures.test.ts +++ b/x-pack/plugins/apm/server/routes/__test__/routeFailures.test.ts @@ -12,7 +12,6 @@ import { initServicesApi } from '../services'; // @ts-ignore import { initStatusApi } from '../status_check'; import { initTracesApi } from '../traces'; -import { initTransactionsApi } from '../transactions'; describe('route handlers should fail with a Boom error', () => { let consoleErrorSpy: any; @@ -76,8 +75,4 @@ describe('route handlers should fail with a Boom error', () => { describe('trace routes', async () => { await testRouteFailures(initTracesApi); }); - - describe('transaction routes', async () => { - await testRouteFailures(initTransactionsApi); - }); }); diff --git a/x-pack/plugins/apm/server/routes/transaction_groups.ts b/x-pack/plugins/apm/server/routes/transaction_groups.ts index d06355d6f18b..60216b0460f6 100644 --- a/x-pack/plugins/apm/server/routes/transaction_groups.ts +++ b/x-pack/plugins/apm/server/routes/transaction_groups.ts @@ -109,19 +109,24 @@ export function initTransactionGroupsApi(server: Server) { options: { validate: { query: withDefaultValidators({ - transactionId: Joi.string().default('') + transactionId: Joi.string().default(''), + traceId: Joi.string().default('') }) } }, handler: req => { const setup = setupRequest(req); const { serviceName, transactionType, transactionName } = req.params; - const { transactionId } = req.query as { transactionId: string }; + const { transactionId, traceId } = req.query as { + transactionId: string; + traceId: string; + }; return getDistribution( serviceName, transactionName, transactionType, transactionId, + traceId, setup ).catch(defaultErrorHandler); } diff --git a/x-pack/plugins/apm/server/routes/transactions.ts b/x-pack/plugins/apm/server/routes/transactions.ts index 1b1bd12f8bce..d6bd35e3fb6d 100644 --- a/x-pack/plugins/apm/server/routes/transactions.ts +++ b/x-pack/plugins/apm/server/routes/transactions.ts @@ -12,12 +12,6 @@ import { setupRequest } from '../lib/helpers/setup_request'; import { getTransaction } from '../lib/transactions/get_transaction'; import { getSpans } from '../lib/transactions/spans/get_spans'; -const defaultErrorHandler = (err: Error) => { - // tslint:disable-next-line - console.error(err.stack); - throw Boom.boomify(err, { statusCode: 400 }); -}; - export function initTransactionsApi(server: Server) { server.route({ method: 'GET', @@ -29,13 +23,16 @@ export function initTransactionsApi(server: Server) { }) } }, - handler: req => { + handler: async req => { const { transactionId } = req.params; const { traceId } = req.query as { traceId: string }; const setup = setupRequest(req); - return getTransaction(transactionId, traceId, setup).catch( - defaultErrorHandler - ); + const transaction = await getTransaction(transactionId, traceId, setup); + if (transaction) { + return transaction; + } else { + throw Boom.notFound('Cannot find the requested page'); + } } }); @@ -51,7 +48,7 @@ export function initTransactionsApi(server: Server) { handler: req => { const { transactionId } = req.params; const setup = setupRequest(req); - return getSpans(transactionId, setup).catch(defaultErrorHandler); + return getSpans(transactionId, setup); } }); } diff --git a/x-pack/plugins/monitoring/public/directives/main/index.js b/x-pack/plugins/monitoring/public/directives/main/index.js index 191ce9261b9c..1d7bf72ac242 100644 --- a/x-pack/plugins/monitoring/public/directives/main/index.js +++ b/x-pack/plugins/monitoring/public/directives/main/index.js @@ -82,35 +82,27 @@ uiModule.directive('monitoringMain', (breadcrumbs, license, kbnUrl, config) => { link(scope, _element, attributes, controller) { config.watch('k7design', (val) => scope.showPluginBreadcrumbs = !val); - function getSetupObj() { - return { - licenseService: license, - breadcrumbsService: breadcrumbs, - kbnUrlService: kbnUrl, - attributes: { - name: attributes.name, - product: attributes.product, - instance: attributes.instance, - resolver: attributes.resolver, - page: attributes.page, - tabIconClass: attributes.tabIconClass, - tabIconLabel: attributes.tabIconLabel, - pipelineId: attributes.pipelineId, - pipelineHash: attributes.pipelineHash, - pipelineVersions: get(scope, 'pageData.versions') - }, - clusterName: get(scope, 'cluster.cluster_name') - }; - } + controller.setup({ + licenseService: license, + breadcrumbsService: breadcrumbs, + kbnUrlService: kbnUrl, + attributes: { + name: attributes.name, + product: attributes.product, + instance: attributes.instance, + resolver: attributes.resolver, + page: attributes.page, + tabIconClass: attributes.tabIconClass, + tabIconLabel: attributes.tabIconLabel, + pipelineId: attributes.pipelineId, + pipelineHash: attributes.pipelineHash, + pipelineVersions: get(scope, 'pageData.versions') + }, + clusterName: get(scope, 'cluster.cluster_name') + }); - const setupObj = getSetupObj(); - controller.setup(setupObj); - Object.keys(setupObj.attributes).forEach(key => { - attributes.$observe(key, () => controller.setup(getSetupObj())); - }); - scope.$watch('pageData.versions', versions => { - controller.pipelineVersions = versions; - }); + attributes.$observe('instance', instance => controller.instance = instance); + attributes.$observe('resolver', resolver => controller.resolver = resolver); } }; }); diff --git a/x-pack/plugins/monitoring/public/views/logstash/pipeline/index.js b/x-pack/plugins/monitoring/public/views/logstash/pipeline/index.js index b6ada2684884..2a1a59f48b9c 100644 --- a/x-pack/plugins/monitoring/public/views/logstash/pipeline/index.js +++ b/x-pack/plugins/monitoring/public/views/logstash/pipeline/index.js @@ -98,9 +98,6 @@ uiRoutes.when('/logstash/pipelines/:id/:hash?', { getPageData, reactNodeId: 'monitoringLogstashPipelineApp', $scope, - options: { - enableTimeFilter: false, - }, $injector });