Commit 2bd023a8 authored by Jesse Doherty's avatar Jesse Doherty Committed by Commit Bot

Changing whitelist to allowlist in histogram expiry code.

This will need a follow up cleanup cl once the parameter is changed in
the variations config.

BUG=b/160157778

Change-Id: I6f29d98223eeb04de880e302870af642e6e73292
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2507340Reviewed-by: default avatarJesse Doherty <jwd@chromium.org>
Reviewed-by: default avatarCaitlin Fischer <caitlinfischer@google.com>
Commit-Queue: Jesse Doherty <jwd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823228}
parent e35a3250
...@@ -15,20 +15,27 @@ namespace { ...@@ -15,20 +15,27 @@ namespace {
const base::Feature kExpiredHistogramLogicFeature{ const base::Feature kExpiredHistogramLogicFeature{
"ExpiredHistogramLogic", base::FEATURE_DISABLED_BY_DEFAULT}; "ExpiredHistogramLogic", base::FEATURE_DISABLED_BY_DEFAULT};
// TODO(jwd): Remove when the study config is updated with the new param.
const base::FeatureParam<std::string> kWhitelistParam{ const base::FeatureParam<std::string> kWhitelistParam{
&kExpiredHistogramLogicFeature, "whitelist", ""}; &kExpiredHistogramLogicFeature, "whitelist", ""};
const base::FeatureParam<std::string> kAllowlistParam{
&kExpiredHistogramLogicFeature, "allowlist", ""};
} // namespace } // namespace
void EnableExpiryChecker(const uint64_t* expired_histograms_hashes, void EnableExpiryChecker(const uint64_t* expired_histograms_hashes,
size_t num_expired_histograms) { size_t num_expired_histograms) {
DCHECK(base::FeatureList::GetInstance()); DCHECK(base::FeatureList::GetInstance());
if (base::FeatureList::IsEnabled(kExpiredHistogramLogicFeature)) { if (base::FeatureList::IsEnabled(kExpiredHistogramLogicFeature)) {
std::string allowlist = kAllowlistParam.Get();
// TODO(jwd): Remove when the study config is updated with the new param.
if (allowlist.empty())
allowlist = kWhitelistParam.Get();
base::StatisticsRecorder::SetRecordChecker( base::StatisticsRecorder::SetRecordChecker(
std::make_unique<ExpiredHistogramsChecker>(expired_histograms_hashes, std::make_unique<ExpiredHistogramsChecker>(
num_expired_histograms, expired_histograms_hashes, num_expired_histograms, allowlist));
kWhitelistParam.Get()));
} }
} }
} // namespace metrics } // namespace metrics
\ No newline at end of file
...@@ -15,27 +15,28 @@ ...@@ -15,27 +15,28 @@
namespace metrics { namespace metrics {
ExpiredHistogramsChecker::ExpiredHistogramsChecker( ExpiredHistogramsChecker::ExpiredHistogramsChecker(
const uint64_t* array, const uint64_t* expired_histogram_hashes,
size_t size, size_t size,
const std::string& whitelist_str) const std::string& allowlist_str)
: array_(array), size_(size) { : expired_histogram_hashes_(expired_histogram_hashes), size_(size) {
InitWhitelist(whitelist_str); InitAllowlist(allowlist_str);
} }
ExpiredHistogramsChecker::~ExpiredHistogramsChecker() {} ExpiredHistogramsChecker::~ExpiredHistogramsChecker() {}
bool ExpiredHistogramsChecker::ShouldRecord(uint64_t histogram_hash) const { bool ExpiredHistogramsChecker::ShouldRecord(uint64_t histogram_hash) const {
// If histogram is whitelisted then it should always be recorded. // If histogram is explicitly allowed then it should always be recorded.
if (base::Contains(whitelist_, histogram_hash)) if (base::Contains(allowlist_, histogram_hash))
return true; return true;
return !std::binary_search(array_, array_ + size_, histogram_hash); return !std::binary_search(expired_histogram_hashes_,
expired_histogram_hashes_ + size_, histogram_hash);
} }
void ExpiredHistogramsChecker::InitWhitelist(const std::string& whitelist_str) { void ExpiredHistogramsChecker::InitAllowlist(const std::string& allowlist_str) {
std::vector<base::StringPiece> whitelist_names = base::SplitStringPiece( std::vector<base::StringPiece> allowlist_names = base::SplitStringPiece(
whitelist_str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); allowlist_str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
for (base::StringPiece name : whitelist_names) for (base::StringPiece name : allowlist_names)
whitelist_.insert(base::HashMetricName(name)); allowlist_.insert(base::HashMetricName(name));
} }
} // namespace metrics } // namespace metrics
...@@ -18,30 +18,31 @@ namespace metrics { ...@@ -18,30 +18,31 @@ namespace metrics {
// to avoid recording expired metrics. // to avoid recording expired metrics.
class ExpiredHistogramsChecker final : public base::RecordHistogramChecker { class ExpiredHistogramsChecker final : public base::RecordHistogramChecker {
public: public:
// Takes sorted in nondecreasing order array of histogram hashes, its size and // Takes a sorted array of histogram hashes in ascending order, its size and a
// list of whitelisted histogram names concatenated as a comma-separated // list of explicitly allowed histogram names as a comma-separated string.
// string. // Histograms in the |allowlist_str| are logged even if their hash is in the
ExpiredHistogramsChecker(const uint64_t* array, // |expired_histograms_hashes|.
ExpiredHistogramsChecker(const uint64_t* expired_histogram_hashes,
size_t size, size_t size,
const std::string& whitelist_str); const std::string& allowlist_str);
~ExpiredHistogramsChecker() override; ~ExpiredHistogramsChecker() override;
// Checks if the given |histogram_hash| corresponds to an expired histogram. // Checks if the given |histogram_hash| corresponds to an expired histogram.
bool ShouldRecord(uint64_t histogram_hash) const override; bool ShouldRecord(uint64_t histogram_hash) const override;
private: private:
// Initializes the |whitelist_| array of histogram hashes that should be // Initializes the |allowlist_| array of histogram hashes that should be
// recorded regardless of their expiration. // recorded regardless of their expiration.
void InitWhitelist(const std::string& whitelist_str); void InitAllowlist(const std::string& allowlist_str);
// Array of expired histogram hashes. // Array of expired histogram hashes.
const uint64_t* const array_; const uint64_t* const expired_histogram_hashes_;
// Size of the |array_|. // Size of the |expired_histogram_hashes_|.
const size_t size_; const size_t size_;
// List of expired histogram hashes that should be recorded. // Set of expired histogram hashes that should be recorded.
std::set<uint64_t> whitelist_; std::set<uint64_t> allowlist_;
DISALLOW_COPY_AND_ASSIGN(ExpiredHistogramsChecker); DISALLOW_COPY_AND_ASSIGN(ExpiredHistogramsChecker);
}; };
......
...@@ -12,14 +12,14 @@ namespace metrics { ...@@ -12,14 +12,14 @@ namespace metrics {
TEST(ExpiredHistogramsCheckerTests, BasicTest) { TEST(ExpiredHistogramsCheckerTests, BasicTest) {
uint64_t expired_hashes[] = {1, 2, 3}; uint64_t expired_hashes[] = {1, 2, 3};
size_t size = 3; size_t size = 3;
std::string whitelist_str = ""; std::string allowlist_str = "";
ExpiredHistogramsChecker checker(expired_hashes, size, whitelist_str); ExpiredHistogramsChecker checker(expired_hashes, size, allowlist_str);
EXPECT_TRUE(checker.ShouldRecord(0)); EXPECT_TRUE(checker.ShouldRecord(0));
EXPECT_FALSE(checker.ShouldRecord(3)); EXPECT_FALSE(checker.ShouldRecord(3));
} }
TEST(ExpiredHistogramsCheckerTests, WhitelistTest) { TEST(ExpiredHistogramsCheckerTests, AllowlistTest) {
std::string hist1 = "hist1"; std::string hist1 = "hist1";
std::string hist2 = "hist2"; std::string hist2 = "hist2";
std::string hist3 = "hist3"; std::string hist3 = "hist3";
...@@ -28,8 +28,8 @@ TEST(ExpiredHistogramsCheckerTests, WhitelistTest) { ...@@ -28,8 +28,8 @@ TEST(ExpiredHistogramsCheckerTests, WhitelistTest) {
uint64_t expired_hashes[] = {base::HashMetricName(hist1), uint64_t expired_hashes[] = {base::HashMetricName(hist1),
base::HashMetricName(hist2)}; base::HashMetricName(hist2)};
size_t size = 2; size_t size = 2;
std::string whitelist_str = hist2 + "," + hist4; std::string allowlist_str = hist2 + "," + hist4;
ExpiredHistogramsChecker checker(expired_hashes, size, whitelist_str); ExpiredHistogramsChecker checker(expired_hashes, size, allowlist_str);
EXPECT_FALSE(checker.ShouldRecord(base::HashMetricName(hist1))); EXPECT_FALSE(checker.ShouldRecord(base::HashMetricName(hist1)));
EXPECT_TRUE(checker.ShouldRecord(base::HashMetricName(hist2))); EXPECT_TRUE(checker.ShouldRecord(base::HashMetricName(hist2)));
...@@ -37,4 +37,4 @@ TEST(ExpiredHistogramsCheckerTests, WhitelistTest) { ...@@ -37,4 +37,4 @@ TEST(ExpiredHistogramsCheckerTests, WhitelistTest) {
EXPECT_TRUE(checker.ShouldRecord(base::HashMetricName(hist4))); EXPECT_TRUE(checker.ShouldRecord(base::HashMetricName(hist4)));
} }
} // namespace metrics } // namespace metrics
\ No newline at end of file
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