-
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
[ML] APM Latency Correlations: Code consolidation. #110790
[ML] APM Latency Correlations: Code consolidation. #110790
Conversation
This reverts commit ca86f76.
x-pack/plugins/apm/server/lib/search_strategies/queries/query_histograms_generator.ts
Show resolved
Hide resolved
@@ -90,16 +89,16 @@ export const asyncSearchServiceStateProvider = () => { | |||
overallHistogram, | |||
percentileThresholdValue, | |||
progress, | |||
values, | |||
latencyCorrelations, | |||
}; |
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.
Instead of:
return {
ccsWarning,
error,
isCancelled,
isRunning,
overallHistogram,
percentileThresholdValue,
progress,
latencyCorrelations,
};
What about having a consistent interface for all kibana search services like:
return {
error,
status,
data
};
status
can perhaps borrow the status from useFetcher
and data
can contain the rest.
I'm also not sure about the top level progress
. It seems like we are doing three separate calls. They could each have their own status
data: {
overallHistogram: { data, status, progress },
percentileThresholdValue: { data, status, progress },
latencyCorrelations: { data, status, progress }
}
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.
That code is an implementation detail of the async code that fetches results. In the code that manages the Kibana search strategy we have then to stick to the format Kibana's search strategies are expecting, that is:
{
id: string;
loaded: number;
total: number;
isRunning: boolean;
isPartial: boolean;
rawResponse: T;
}
So Kibana's Search strategy is expecting one total progress. On the client side, useStrategy
will receive and split it into progress
(loaded, total, isRunning, is Partial) and response
(rawResponse) to be more in line with the structure of the rest of APM's code.
onCancel={cancelFetch} | ||
/> | ||
|
||
{ccsWarning && ( | ||
{response.ccsWarning && ( | ||
<> | ||
<EuiSpacer size="m" /> | ||
<CrossClusterSearchCompatibilityWarning version="7.15" /> |
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.
This is 7.14 for latency correlations. Is that on purpose?
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.
Yes this one is on purpose, latency correlations uses ES aggregation that are available since 7.14, but failed transaction correlations uses ES aggs that were only introduced in 7.15.
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.
And this is only a problem when the user is using ccs? It works if they use a local cluster?
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.
In the Kibana UI the updated feature with this functionality is not part of 7.14, so if the local cluster + Kibana is 7.14, they won't run into a problem, the updated feature is simply not there. If the local cluster + Kibana is 7.15 with the updated feature, a cross cluster search against 7.14- will return errors, that's when we show the callout.
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.
Latest changes LGTM. Also gave it a quick test.
x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx
Outdated
Show resolved
Hide resolved
columns={failedTransactionsCorrelationsColumns} | ||
significantTerms={correlationTerms} | ||
status={isRunning ? FETCH_STATUS.LOADING : FETCH_STATUS.SUCCESS} | ||
status={ | ||
progress.isRunning ? FETCH_STATUS.LOADING : FETCH_STATUS.SUCCESS |
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.
I'm wondering if we should just apply this status server side?
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.
isRunning
is part of Kibana's search strategy contract, we cannot replace it, we could just add our own loading logic in addition on top of Kibana's customizable rawResponse
which I'd like to avoid.
x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx
Outdated
Show resolved
Hide resolved
const selectedTerm = useMemo(() => { | ||
if (selectedSignificantTerm) return selectedSignificantTerm; | ||
return result?.values && | ||
Array.isArray(result.values) && | ||
result.values.length > 0 | ||
? result?.values[0] | ||
return Array.isArray(response.failedTransactionsCorrelations) && | ||
response.failedTransactionsCorrelations.length > 0 | ||
? response.failedTransactionsCorrelations[0] | ||
: undefined; | ||
}, [selectedSignificantTerm, result]); | ||
}, [selectedSignificantTerm, response.failedTransactionsCorrelations]); |
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.
Afaict this doesn't need to be memoized:
const selectedTerm = selectedSignificantTerm ?? response.failedTransactionsCorrelations?.[0]
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.
Updated in b665413.
@@ -293,9 +242,14 @@ export function LatencyCorrelations({ onFilter }: { onFilter: () => void }) { | |||
field: sortField, | |||
direction: sortDirection, | |||
}, | |||
} as EuiTableSortingType<MlCorrelationsTerms>, | |||
} as EuiTableSortingType<LatencyCorrelation>, |
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.
nit: afaict there's no need to memoize sorting
.
const sorting = {
sort: { field: sortField, direction: sortDirection },
} as EuiTableSortingType<LatencyCorrelation>;
const histogramTerms = useMemo(
() => orderBy(response.latencyCorrelations ?? [], sortField, sortDirection),
[response.latencyCorrelations, sortField, sortDirection]
);
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.
Updated in 6076fbf.
💚 Build Succeeded
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @walterra |
Thanks for all the improvements! Code is much more readable now. I'm sure I can keep nitpicking forever but this is a great improvement as-is. |
Code deduplication: - combine 3 existing client side hooks into useSearchStrategy - combine server side multiple search strategy files into shared search_strategy_provider.ts - Clarified naming (client/server params, strategy naming etc.), improved types. - None of the actual deeper internal logic changed, larger chunks of code that show up as new lines is mostly just moved code + additional types (e.g. function overloads) to support the different search strategies with the same server side code and client side hook.
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
…-link-to-kibana-app * 'master' of github.com:elastic/kibana: (61 commits) [Logs UI] Fix alert previews for thresholds of `0` (elastic#111150) [Archive Migration][Partial] discover apps-discover (elastic#110437) [APM] Set start date of APM ML job to -4 weeks (elastic#111375) [ML] APM Latency Correlations: Code consolidation. (elastic#110790) [Discover] Fix indices permission for multiline test (elastic#111284) [Detection Rules] Add 7.15 rules (elastic#111464) [Security Solution][Endpoint][Host Isolation] Hide isolate host option in alert details rather than disabling (elastic#111064) React version of angular license view (elastic#111317) [APM] Fix link in readme (elastic#111362) [Security Solution] add agent field to generator (elastic#111428) [Dashboard] Retain Tags on Quicksave (elastic#111015) Reorder App Search ingestion methods (elastic#111361) Port performance docs to new docs system. (elastic#111063) [Security Solution][RAC] Fixes updatedAt loading bug (elastic#111010) [sample data] update web log geo.src field to match country code of geo.coordinates (elastic#110885) [Security solution] [Endpoint] Fix bad artifact migration (elastic#111294) Fix copy typo. (elastic#111203) [build] Remove empty optimize directory (elastic#111393) [Maps] fix term join not updating when editing right field (elastic#111030) [Fleet] Set default settings in component template instead of the index template (elastic#111197) ... # Conflicts: # x-pack/plugins/reporting/public/management/__snapshots__/report_listing.test.tsx.snap # x-pack/plugins/reporting/public/management/report_listing.test.tsx
Code deduplication: - combine 3 existing client side hooks into useSearchStrategy - combine server side multiple search strategy files into shared search_strategy_provider.ts - Clarified naming (client/server params, strategy naming etc.), improved types. - None of the actual deeper internal logic changed, larger chunks of code that show up as new lines is mostly just moved code + additional types (e.g. function overloads) to support the different search strategies with the same server side code and client side hook. Co-authored-by: Walter Rafelsberger <[email protected]>
Code deduplication: - combine 3 existing client side hooks into useSearchStrategy - combine server side multiple search strategy files into shared search_strategy_provider.ts - Clarified naming (client/server params, strategy naming etc.), improved types. - None of the actual deeper internal logic changed, larger chunks of code that show up as new lines is mostly just moved code + additional types (e.g. function overloads) to support the different search strategies with the same server side code and client side hook.
Summary
Part of #109220.
useSearchStrategy
search_strategy_provider.ts
useSearchStrategy
uses generic types and function overloads to provide types for parameters and the response based on the strategy name.In the examples above, both are valid TS, based on the strategy name the first one doesn't require any additional parameters whereas the second one does. The client and server code share the same types defined in
plugins/apm/common/search_strategies/*
so it only has to be defined once.Checklist
Delete any items that are not applicable to this PR.