-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af8f9fa
commit 399eed7
Showing
51 changed files
with
1,640 additions
and
266 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"include": [ | ||
"./plugins/apm/**/*", | ||
"./plugins/observability/**/*", | ||
"./typings/**/*" | ||
], | ||
"exclude": [ | ||
|
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
111 changes: 111 additions & 0 deletions
111
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,111 @@ | ||
/* | ||
* 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_VERSION | ||
} from '../../../../common/elasticsearch_fieldnames'; | ||
import { getEnvironmentUiFilterES } from '../../helpers/convert_ui_filters/get_environment_ui_filter_es'; | ||
|
||
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' } }, | ||
{ term: { [SERVICE_NAME]: serviceName } } | ||
]; | ||
|
||
const environmentFilter = getEnvironmentUiFilterES(environment); | ||
|
||
if (environmentFilter) { | ||
filter.push(environmentFilter); | ||
} | ||
|
||
const versions = | ||
( | ||
await client.search({ | ||
index: indices['apm_oss.transactionIndices'], | ||
body: { | ||
size: 0, | ||
query: { | ||
bool: { | ||
filter: filter.concat({ range: rangeFilter(start, end) }) | ||
} | ||
}, | ||
aggs: { | ||
versions: { | ||
terms: { | ||
field: SERVICE_VERSION | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
).aggregations?.versions.buckets.map(bucket => bucket.key) ?? []; | ||
|
||
if (versions.length <= 1) { | ||
return []; | ||
} | ||
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.concat({ | ||
term: { | ||
[SERVICE_VERSION]: version | ||
} | ||
}) | ||
} | ||
}, | ||
aggs: { | ||
first_seen: { | ||
min: { | ||
field: '@timestamp' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
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, | ||
'@timestamp': firstSeen, | ||
text: version | ||
}; | ||
}) | ||
); | ||
return annotations.filter(Boolean) as Annotation[]; | ||
} |
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/apm/server/lib/services/annotations/get_stored_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,76 @@ | ||
/* | ||
* 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 { APICaller } from 'kibana/server'; | ||
import { SERVICE_NAME } from '../../../../common/elasticsearch_fieldnames'; | ||
import { ESSearchResponse } from '../../../../typings/elasticsearch'; | ||
import { ScopedAnnotationsClient } from '../../../../../observability/server'; | ||
import { Annotation, AnnotationType } from '../../../../common/annotations'; | ||
import { Annotation as ESAnnotation } from '../../../../../observability/common/annotations'; | ||
import { SetupTimeRange, Setup } from '../../helpers/setup_request'; | ||
import { getEnvironmentUiFilterES } from '../../helpers/convert_ui_filters/get_environment_ui_filter_es'; | ||
|
||
export async function getStoredAnnotations({ | ||
setup, | ||
serviceName, | ||
environment, | ||
apiCaller, | ||
annotationsClient | ||
}: { | ||
setup: Setup & SetupTimeRange; | ||
serviceName: string; | ||
environment?: string; | ||
apiCaller: APICaller; | ||
annotationsClient: ScopedAnnotationsClient; | ||
}): Promise<Annotation[]> { | ||
try { | ||
const environmentFilter = getEnvironmentUiFilterES(environment); | ||
|
||
const response: ESSearchResponse<ESAnnotation, any> = (await apiCaller( | ||
'search', | ||
{ | ||
index: annotationsClient.index, | ||
body: { | ||
size: 50, | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ | ||
range: { | ||
'@timestamp': { | ||
gte: setup.start, | ||
lt: setup.end | ||
} | ||
} | ||
}, | ||
{ term: { 'annotation.type': 'deployment' } }, | ||
{ term: { tags: 'apm' } }, | ||
{ term: { [SERVICE_NAME]: serviceName } }, | ||
...(environmentFilter ? [environmentFilter] : []) | ||
] | ||
} | ||
} | ||
} | ||
} | ||
)) as any; | ||
|
||
return response.hits.hits.map(hit => { | ||
return { | ||
type: AnnotationType.VERSION, | ||
id: hit._id, | ||
'@timestamp': new Date(hit._source['@timestamp']).getTime(), | ||
text: hit._source.message | ||
}; | ||
}); | ||
} catch (error) { | ||
// index is only created when an annotation has been indexed, | ||
// so we should handle this error gracefully | ||
if (error.body?.error?.type === 'index_not_found_exception') { | ||
return []; | ||
} | ||
throw error; | ||
} | ||
} |
Oops, something went wrong.