Merge "Guardrail the max gauge atoms per dimension in one bucket." into pi-dev am: 67cee97754
am: 2d41c7d382
Change-Id: I59c218fe5048f2d9e828f6f4f621b031cd424acd
diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp
index 55dde10..aabd361 100644
--- a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp
+++ b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp
@@ -84,7 +84,8 @@
mDimensionHardLimit(StatsdStats::kAtomDimensionKeySizeLimitMap.find(pullTagId) !=
StatsdStats::kAtomDimensionKeySizeLimitMap.end()
? StatsdStats::kAtomDimensionKeySizeLimitMap.at(pullTagId).second
- : StatsdStats::kDimensionKeySizeHardLimit) {
+ : StatsdStats::kDimensionKeySizeHardLimit),
+ mGaugeAtomsPerDimensionLimit(metric.max_num_gauge_atoms_per_bucket()) {
mCurrentSlicedBucket = std::make_shared<DimToGaugeAtomsMap>();
mCurrentSlicedBucketForAnomaly = std::make_shared<DimToValMap>();
int64_t bucketSizeMills = 0;
@@ -433,6 +434,9 @@
if (hitGuardRailLocked(eventKey)) {
return;
}
+ if ((*mCurrentSlicedBucket)[eventKey].size() >= mGaugeAtomsPerDimensionLimit) {
+ return;
+ }
GaugeAtom gaugeAtom(getGaugeFields(event), eventTimeNs, getWallClockNs());
(*mCurrentSlicedBucket)[eventKey].push_back(gaugeAtom);
// Anomaly detection on gauge metric only works when there is one numeric
diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.h b/cmds/statsd/src/metrics/GaugeMetricProducer.h
index ac2bd77..c74f792 100644
--- a/cmds/statsd/src/metrics/GaugeMetricProducer.h
+++ b/cmds/statsd/src/metrics/GaugeMetricProducer.h
@@ -164,6 +164,8 @@
const size_t mDimensionHardLimit;
+ const size_t mGaugeAtomsPerDimensionLimit;
+
FRIEND_TEST(GaugeMetricProducerTest, TestWithCondition);
FRIEND_TEST(GaugeMetricProducerTest, TestWithSlicedCondition);
FRIEND_TEST(GaugeMetricProducerTest, TestNoCondition);
diff --git a/cmds/statsd/src/statsd_config.proto b/cmds/statsd/src/statsd_config.proto
index 9b5d72b..849d5f6 100644
--- a/cmds/statsd/src/statsd_config.proto
+++ b/cmds/statsd/src/statsd_config.proto
@@ -239,6 +239,7 @@
optional SamplingType sampling_type = 9 [default = RANDOM_ONE_SAMPLE] ;
optional int64 min_bucket_size_nanos = 10;
+ optional int64 max_num_gauge_atoms_per_bucket = 11 [default = 10];
}
message ValueMetric {