Skip to content
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

Merged
merged 46 commits into from
Sep 8, 2021

Conversation

walterra
Copy link
Contributor

@walterra walterra commented Sep 1, 2021

Summary

Part of #109220.

  • 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.

useSearchStrategy uses generic types and function overloads to provide types for parameters and the response based on the strategy name.

  const { progress, response, startFetch, cancelFetch } = useSearchStrategy(
    APM_SEARCH_STRATEGIES.APM_FAILED_TRANSACTIONS_CORRELATIONS
  );

  const { progress, response, startFetch, cancelFetch } = useSearchStrategy(
    APM_SEARCH_STRATEGIES.APM_LATENCY_CORRELATIONS,
    {
      percentileThreshold: DEFAULT_PERCENTILE_THRESHOLD,
      analyzeCorrelations: true,
    }
  );

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.

@walterra walterra self-assigned this Sep 1, 2021
@walterra walterra added the release_note:skip Skip the PR/issue when compiling release notes label Sep 1, 2021
@@ -90,16 +89,16 @@ export const asyncSearchServiceStateProvider = () => {
overallHistogram,
percentileThresholdValue,
progress,
values,
latencyCorrelations,
};
Copy link
Member

@sorenlouv sorenlouv Sep 6, 2021

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 }
}

Copy link
Contributor Author

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" />
Copy link
Member

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?

Copy link
Contributor Author

@walterra walterra Sep 7, 2021

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.

Copy link
Member

@sorenlouv sorenlouv Sep 7, 2021

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@peteharverson peteharverson left a 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.

columns={failedTransactionsCorrelationsColumns}
significantTerms={correlationTerms}
status={isRunning ? FETCH_STATUS.LOADING : FETCH_STATUS.SUCCESS}
status={
progress.isRunning ? FETCH_STATUS.LOADING : FETCH_STATUS.SUCCESS
Copy link
Member

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?

Copy link
Contributor Author

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.

Comment on lines 76 to 82
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]);
Copy link
Member

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]

Copy link
Contributor Author

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>,
Copy link
Member

@sorenlouv sorenlouv Sep 7, 2021

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]
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 6076fbf.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
apm 4.4MB 4.4MB -9.8KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @walterra

@walterra walterra added the auto-backport Deprecated - use backport:version if exact versions are needed label Sep 7, 2021
@sorenlouv
Copy link
Member

sorenlouv commented Sep 7, 2021

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.

@walterra walterra merged commit f1fbe8e into elastic:master Sep 8, 2021
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Sep 8, 2021
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.
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

@walterra walterra deleted the ml-apm-correlations-consolidation-1 branch September 8, 2021 08:26
jloleysens added a commit to jloleysens/kibana that referenced this pull request Sep 8, 2021
…-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
kibanamachine added a commit that referenced this pull request Sep 8, 2021
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]>
chrisronline pushed a commit to chrisronline/kibana that referenced this pull request Sep 8, 2021
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:correlations auto-backport Deprecated - use backport:version if exact versions are needed :ml refactoring release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants