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

Metrics for page resources #26

Merged
merged 6 commits into from
Aug 1, 2016
Merged

Metrics for page resources #26

merged 6 commits into from
Aug 1, 2016

Conversation

theninj4
Copy link
Contributor

@theninj4 theninj4 commented Jul 29, 2016

This PR enables a config driven approach to gathering page resource metrics. Resolves #3

The functionality is best read on the README.md, the TL;DR is that the feature is controlled via:

window.barometer.resources = [
  { domain: 'example.com', path: /\.js$/, metrics: [ 'startTime', 'duration' ] }
]

The production build size currently increases from 2.31KB to 2.79KB. Not too bad considering what we get.

@@ -45,6 +45,7 @@ Metrics are gathered in the format used by a statsd / graphite / grafana stack -
* PageChange - When the page loads, or whenever a navigation event occurs, we log a counter for the page visit and a gauge for how long the page load took. The page load is a measure of the time between the navigation event firing, the event loop lagging for over 25ms and finally the event loop freeing up for 125ms. Basically we wait for the page to get busy, then we wait for it to finish being busy.
* PageLoad - We use `window.performance` to get details of the initial page load.
* XhrStats - We monkey-patch over `XMLHttpRequest` in order to identify every AJAX request, the destination, the transition between states, final response size and timing.
* PageResources - `connectEnd`, `connectStart`, `domainLookupEnd`, `domainLookupStart`, `duration`, `fetchStart`, `redirectEnd`, `redirectStart`, `requestStart`, `responseEnd`, `responseStart`, `secureConnectionStart`, `startTime`, `workerStart`.

Choose a reason for hiding this comment

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

Seems inconsistent to list these for pageLoad but not the others

@msaspence
Copy link

I agree that the 4.6KB is worth it but might be nice to have a build time config that can exclude them for custom builds. I've created #27 to consider that

@theninj4
Copy link
Contributor Author

This work only adds 0.46KB ;) I'll come back to this on Sunday and write the full documentation (the listing in the README was there so I didn't lose it) and tests. Should be good to ship come Monday morning.

@msaspence
Copy link

Sorry that's what I meant, still reeling from yesterdays rabbit hunt

}

pageResources.findRule = function (entry) {
var config = window.barometer.resources
Copy link

@msaspence msaspence Jul 30, 2016

Choose a reason for hiding this comment

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

I'm thinking about this for bandwidthStats:

if (barometer.bandwidth === false) return 
var config = barometer.bandwidth || {}

this will give null or undefined values a default config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going with the idea that you don't define it if you don't want it. If you do define it, it should be an array of properties to match on and the metrics we want to capture. The default value should be [] in the code you've highlighted - I'll get to it on Sunday ;)

Choose a reason for hiding this comment

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

This does seem like one that should be disabled by default, maybe bandwidth as well, not sure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry, I've just re-read this now I'm fully behind a computer, I think we were talking about different things. I think you're right, bandwidth should be an opt-in, and maybe locked behind an onPageChanged event to limit any impact on end user experience. The other modules in this project check for appropriate browser support before they kick off - a similar approach can be taken for config. If there's no config, the module simply won't initialise.

@theninj4
Copy link
Contributor Author

I've gone to town on the documentation @msaspence

@theninj4
Copy link
Contributor Author

I've added a new test and it's passing in all environments 👍

@jackdclark jackdclark self-assigned this Aug 1, 2016
pageResources.track = function (entry, metrics) {
var parts = entry.name.replace(/https?:\/\//i, '').split('/')
var prefix = 'resources.' + entry.entryType + '.'
prefix += parts.shift().replace(/[^a-z0-9_]/gi, '_')

Choose a reason for hiding this comment

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

Might be worth setting /[^a-z0-9_]/gi as a var?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The less code the better ;) Space is precious! If the code became unreadable, then fair enough. For now, I think it's good enough.

@connormeredith
Copy link

Minor comment, overall looks great 👍

@jackdclark
Copy link

👍

@theninj4 theninj4 merged commit 8f0ccd8 into master Aug 1, 2016
@theninj4 theninj4 deleted the page-resources branch August 1, 2016 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants