Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Unified Diff: components/domain_reliability/context.cc

Issue 1497803004: Domain Reliability: Add sample_rate field to Beacon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more sample rate tests Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/domain_reliability/config.cc ('k') | components/domain_reliability/context_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/domain_reliability/context.cc
diff --git a/components/domain_reliability/context.cc b/components/domain_reliability/context.cc
index 2cf5dde72fdc6f96631a19f7cafcb2c6f76571a6..0615259a7f8a08893cbcdce9616a89ee4059a223 100644
--- a/components/domain_reliability/context.cc
+++ b/components/domain_reliability/context.cc
@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
+#include "base/rand_util.h"
#include "base/values.h"
#include "components/domain_reliability/dispatcher.h"
#include "components/domain_reliability/uploader.h"
@@ -69,16 +70,17 @@ DomainReliabilityContext::~DomainReliabilityContext() {
void DomainReliabilityContext::OnBeacon(
scoped_ptr<DomainReliabilityBeacon> beacon) {
bool success = (beacon->status == "ok");
-
- bool reported = config().DecideIfShouldReportRequest(success);
- UMA_HISTOGRAM_BOOLEAN("DomainReliability.BeaconReported", reported);
- if (!reported) {
+ double sample_rate = config().GetSampleRate(success);
+ bool should_report = base::RandDouble() < sample_rate;
+ UMA_HISTOGRAM_BOOLEAN("DomainReliability.BeaconReported", should_report);
+ if (!should_report) {
// If the beacon isn't queued to be reported, it definitely cannot evict
// an older beacon. (This histogram is also logged below based on whether
// an older beacon was actually evicted.)
LogOnBeaconDidEvictHistogram(false);
return;
}
+ beacon->sample_rate = sample_rate;
UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.ReportedBeaconError",
-beacon->chrome_error);
@@ -94,11 +96,11 @@ void DomainReliabilityContext::OnBeacon(
if (beacon->upload_depth <= kMaxUploadDepthToSchedule)
scheduler_.OnBeaconAdded();
beacons_.push_back(beacon.release());
- bool evicted = beacons_.size() > kMaxQueuedBeacons;
- if (evicted)
+ bool should_evict = beacons_.size() > kMaxQueuedBeacons;
+ if (should_evict)
RemoveOldestBeacon();
- LogOnBeaconDidEvictHistogram(evicted);
+ LogOnBeaconDidEvictHistogram(should_evict);
}
void DomainReliabilityContext::ClearBeacons() {
« no previous file with comments | « components/domain_reliability/config.cc ('k') | components/domain_reliability/context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698