sitespeed.io icon indicating copy to clipboard operation
sitespeed.io copied to clipboard

--script only works with single JS file, not with directory

Open marcokaiser opened this issue 9 years ago • 10 comments

Hi,

I am trying to run some custom scripts to collect additional metrics on the page I'm testing. According to the documentation, it should also be possible to supply a directory via --script, but it only seems to collect any data if I supply a single JS file.

This works: docker-compose run -v $(pwd):/sitespeed.io --rm sitespeed.io http://www.domain.com/ --script /sitespeed.io/scripts/test/myMetric.js

This doesn't: docker-compose run -v $(pwd):/sitespeed.io --rm sitespeed.io http://www.domain.com/ --script /sitespeed.io/scripts/test/

It makes no difference if the directory contains only the single JS file that works by itself or more scripts.

I'm running via docker-compose:

[2017-10-26 14:56:55] INFO: [sitespeedio] Versions OS: linux 4.9.49-moby nodejs: v6.11.1 sitespeed.io: 5.6.5 browsertime: 1.9.4 coach: 0.36.0

Anything I am doing wrong here, or is this a bug?

Thanks in advance for any hints.

marcokaiser avatar Oct 26 '17 15:10 marcokaiser

Hi @marcokaiser sorry I think there is a mismatch between Browsertime (where you can set a dir) and sitespeed.io where you need to point out each and every script (at least that's why I'm guessing). I did a quick test and got the same as you. Let me check that later this week.

Best Peter

P.S Btw, I think the documentation isn't clear on that, but I personally always use docker run .. instead of compose when I run sitespeed.io because I usually run on another server and I only use compose to setup Graphite/Grafana etc.

soulgalore avatar Oct 26 '17 22:10 soulgalore

@soulgalore thanks for your response - that's what I was guessing as well. I can list the scripts individually on the command line, but just throwing them into a directory would make things quite a bit easier, especially given that browsertime does seem to support this. So that makes this more of a feature request than a bug report ;)

As for docker vs. docker-compose - thanks for pointing that out. Are you avoiding running on the same host due to performance concerns that could affect the test results?

marcokaiser avatar Oct 27 '17 07:10 marcokaiser

I think it's bug since the behavior is different. I think only way is to keep the experience the same, since we wanna be able to point to the docs for Browsertime from sitespeed.io (adding browsertime to your cli parameter will push that param to browsertime.

Yes only one thing running on that host where you test. @beenanner tested out different cloud providers before and the winner for us was AWS (I'm just changing that on dashboard.sitespeed.io and will show the results later on). I think GC was to too. The thing it's not a CPU thing, it depends on how well separated the instance is from other things running on the same machine. For example one cloud provider can have metrics that differs 20-30% with more CPU/memory etc than another where the diff is only 5%.

soulgalore avatar Oct 27 '17 09:10 soulgalore

@soulgalore using script with folder works now, you can check once and close the issue.

sumeetrohra avatar Sep 22 '19 17:09 sumeetrohra

@sumeetrohra I didn't follow, did you do a fix or does it just works? :)

soulgalore avatar Sep 22 '19 19:09 soulgalore

@soulgalore it just works :)

sumeetrohra avatar Sep 22 '19 20:09 sumeetrohra

@sumeetrohra can you test one more time? I did a quick test and couldn't see that it works, I think maybe we talk about different things,

I created a new directory and put two JavasScript files in it as simple as possible:

dir/metric1.js

(function() {
    return 1;
})();

and dir/metric2.js

(function() {
    return 2;
})();

And if I add --script dir/ I don't get the metrics but if I run --script dir/metric1.js I get it.

When it works you should see the metric on the tab "Metrics" and scroll down to Custom metrics.

Screenshot 2019-09-23 at 12 39 18

soulgalore avatar Sep 23 '19 10:09 soulgalore

@soulgalore I checked and it's not working, it was working on my system before :sweat: , sorry for the wrong info, I might have made some changes, I'll look into it this week and make sure it works...

sumeetrohra avatar Sep 23 '19 11:09 sumeetrohra

@soulgalore I figured out the problem. sitespeed reads all the scripts and keeps them in an object with key custom, if we pass the scripts individually it gives a new object as

{ custom: 
    {metric1: <script>, metric2: <script>}
}

But if we pass a directory it gives the output as

{<dirName>: 
    {metric1: <script>, metric2: <script>}
}

So I'm making a small check for the key name, it should make things work. P.S. : this is the behaviour of browsertime.browserScripts.findAndParseScripts click here for gist

sumeetrohra avatar Sep 23 '19 12:09 sumeetrohra

Aha I see, good find @sumeetrohra !

soulgalore avatar Sep 23 '19 12:09 soulgalore