Commit a928970f authored by Olivier Robin's avatar Olivier Robin Committed by Chromium LUCI CQ

Remove static for experiment accessors in UKMRecorderImpl

Unittests rely on ScopedFeatureList which does not work
because of these static values.

Bug: 1166714
Change-Id: Ie3b0ff8beac1efa2398c68e77725ff69fce9cc2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627405
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844187}
parent 3eef3218
...@@ -55,34 +55,6 @@ bool IsWhitelistedSourceId(SourceId source_id) { ...@@ -55,34 +55,6 @@ bool IsWhitelistedSourceId(SourceId source_id) {
GetSourceIdType(source_id) == SourceIdType::PAYMENT_APP_ID; GetSourceIdType(source_id) == SourceIdType::PAYMENT_APP_ID;
} }
// Gets the maximum number of Sources we'll keep in memory before discarding any
// new ones being added.
size_t GetMaxSources() {
constexpr size_t kDefaultMaxSources = 500;
static auto value = static_cast<size_t>(base::GetFieldTrialParamByFeatureAsInt(
kUkmFeature, "MaxSources", kDefaultMaxSources));
return value;
}
// Gets the maximum number of Sources we can keep in memory at the end of the
// current reporting cycle that will stay accessible in the next reporting
// interval.
size_t GetMaxKeptSources() {
constexpr size_t kDefaultMaxKeptSources = 100;
static auto value = static_cast<size_t>(base::GetFieldTrialParamByFeatureAsInt(
kUkmFeature, "MaxKeptSources", kDefaultMaxKeptSources));
return value;
}
// Gets the maximum number of Entries we'll keep in memory before discarding any
// new ones being added.
size_t GetMaxEntries() {
constexpr size_t kDefaultMaxEntries = 5000;
static auto value = static_cast<size_t>(base::GetFieldTrialParamByFeatureAsInt(
kUkmFeature, "MaxEntries", kDefaultMaxEntries));
return value;
}
// Returns whether |url| has one of the schemes supported for logging to UKM. // Returns whether |url| has one of the schemes supported for logging to UKM.
// URLs with other schemes will not be logged. // URLs with other schemes will not be logged.
bool HasSupportedScheme(const GURL& url) { bool HasSupportedScheme(const GURL& url) {
...@@ -218,8 +190,16 @@ bool HasUnknownMetrics(const builders::DecodeMap& decode_map, ...@@ -218,8 +190,16 @@ bool HasUnknownMetrics(const builders::DecodeMap& decode_map,
} // namespace } // namespace
UkmRecorderImpl::UkmRecorderImpl() UkmRecorderImpl::UkmRecorderImpl()
: recording_enabled_(false), : sampling_seed_(static_cast<uint32_t>(base::RandUint64())) {
sampling_seed_(static_cast<uint32_t>(base::RandUint64())) {} max_sources_ = static_cast<size_t>(base::GetFieldTrialParamByFeatureAsInt(
kUkmFeature, "MaxSources", max_sources_));
max_kept_sources_ =
static_cast<size_t>(base::GetFieldTrialParamByFeatureAsInt(
kUkmFeature, "MaxKeptSources", max_kept_sources_));
max_entries_ = static_cast<size_t>(base::GetFieldTrialParamByFeatureAsInt(
kUkmFeature, "MaxEntries", max_entries_));
}
UkmRecorderImpl::~UkmRecorderImpl() = default; UkmRecorderImpl::~UkmRecorderImpl() = default;
// static // static
...@@ -523,7 +503,7 @@ void UkmRecorderImpl::StoreRecordingsInReport(Report* report) { ...@@ -523,7 +503,7 @@ void UkmRecorderImpl::StoreRecordingsInReport(Report* report) {
// Defer at most GetMaxKeptSources() sources to the next report, // Defer at most GetMaxKeptSources() sources to the next report,
// prioritizing most recently created ones. // prioritizing most recently created ones.
int pruned_sources_age = PruneOldSources(GetMaxKeptSources()); int pruned_sources_age = PruneOldSources(max_kept_sources_);
// Record how old the newest truncated source is. // Record how old the newest truncated source is.
source_counts_proto->set_pruned_sources_age_seconds(pruned_sources_age); source_counts_proto->set_pruned_sources_age_seconds(pruned_sources_age);
...@@ -671,7 +651,7 @@ bool UkmRecorderImpl::ShouldRecordUrl(SourceId source_id, ...@@ -671,7 +651,7 @@ bool UkmRecorderImpl::ShouldRecordUrl(SourceId source_id,
return false; return false;
} }
if (recordings_.sources.size() >= GetMaxSources()) { if (recordings_.sources.size() >= max_sources_) {
RecordDroppedSource(DroppedDataReason::MAX_HIT); RecordDroppedSource(DroppedDataReason::MAX_HIT);
return false; return false;
} }
...@@ -770,7 +750,7 @@ void UkmRecorderImpl::AddEntry(mojom::UkmEntryPtr entry) { ...@@ -770,7 +750,7 @@ void UkmRecorderImpl::AddEntry(mojom::UkmEntryPtr entry) {
} }
} }
if (recordings_.entries.size() >= GetMaxEntries()) { if (recordings_.entries.size() >= max_entries_) {
RecordDroppedEntry(entry->event_hash, DroppedDataReason::MAX_HIT); RecordDroppedEntry(entry->event_hash, DroppedDataReason::MAX_HIT);
event_aggregate.dropped_due_to_limits++; event_aggregate.dropped_due_to_limits++;
for (auto& metric : entry->metrics) for (auto& metric : entry->metrics)
......
...@@ -274,6 +274,19 @@ class COMPONENT_EXPORT(UKM_RECORDER) UkmRecorderImpl : public UkmRecorder { ...@@ -274,6 +274,19 @@ class COMPONENT_EXPORT(UKM_RECORDER) UkmRecorderImpl : public UkmRecorder {
}; };
Recordings recordings_; Recordings recordings_;
// The maximum number of Sources we'll keep in memory before discarding any
// new ones being added.
size_t max_sources_ = 500;
// The maximum number of Sources we can keep in memory at the end of the
// current reporting cycle that will stay accessible in the next reporting
// interval.
size_t max_kept_sources_ = 100;
// The maximum number of Entries we'll keep in memory before discarding any
// new ones being added.
size_t max_entries_ = 5000;
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment