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

[Reporting/PDF] Refactor screenshot pipeline for multi-url by default #48588

Merged
merged 9 commits into from
Jan 6, 2020

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Oct 17, 2019

Summary

This PR is primarily improvements to Typescript and simplifying interfaces between modules. I think these changes will go towards implementing scheduled reports because the screenshot observable is easier to invoke.

This takes away the requirement that when using screenshotObservable, you would have to put it in the body of a loop to capture multiple URLs (Or ). This change makes the screenshotObservable take a string array parameter for URLs.

The change includes a refactoring of the screenshotsObservable pipeline. The changes allow for better Typescript inference of the payload type of the pipelines. The screenshot pipeline was also simplified by hoisting out a block of code into a new module called scanPage.

There are also changes to a few other interfaces:

  • browserDriverFactory.test() method doesn't take the layout params, they are hardcoded in the test now.
  • browserDriverFactory.createPage() method accepts a logger object, instead of using a class field for the logger.
  • browserDriverFactory.createPage() method returns an Observable of an object with 2 fields: driver and exit$. Previously, the driver object was an observable to the driver, that had to be piped out to be used. Now, driver is the raw driver. This means that the resolved driver no longer has to be streamed through most of the screenshot observable pipe, as it was before.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

@tsullivan tsullivan force-pushed the reporting/screenshots-multi-url branch 3 times, most recently from 95765da to 409e56a Compare October 25, 2019 22:55
@tsullivan tsullivan force-pushed the reporting/screenshots-multi-url branch from 409e56a to 69614aa Compare December 2, 2019 22:01
@tsullivan tsullivan force-pushed the reporting/screenshots-multi-url branch 6 times, most recently from dfe877d to 493598d Compare December 10, 2019 20:22
@tsullivan tsullivan force-pushed the reporting/screenshots-multi-url branch from 493598d to 7b40c6b Compare December 12, 2019 21:55
@elastic elastic deleted a comment from elasticmachine Dec 12, 2019
@elastic elastic deleted a comment from elasticmachine Dec 12, 2019
@elastic elastic deleted a comment from elasticmachine Dec 12, 2019
@elastic elastic deleted a comment from elasticmachine Dec 12, 2019
@elastic elastic deleted a comment from elasticmachine Dec 12, 2019
@elastic elastic deleted a comment from elasticmachine Dec 12, 2019
@elastic elastic deleted a comment from elasticmachine Dec 12, 2019
@elastic elastic deleted a comment from elasticmachine Dec 12, 2019
}),
first()
toArray()
Copy link
Member Author

Choose a reason for hiding this comment

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

Main changes (1) of this PR are above

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, having the first operator is important, so that the observable actually finishes.

map(decryptedHeaders => omitBlacklistedHeaders({ job, decryptedHeaders })),
map(filteredHeaders => getConditionalHeaders({ server, job, filteredHeaders })),
concatMap(conditionalHeaders => {
const urls = getFullUrls({ server, job });
Copy link
Member Author

Choose a reason for hiding this comment

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

Main changes (2)

layout,
logo
);
}),
Copy link
Member Author

Choose a reason for hiding this comment

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

main changes (3)

@@ -206,7 +213,7 @@ export class HeadlessChromiumDriverFactory {
// just log closing of the process
const processClose$ = Rx.fromEvent<void>(childProcess, 'close').pipe(
tap(() => {
this.logger.debug('child process closed', ['headless-browser-process']);
logger.debug('child process closed', ['headless-browser-process']);
Copy link
Member Author

Choose a reason for hiding this comment

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

main changes (4) - pass a logger object to createPage instead have a this.logger

throw new Error('Could not close browser client handle!');
}
});
return browserFactory.test(logger).then((browser: Browser | null) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Opportune change: the test method doesn't need a dynamic viewport

@@ -43,7 +43,7 @@ describe('headers', () => {
};

const encryptedHeaders = await encryptHeaders(headers);
const { decryptedHeaders } = await decryptJobHeaders({
const decryptedHeaders = await decryptJobHeaders({
Copy link
Member Author

@tsullivan tsullivan Dec 12, 2019

Choose a reason for hiding this comment

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

Pipeline methods no longer need to have return value destructured, because they (usually) only return what is necessary. They no longer need to return a caravan of objects to get carried down the pipeline.

This is an effect of main change (1)

@tsullivan tsullivan marked this pull request as ready for review December 12, 2019 22:02
@tsullivan tsullivan added the (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead label Dec 12, 2019
@tsullivan tsullivan added v7.6.0 v8.0.0 release_note:skip Skip the PR/issue when compiling release notes review labels Dec 12, 2019
@tsullivan tsullivan force-pushed the reporting/screenshots-multi-url branch from 7b40c6b to 2aa08df Compare December 12, 2019 22:10
logger.debug(
'waiting for elements or items count attribute; or not found to interrupt'
);
return Rx.from(urls).pipe(
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to go with concatMap over mergeMap? I'm assuming it has to do with the utility return signature change (I did read over both in the rxjs docs)

Copy link
Member Author

Choose a reason for hiding this comment

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

I've read over the docs quite a bit too, and I'll admit it is hard to understand how the difference will matter to us. The subscription pipeline handles one incoming event, and then is destroyed, so there are no incoming subsequent events that need to be in sync with the first one.

I think that is the reason I switched from mergeMap to concatMap - it seemed to make more sense with the fact that the pipeline is used for a single event, and then the subscription is cancelled. The next event gets a new subscription.

Thinking about it now, having the breakup of multiple mergeMap or concatMap is really about syntax and style. There could be just the concatMap on line 44 and it chains the async functions together and forms a payload, or cancels itself from the exit$.

Given how hard it was to try to justify, I think another change is due in this PR to simplify things here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think there is some justifiable reasoning in keeping the pipeline separated using observable operators, instead of having a larger function with multiple async steps. The observable pipeline is cancelable, and we're racing the pipeline against the exit$ observable.

Copy link
Contributor

@joelgriffith joelgriffith left a comment

Choose a reason for hiding this comment

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

Looks good, going to pull and test shortly

@elasticmachine

This comment has been minimized.

@tsullivan
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@tsullivan tsullivan merged commit fa8da7c into elastic:master Jan 6, 2020
@tsullivan tsullivan deleted the reporting/screenshots-multi-url branch January 6, 2020 21:34
tsullivan added a commit to tsullivan/kibana that referenced this pull request Jan 6, 2020
…elastic#48588)

* Multi-url pass to screenshotsObservable

* Restore "first" operator

* max attempt = 1 for testing

* cleanup debug

* restore more concatMap

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
tsullivan added a commit that referenced this pull request Jan 7, 2020
…#48588) (#54075)

* Multi-url pass to screenshotsObservable

* Restore "first" operator

* max attempt = 1 for testing

* cleanup debug

* restore more concatMap

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead release_note:skip Skip the PR/issue when compiling release notes review v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants