-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM]: Inferred types for aggregations #37360
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b877cef
[APM]: Inferred types for aggregations
dgieselaar bd4bf48
Fix idx error
dgieselaar d6b0d1e
Safeguard against querying against non-existing indices in functional…
dgieselaar 676a69f
Improve metric typings
dgieselaar dc9e936
Automatically infer params from function arguments
dgieselaar 8ac37e6
Remove unnecessary type hints
dgieselaar 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
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { SearchParams } from 'elasticsearch'; | ||
import { idx } from '@kbn/elastic-idx'; | ||
import { | ||
ERROR_CULPRIT, | ||
|
@@ -37,7 +36,10 @@ export async function getErrorGroups({ | |
}) { | ||
const { start, end, uiFiltersES, client, config } = setup; | ||
|
||
const params: SearchParams = { | ||
// sort buckets by last occurrence of error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TS was complaining about changing the shape of the object after creating it, so I moved it inline. |
||
const sortByLatestOccurrence = sortField === 'latestOccurrenceAt'; | ||
|
||
const params = { | ||
index: config.get<string>('apm_oss.errorIndices'), | ||
body: { | ||
size: 0, | ||
|
@@ -56,7 +58,11 @@ export async function getErrorGroups({ | |
terms: { | ||
field: ERROR_GROUP_ID, | ||
size: 500, | ||
order: { _count: sortDirection } | ||
order: sortByLatestOccurrence | ||
? { | ||
max_timestamp: sortDirection | ||
} | ||
: { _count: sortDirection } | ||
}, | ||
aggs: { | ||
sample: { | ||
|
@@ -72,24 +78,22 @@ export async function getErrorGroups({ | |
sort: [{ '@timestamp': 'desc' }], | ||
size: 1 | ||
} | ||
} | ||
}, | ||
...(sortByLatestOccurrence | ||
? { | ||
max_timestamp: { | ||
max: { | ||
field: '@timestamp' | ||
} | ||
} | ||
} | ||
: {}) | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// sort buckets by last occurrence of error | ||
if (sortField === 'latestOccurrenceAt') { | ||
params.body.aggs.error_groups.terms.order = { | ||
max_timestamp: sortDirection | ||
}; | ||
|
||
params.body.aggs.error_groups.aggs.max_timestamp = { | ||
max: { field: '@timestamp' } | ||
}; | ||
} | ||
|
||
interface SampleError { | ||
'@timestamp': APMError['@timestamp']; | ||
error: { | ||
|
@@ -105,44 +109,27 @@ export async function getErrorGroups({ | |
}; | ||
} | ||
|
||
interface Bucket { | ||
key: string; | ||
doc_count: number; | ||
sample: { | ||
hits: { | ||
total: number; | ||
max_score: number | null; | ||
hits: Array<{ | ||
_source: SampleError; | ||
}>; | ||
}; | ||
}; | ||
} | ||
|
||
interface Aggs { | ||
error_groups: { | ||
buckets: Bucket[]; | ||
}; | ||
} | ||
const resp = await client.search(params); | ||
|
||
const resp = await client.search<void, Aggs>(params); | ||
const buckets = idx(resp, _ => _.aggregations.error_groups.buckets) || []; | ||
// aggregations can be undefined when no matching indices are found. | ||
// this is an exception rather than the rule so the ES type does not account for this. | ||
const hits = (idx(resp, _ => _.aggregations.error_groups.buckets) || []).map( | ||
bucket => { | ||
const source = bucket.sample.hits.hits[0]._source as SampleError; | ||
const message = | ||
idx(source, _ => _.error.log.message) || | ||
idx(source, _ => _.error.exception[0].message); | ||
|
||
const hits = buckets.map(bucket => { | ||
const source = bucket.sample.hits.hits[0]._source; | ||
const message = | ||
idx(source, _ => _.error.log.message) || | ||
idx(source, _ => _.error.exception[0].message); | ||
|
||
return { | ||
message, | ||
occurrenceCount: bucket.doc_count, | ||
culprit: idx(source, _ => _.error.culprit), | ||
groupId: idx(source, _ => _.error.grouping_key), | ||
latestOccurrenceAt: source['@timestamp'], | ||
handled: idx(source, _ => _.error.exception[0].handled) | ||
}; | ||
}); | ||
return { | ||
message, | ||
occurrenceCount: bucket.doc_count, | ||
culprit: idx(source, _ => _.error.culprit), | ||
groupId: idx(source, _ => _.error.grouping_key), | ||
latestOccurrenceAt: source['@timestamp'], | ||
handled: idx(source, _ => _.error.exception[0].handled) | ||
}; | ||
} | ||
); | ||
|
||
return hits; | ||
} |
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
64 changes: 0 additions & 64 deletions
64
x-pack/plugins/apm/server/lib/metrics/by_agent/java/heap_memory/fetcher.ts
This file was deleted.
Oops, something went wrong.
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.
values from metric aggregations can be
null
too