forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
31 changed files
with
1,535 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
x-pack/legacy/plugins/apm/scripts/optimize-tsconfig/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 0 additions & 105 deletions
105
x-pack/plugins/apm/server/lib/helpers/create_or_update_index.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* 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 { isNumber } from 'lodash'; | ||
import { Annotation, AnnotationType } from '../../../../common/annotations'; | ||
import { SetupTimeRange, Setup } from '../../helpers/setup_request'; | ||
import { ESFilter } from '../../../../typings/elasticsearch'; | ||
import { rangeFilter } from '../../helpers/range_filter'; | ||
import { | ||
PROCESSOR_EVENT, | ||
SERVICE_NAME, | ||
SERVICE_ENVIRONMENT, | ||
SERVICE_VERSION | ||
} from '../../../../common/elasticsearch_fieldnames'; | ||
|
||
export async function getDerivedServiceAnnotations({ | ||
setup, | ||
serviceName, | ||
environment | ||
}: { | ||
serviceName: string; | ||
environment?: string; | ||
setup: Setup & SetupTimeRange; | ||
}) { | ||
const { start, end, client, indices } = setup; | ||
|
||
const filter: ESFilter[] = [ | ||
{ term: { [PROCESSOR_EVENT]: 'transaction' } }, | ||
{ range: rangeFilter(start, end) }, | ||
{ term: { [SERVICE_NAME]: serviceName } } | ||
]; | ||
|
||
if (environment) { | ||
filter.push({ term: { [SERVICE_ENVIRONMENT]: environment } }); | ||
} | ||
|
||
const versions = | ||
( | ||
await client.search({ | ||
index: indices['apm_oss.transactionIndices'], | ||
body: { | ||
size: 0, | ||
track_total_hits: false, | ||
query: { | ||
bool: { | ||
filter | ||
} | ||
}, | ||
aggs: { | ||
versions: { | ||
terms: { | ||
field: SERVICE_VERSION | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
).aggregations?.versions.buckets.map(bucket => bucket.key) ?? []; | ||
|
||
if (versions.length > 1) { | ||
const annotations = await Promise.all( | ||
versions.map(async version => { | ||
const response = await client.search({ | ||
index: indices['apm_oss.transactionIndices'], | ||
body: { | ||
size: 0, | ||
query: { | ||
bool: { | ||
filter: filter | ||
.filter(esFilter => !Object.keys(esFilter).includes('range')) | ||
.concat({ | ||
term: { | ||
[SERVICE_VERSION]: version | ||
} | ||
}) | ||
} | ||
}, | ||
aggs: { | ||
first_seen: { | ||
min: { | ||
field: '@timestamp' | ||
} | ||
} | ||
}, | ||
track_total_hits: false | ||
} | ||
}); | ||
|
||
const firstSeen = response.aggregations?.first_seen.value; | ||
|
||
if (!isNumber(firstSeen)) { | ||
throw new Error( | ||
'First seen for version was unexpectedly undefined or null.' | ||
); | ||
} | ||
|
||
if (firstSeen < start || firstSeen > end) { | ||
return null; | ||
} | ||
|
||
return { | ||
type: AnnotationType.VERSION, | ||
id: version, | ||
time: firstSeen, | ||
text: version | ||
}; | ||
}) | ||
); | ||
return annotations.filter(Boolean) as Annotation[]; | ||
} | ||
return []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.