diff --git a/x-pack/plugins/apm/server/lib/services/__snapshots__/queries.test.ts.snap b/x-pack/plugins/apm/server/lib/services/__snapshots__/queries.test.ts.snap index 3e68831ee7cba..0521ff7d9554d 100644 --- a/x-pack/plugins/apm/server/lib/services/__snapshots__/queries.test.ts.snap +++ b/x-pack/plugins/apm/server/lib/services/__snapshots__/queries.test.ts.snap @@ -34,6 +34,15 @@ Object { }, }, }, + Object { + "range": Object { + "@timestamp": Object { + "format": "epoch_millis", + "gte": 1528113600000, + "lte": 1528977600000, + }, + }, + }, ], }, }, diff --git a/x-pack/plugins/apm/server/lib/services/annotations/__fixtures__/versions_first_seen.json b/x-pack/plugins/apm/server/lib/services/annotations/__fixtures__/versions_first_seen.json index c53b28c8bf594..8a277797825a4 100644 --- a/x-pack/plugins/apm/server/lib/services/annotations/__fixtures__/versions_first_seen.json +++ b/x-pack/plugins/apm/server/lib/services/annotations/__fixtures__/versions_first_seen.json @@ -9,16 +9,16 @@ }, "hits": { "total": { - "value": 10000, + "value": 1, "relation": "gte" }, "max_score": null, - "hits": [] - }, - "aggregations": { - "first_seen": { - "value": 1.5281138E12, - "value_as_string": "2018-06-04T12:00:00.000Z" - } + "hits": [ + { + "_source": { + "@timestamp": "2018-06-04T12:00:00.000Z" + } + } + ] } } diff --git a/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts b/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts index 67aa9d7fcd870..25c42f403da2e 100644 --- a/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts +++ b/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { isNumber } from 'lodash'; +import { isFiniteNumber } from '../../../../common/utils/is_finite_number'; import { ESFilter } from '../../../../../../typings/elasticsearch'; import { Annotation, AnnotationType } from '../../../../common/annotations'; import { @@ -85,25 +85,23 @@ export async function getDerivedServiceAnnotations({ ], }, body: { - size: 0, + size: 1, query: { bool: { filter: [...filter, { term: { [SERVICE_VERSION]: version } }], }, }, - aggs: { - first_seen: { - min: { - field: '@timestamp', - }, - }, + sort: { + '@timestamp': 'desc', }, }, }); - const firstSeen = response.aggregations?.first_seen.value; + const firstSeen = new Date( + response.hits.hits[0]._source['@timestamp'] + ).getTime(); - if (!isNumber(firstSeen)) { + if (!isFiniteNumber(firstSeen)) { throw new Error( 'First seen for version was unexpectedly undefined or null.' ); diff --git a/x-pack/plugins/apm/server/lib/services/annotations/index.test.ts b/x-pack/plugins/apm/server/lib/services/annotations/index.test.ts index 206e04d49cc03..d86016ed9d505 100644 --- a/x-pack/plugins/apm/server/lib/services/annotations/index.test.ts +++ b/x-pack/plugins/apm/server/lib/services/annotations/index.test.ts @@ -111,13 +111,13 @@ describe('getServiceAnnotations', () => { { id: '8.0.0', text: '8.0.0', - '@timestamp': 1.5281138e12, + '@timestamp': new Date('2018-06-04T12:00:00.000Z').getTime(), type: 'version', }, { id: '7.5.0', text: '7.5.0', - '@timestamp': 1.5281138e12, + '@timestamp': new Date('2018-06-04T12:00:00.000Z').getTime(), type: 'version', }, ]); diff --git a/x-pack/plugins/apm/server/lib/services/get_services/get_legacy_data_status.ts b/x-pack/plugins/apm/server/lib/services/get_services/get_legacy_data_status.ts index 87f3c0a5d1b38..a3adca0d306aa 100644 --- a/x-pack/plugins/apm/server/lib/services/get_services/get_legacy_data_status.ts +++ b/x-pack/plugins/apm/server/lib/services/get_services/get_legacy_data_status.ts @@ -5,15 +5,16 @@ * 2.0. */ +import { rangeQuery } from '../../../../common/utils/queries'; import { ProcessorEvent } from '../../../../common/processor_event'; import { OBSERVER_VERSION_MAJOR } from '../../../../common/elasticsearch_fieldnames'; -import { Setup } from '../../helpers/setup_request'; +import { Setup, SetupTimeRange } from '../../helpers/setup_request'; import { withApmSpan } from '../../../utils/with_apm_span'; // returns true if 6.x data is found -export async function getLegacyDataStatus(setup: Setup) { +export async function getLegacyDataStatus(setup: Setup & SetupTimeRange) { return withApmSpan('get_legacy_data_status', async () => { - const { apmEventClient } = setup; + const { apmEventClient, start, end } = setup; const params = { terminateAfter: 1, @@ -24,7 +25,10 @@ export async function getLegacyDataStatus(setup: Setup) { size: 0, query: { bool: { - filter: [{ range: { [OBSERVER_VERSION_MAJOR]: { lt: 7 } } }], + filter: [ + { range: { [OBSERVER_VERSION_MAJOR]: { lt: 7 } } }, + ...rangeQuery(start, end), + ], }, }, }, diff --git a/x-pack/plugins/apm/server/lib/transactions/__snapshots__/queries.test.ts.snap b/x-pack/plugins/apm/server/lib/transactions/__snapshots__/queries.test.ts.snap index 5d6a92a874111..62050563497e9 100644 --- a/x-pack/plugins/apm/server/lib/transactions/__snapshots__/queries.test.ts.snap +++ b/x-pack/plugins/apm/server/lib/transactions/__snapshots__/queries.test.ts.snap @@ -164,6 +164,23 @@ Object { "service.environment": "test", }, }, + Object { + "bool": Object { + "minimum_should_match": 1, + "should": Array [ + Object { + "exists": Object { + "field": "span.self_time.sum.us", + }, + }, + Object { + "exists": Object { + "field": "transaction.breakdown.count", + }, + }, + ], + }, + }, ], }, }, @@ -298,6 +315,23 @@ Object { "service.environment": "test", }, }, + Object { + "bool": Object { + "minimum_should_match": 1, + "should": Array [ + Object { + "exists": Object { + "field": "span.self_time.sum.us", + }, + }, + Object { + "exists": Object { + "field": "transaction.breakdown.count", + }, + }, + ], + }, + }, Object { "term": Object { "transaction.name": "baz", diff --git a/x-pack/plugins/apm/server/lib/transactions/breakdown/index.ts b/x-pack/plugins/apm/server/lib/transactions/breakdown/index.ts index c3741184c807d..f1e202df312c2 100644 --- a/x-pack/plugins/apm/server/lib/transactions/breakdown/index.ts +++ b/x-pack/plugins/apm/server/lib/transactions/breakdown/index.ts @@ -87,6 +87,15 @@ export function getTransactionBreakdown({ ...rangeQuery(start, end), ...environmentQuery(environment), ...esFilter, + { + bool: { + should: [ + { exists: { field: SPAN_SELF_TIME_SUM } }, + { exists: { field: TRANSACTION_BREAKDOWN_COUNT } }, + ], + minimum_should_match: 1, + }, + }, ]; if (transactionName) {