Move stats collection sample rate to config

This way, we can update the rate in one place.
This commit is contained in:
Jack Lawson
2014-10-21 11:35:41 -07:00
parent 923f427545
commit d5fedb0a4e
3 changed files with 11 additions and 4 deletions

View File

@@ -202,6 +202,8 @@ error_reporters =
statsd_addr =
# how often to send them [0.0 - 1.0]
statsd_sample_rate = 1.0
# percentage of stats for sampling (0-100)
stats_sample_rate = 1
############################################ MEDIA STORAGE

View File

@@ -151,6 +151,7 @@ def js_config(extra_config=None):
# where do ajax requests go?
"ajax_domain": get_domain(cname=c.authorized_cname, subreddit=False),
"stats_domain": g.stats_domain or '',
"stats_sample_rate": g.stats_sample_rate or 0,
"extension": c.extension,
"https_endpoint": is_subdomain(request.host, g.domain) and g.https_endpoint,
# does the client only want to communicate over HTTPS?

View File

@@ -86,11 +86,15 @@ r.ui.initLiveTimestamps = function() {
}
r.ui.initTimings = function() {
// sample at a rate of 1%
if (Math.random() > 0.01) { return }
// return if we're not configured for sending stats
if (!r.config.pageInfo.actionName || !r.config.stats_domain) {
return
}
if (!r.config.pageInfo.actionName) { return }
if (!r.config.stats_domain) { return }
// Sample based on the configuration sample rate
if (Math.random() > r.config.stats_sample_rate / 100) {
return
}
var browserTimings = new r.NavigationTimings()