-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add downstream dependency service name to logs and errors to improve alert insights #183215
Merged
sorenlouv
merged 6 commits into
elastic:main
from
sorenlouv:improve-contextual-alert-insights
May 13, 2024
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4fe52c2
Add downstream dependency service name to logs and errors
sorenlouv eab4222
Merge branch 'main' into improve-contextual-alert-insights
sorenlouv 76602aa
Merge branch 'main' into improve-contextual-alert-insights
sorenlouv 8db9b30
Remove console.log
sorenlouv 17a1fc2
declare `errorCategory `
sorenlouv cb57b71
Re-write clause for matching search query
sorenlouv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
50 changes: 50 additions & 0 deletions
50
...rver/routes/assistant_functions/get_observability_alert_details_context/get_apm_errors.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,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import datemath from '@elastic/datemath'; | ||
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client'; | ||
import { getErrorGroupMainStatistics } from '../../errors/get_error_groups/get_error_group_main_statistics'; | ||
import { getDownstreamServiceResource } from './get_downstream_dependency_name'; | ||
|
||
export async function getApmErrors(params: { | ||
apmEventClient: APMEventClient; | ||
start: string; | ||
end: string; | ||
serviceName: string; | ||
serviceEnvironment?: string; | ||
}) { | ||
const { apmEventClient, serviceName, serviceEnvironment } = params; | ||
|
||
const start = datemath.parse(params.start)?.valueOf()!; | ||
const end = datemath.parse(params.end)?.valueOf()!; | ||
|
||
const res = await getErrorGroupMainStatistics({ | ||
serviceName, | ||
apmEventClient, | ||
environment: serviceEnvironment, | ||
start, | ||
end, | ||
maxNumberOfErrorGroups: 100, | ||
}); | ||
|
||
const promises = res.errorGroups.map(async (errorGroup) => { | ||
if (!errorGroup.traceId) { | ||
return { ...errorGroup, downstreamServiceResource: undefined }; | ||
} | ||
|
||
const downstreamServiceResource = await getDownstreamServiceResource({ | ||
traceId: errorGroup.traceId, | ||
start, | ||
end, | ||
apmEventClient, | ||
}); | ||
|
||
return { ...errorGroup, downstreamServiceResource }; | ||
}); | ||
|
||
return Promise.all(promises); | ||
} |
58 changes: 58 additions & 0 deletions
58
...stant_functions/get_observability_alert_details_context/get_downstream_dependency_name.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,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { rangeQuery } from '@kbn/observability-plugin/server'; | ||
import { ApmDocumentType } from '../../../../common/document_type'; | ||
import { termQuery } from '../../../../common/utils/term_query'; | ||
import { | ||
EVENT_OUTCOME, | ||
SPAN_DESTINATION_SERVICE_RESOURCE, | ||
TRACE_ID, | ||
} from '../../../../common/es_fields/apm'; | ||
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client'; | ||
import { RollupInterval } from '../../../../common/rollup'; | ||
|
||
export async function getDownstreamServiceResource({ | ||
traceId, | ||
start, | ||
end, | ||
apmEventClient, | ||
}: { | ||
traceId: string; | ||
start: number; | ||
end: number; | ||
apmEventClient: APMEventClient; | ||
}) { | ||
const response = await apmEventClient.search('get_error_group_main_statistics', { | ||
apm: { | ||
sources: [ | ||
{ | ||
documentType: ApmDocumentType.SpanEvent, | ||
rollupInterval: RollupInterval.None, | ||
}, | ||
], | ||
}, | ||
body: { | ||
track_total_hits: false, | ||
size: 1, | ||
_source: ['span.destination.service'], | ||
query: { | ||
bool: { | ||
filter: [ | ||
...termQuery(TRACE_ID, traceId), | ||
...termQuery(EVENT_OUTCOME, 'failure'), | ||
...rangeQuery(start, end), | ||
{ exists: { field: SPAN_DESTINATION_SERVICE_RESOURCE } }, | ||
], | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const hit = response.hits.hits[0]; | ||
return hit?._source?.span.destination?.service.resource; | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The downstream service name is resolved via a single sample trace id. The error could have multiple failed downstream dependencies. Ideally we'd get every downstream dependency for the given error. Not sure how in a performant manner