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
feat: post process screenshots for deduping #290
feat: post process screenshots for deduping #290
Conversation
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
Trends 🧪 |
src/reporters/json.ts
Outdated
const left = col * blockWidth; | ||
const buf = await img | ||
.extract({ top, left, width: blockWidth, height: blockHeight }) | ||
.toFormat(sharp.format.webp) |
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.
self note:
- check the size of individual blocks using different format.
- Run benchmarks on this function.
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.
webp even though smaller than png by ~20ms average would yield more savings. Will leave it as webp for now.
Processing 50 images
webp - 14.36 seconds
png - 13.119 seconds
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.
Benchmarks script to play with
!(async () => {
console.time('screenshots');
for (let i = 0; i < 50; i++) {
await gatherScreenshots(
'path/to/.synthetics/pid/screenshots'
);
}
console.timeEnd('screenshots');
})();
c6e5089
to
5ad799d
Compare
*/ | ||
this.stream.flush(); | ||
} | ||
this.runner.on('end', () => this.stream.flush()); |
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.
We don't need to take care of closing the stream as the process exists automatically which closes the underlying stream once program runs to completion. This is better than figuring out when to close and prematurely closing it than leaving it which does not harm.
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.
Love the improvements here left some comments on some ways it could work even better
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.
This PR is essentially LGTM but I'm leaving it in request changes state because we can't merge it as is without breaking things for existing users. If we were to merge and release this today screenshots will not work with current versions of kibana. We really need a system of feature flags or something similar to heartbeat to determine which features are enabled. Heartbeat at least follows the stack versioning, and as a result can inform the code here of how to act.
I think we will also need to support the old way of screenshots working based on whatever system of flags or capabilities we come up with. I've opened #292 to track
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.
There's a bug somewhere in this PR that affects handling of erroring test-cases. Running the following: cat t.js | node dist/cli.js --network --json --inline --screenshots | jq .type
will fail early, not outputting journey/end
and other events, where the contents of t.js
are:
step("load homepage", async () => {
await page.goto('https://www.elastic.co');
});
step("hover over products menu", async () => {
await page.hover('css=[data-nav-item=products]');
});
step("failme", async () => {
await page.hhover('css=[data-nav-item=products]');
});
@andrewvc Could be this #290 (comment), Will check tomorrow. |
Not sure as to the root cause |
Fixed the issue - We do async processing of the events in the microtasks which are being cut of by the CLI node process. Now we wait for the ack from the reporter once its written to the file descriptor before closing the process - 36a42e5 |
const left = col * blockWidth; | ||
const buf = await img | ||
.extract({ top, left, width: blockWidth, height: blockHeight }) | ||
.jpeg() |
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.
changed to jpeg for now, we can play with webp
once we decide a solution in the Kibana.
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.
@justinkambic FYI
expect(callback).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('idempotent on constructing screenshots blocks', async () => { |
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.
Love this!
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.
LGTM
.synthetics/<pid>/screenshots
folder in JSON format withstep
andscreenshot
info. The pid stuff is to make sure each process (workers in future for leveraging parallelism) is writing screenshots to individual folders to avoid mutation.1280*720
viewport (Default) and wrote to heartbeat asscreenshot/block
and the whole screenshot reference is written asstep/screenshot_reference
which can be queried from the Uptime UI to construct all the images from the hash of individual block.