diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp index 55dde103902d3..aabd3616e2fe4 100644 --- a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp +++ b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp @@ -84,7 +84,8 @@ GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric 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(); mCurrentSlicedBucketForAnomaly = std::make_shared(); int64_t bucketSizeMills = 0; @@ -433,6 +434,9 @@ void GaugeMetricProducer::onMatchedLogEventInternalLocked( 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 ac2bd77f0df5e..c74f7927dfac7 100644 --- a/cmds/statsd/src/metrics/GaugeMetricProducer.h +++ b/cmds/statsd/src/metrics/GaugeMetricProducer.h @@ -164,6 +164,8 @@ private: 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 9b5d72bf56dce..849d5f683d679 100644 --- a/cmds/statsd/src/statsd_config.proto +++ b/cmds/statsd/src/statsd_config.proto @@ -239,6 +239,7 @@ message GaugeMetric { 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 {