-
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
[Reporting/PDF] Refactor screenshot pipeline for multi-url by default #48588
[Reporting/PDF] Refactor screenshot pipeline for multi-url by default #48588
Conversation
95765da
to
409e56a
Compare
409e56a
to
69614aa
Compare
dfe877d
to
493598d
Compare
493598d
to
7b40c6b
Compare
}), | ||
first() | ||
toArray() |
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.
Main changes (1) of this PR are above
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.
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 }); |
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.
Main changes (2)
layout, | ||
logo | ||
); | ||
}), |
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.
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']); |
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.
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) => { |
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.
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({ |
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.
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)
7b40c6b
to
2aa08df
Compare
logger.debug( | ||
'waiting for elements or items count attribute; or not found to interrupt' | ||
); | ||
return Rx.from(urls).pipe( |
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.
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)
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'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.
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 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.
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.
Looks good, going to pull and test shortly
This comment has been minimized.
This comment has been minimized.
@elasticmachine merge upstream |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
…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>
…#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>
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
andexit$
. 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
strikethroughsto remove checklist items you don't feel are applicable to this PR.[ ] This was checked for cross-browser compatibility, including a check against IE11[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibility