Skip to content

Fix #22581 by introducing an artificial delay#22601

Merged
chrisdavies merged 5 commits intoelastic:masterfrom
chrisdavies:reporting/22581-blank-report-visualizations
Sep 5, 2018
Merged

Fix #22581 by introducing an artificial delay#22601
chrisdavies merged 5 commits intoelastic:masterfrom
chrisdavies:reporting/22581-blank-report-visualizations

Conversation

@chrisdavies
Copy link
Copy Markdown
Contributor

Chromium reports occasionally render a blank initial visualization. It seems that this might happen due to visualizations triggering renderComplete prior to actually being in the DOM. This change introduces a setTimeout in the waitForRenderComplete function which will hopefully mitigate the issue.

waitForRenderComplete function in reporting
@chrisdavies chrisdavies added Feature:Visualizations Generic visualization features (in case no more specific feature label is available) :Sharing zDeprecated Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead v7.0.0 v6.5.0 labels Aug 31, 2018
// we wait for the event loop to flush before resolving the promise. This
// seems to correct the timing issue and prevents us from capturing
// visualization screenshots before they're rendered.
visualization.addEventListener('renderComplete', () => setTimeout(resolve));
Copy link
Copy Markdown
Contributor Author

@chrisdavies chrisdavies Aug 31, 2018

Choose a reason for hiding this comment

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

We could probably put the setTimeout in a .then at the bottom of this function... (e.g. return Promise.all(renderedTasks).then(new Promise(r => setTimeout(r))); That would prevent us from queuing up a setTimeout per visualization, but would still give us the desired effect of waiting for the event loop to flush before resolving.

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@stacey-gammon
Copy link
Copy Markdown

retest

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@stacey-gammon
Copy link
Copy Markdown

retest

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@chrisdavies
Copy link
Copy Markdown
Contributor Author

retest

Copy link
Copy Markdown

@stacey-gammon stacey-gammon left a comment

Choose a reason for hiding this comment

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

As discussed offline, I think it's fine to check this in as a short term fix so we can both fix the tests and the legit reporting bug, but the longer term fix should ideally be in the visualization code to emit the renderComplete flag only after the visualizations are loaded in the DOM.

Lets file an issue for that to keep track and then we can loop back around to this.

@chrisdavies
Copy link
Copy Markdown
Contributor Author

For the record, the related bug is here:

#22654

@chrisdavies
Copy link
Copy Markdown
Contributor Author

Gah! Gradle failing again.

@chrisdavies
Copy link
Copy Markdown
Contributor Author

retest

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@chrisdavies
Copy link
Copy Markdown
Contributor Author

retest

Copy link
Copy Markdown
Contributor

@timroes timroes left a comment

Choose a reason for hiding this comment

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

LGTM as a workaround for the broken vis behavior until we can fix that properly

@chrisdavies
Copy link
Copy Markdown
Contributor Author

Gradle failed to build again.

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@chrisdavies
Copy link
Copy Markdown
Contributor Author

retest

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@stacey-gammon
Copy link
Copy Markdown

hmmm, looks like this might not be the solution.

Latest failure is snapshot failure with no pie chart.

screen shot 2018-09-04 at 8 49 26 pm

jenkins test this

@chrisdavies
Copy link
Copy Markdown
Contributor Author

Yup. We need a robust way to determine if a visualization is actually present and visible in the DOM. Looks like timing-based solutions are not going to work. The original code waited for the visualizations to report "ready", then resized the browser, then rendered the report. We now resize the browser, wait for "ready", then render the report. The resize in the original seems to have introduced a long enough delay that the visualizations actually were ready by the time we started capturing.

We reordered things due to another bug, so I don't think we want to change the order. Instead, we want to come up with a robust way of reporting "ready". While we wait for that solution, we can come up with workarounds such as introducing a longer delay following the "ready" event.

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@chrisdavies
Copy link
Copy Markdown
Contributor Author

chrisdavies commented Sep 5, 2018

Thinking about this this AM, and what kind of workarounds we might put in place.

  • Add a real timeout (instead of an instant one like this fix introduced)
  • Add a DOM observer and wait until the DOM has not been modified for N milliseconds

For the latter, we could use a function that looks something like this:

function waitForDOMToSettle(fn, ms) {
  let timeout;
  const node = document.body;
  const observer = new MutationObserver(onChange);

  function onChange() {
    clearTimeout(timeout);
    timeout = setTimeout(doneObserving, ms);
  }

  function doneObserving() {
    observer.disconnect();
    fn();
  }

  observer.observe(node, { childList: true, subtree: true });
  onChange();
}

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@chrisdavies
Copy link
Copy Markdown
Contributor Author

retest

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@chrisdavies chrisdavies merged commit ccf455e into elastic:master Sep 5, 2018
@chrisdavies chrisdavies deleted the reporting/22581-blank-report-visualizations branch September 5, 2018 15:10
chrisdavies added a commit to chrisdavies/kibana that referenced this pull request Sep 5, 2018
Introduce a delay into reports to allow visualizations time to appear in the DOM. This is intended as a temporary (and hacky) workaround until we come up with a more robust way to determine that all of the visualizations on the page are ready for capture.
chrisdavies added a commit that referenced this pull request Sep 5, 2018
Introduce a delay into reports to allow visualizations time to appear in the DOM. This is intended as a temporary (and hacky) workaround until we come up with a more robust way to determine that all of the visualizations on the page are ready for capture.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Visualizations Generic visualization features (in case no more specific feature label is available) v6.5.0 v7.0.0 zDeprecated Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants