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

[Metrics UI] Fixing race condition in Metric Threshold alerts #98563

Conversation

simianhacker
Copy link
Member

@simianhacker simianhacker commented Apr 27, 2021

Summary

This PR fixes #97150 by refactoring useMetricsExplorerData to use useTrackedPromises and then rely on the cancelPreviousOn set to creation to cancel the previous request. Since the basic behavior should remain the same the original use_metrics_explorer_data.test.tsx tests should pass.

Setup for Testing

In order to test this, you need to put the Metrics Explorer code into a state where the some requests are delayed. To do this add the following code to x-pack/plugins/infra/server/routes/metrics_explorer/index.ts starting on line 57:

const sleep = (milliseconds: number) => {
  return new Promise((resolve) => setTimeout(resolve, milliseconds));
};

const hasHostName = /host\.name/.test(optionsWithInterval.filterQuery || '');
const hasEventDataset = /event\.dataset/.test(optionsWithInterval.filterQuery || '');
console.log('hasHostName', hasHostName, 'hasEventDataset', hasEventDataset);

if (hasHostName && !hasEventDataset) {
  await sleep(3000);
}

Steps for Testing

  1. Open a browser with the network traffic tab open in the dev console
  2. Create some hosts using the latest version of Slingshot via:
    ./bin/slingshot.ts load --config ./configs/hosts.json --purge --start now-5d/d --end now+1d/d
  3. Create a Metric Threshold alert for Average of system.cpu.total.pct and filter by host.name: "host-0" and event.dataset: "system.memory"
  4. Select and event.dataset: "system.memory", cut it then paste it immediately.

Before the fix, it should make a request for only host.name: "host-0", which should take ~3 seconds and then a request with host.name: "host-0" and event.dataset: "system.memory" should happen but return almost immediately. The screen will update with a blank chart (from the second request) and then update to a chart with data (from the first request).

After the fix the chart should display the results from the second request, even when the first request completes afterwards.

@simianhacker simianhacker added Feature:Metrics UI Metrics UI feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.14.0 v8.0.0 labels Apr 27, 2021
@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
infra 1.9MB 1.9MB +486.0B

History

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

@sgrodzicki
Copy link

Can we get this in for v7.13.0 too?

@simianhacker simianhacker marked this pull request as ready for review April 28, 2021 15:43
@simianhacker simianhacker requested a review from a team as a code owner April 28, 2021 15:43
@elasticmachine
Copy link
Contributor

Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui)

Copy link
Contributor

@estermv estermv left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@simianhacker simianhacker merged commit 9b28ec8 into elastic:master Apr 29, 2021
simianhacker added a commit to simianhacker/kibana that referenced this pull request Apr 30, 2021
…c#98563)

* [Metrics UI] Fixing race condition in Metric Threshold alerts

* fixing type issue
simianhacker added a commit to simianhacker/kibana that referenced this pull request Apr 30, 2021
…c#98563)

* [Metrics UI] Fixing race condition in Metric Threshold alerts

* fixing type issue
simianhacker added a commit that referenced this pull request Apr 30, 2021
#98978)

* [Metrics UI] Fixing race condition in Metric Threshold alerts

* fixing type issue
simianhacker added a commit that referenced this pull request Apr 30, 2021
#98977)

* [Metrics UI] Fixing race condition in Metric Threshold alerts

* fixing type issue
@simianhacker simianhacker deleted the issue-97150-fix-race-condition-in-metric-threshold-alerts branch April 17, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Metrics UI Metrics UI feature release_note:fix Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.13.0 v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metric threshold alert preview has a race condition
5 participants