OSDN Git Service

Small fix to anomaly tracker in statsd.
authorDavid Chen <dwchen@google.com>
Sat, 10 Feb 2018 00:09:26 +0000 (16:09 -0800)
committerDavid Chen <dwchen@google.com>
Sat, 10 Feb 2018 00:09:26 +0000 (16:09 -0800)
If the config specifies only one past bucket for anomaly detection,
statsd doesn't want to store any past buckets since only the current
bucket being tracked in the Metrics Producer is used for deciding
if we hit the anomaly.

Test: Checked that statsd_test passes.
Change-Id: I7ca65bf7d2dfcb2d5c7d5c90f63f4a1c70fbc792

cmds/statsd/src/anomaly/AnomalyTracker.cpp

index 7c5e45e..0614e42 100644 (file)
@@ -93,6 +93,9 @@ void AnomalyTracker::flushPastBuckets(const int64_t& latestPastBucketNum) {
 
 void AnomalyTracker::addPastBucket(const MetricDimensionKey& key, const int64_t& bucketValue,
                                    const int64_t& bucketNum) {
+    if (mNumOfPastBuckets == 0) {
+        return;
+    }
     flushPastBuckets(bucketNum);
 
     auto& bucket = mPastBuckets[index(bucketNum)];
@@ -107,6 +110,9 @@ void AnomalyTracker::addPastBucket(const MetricDimensionKey& key, const int64_t&
 void AnomalyTracker::addPastBucket(std::shared_ptr<DimToValMap> bucketValues,
                                    const int64_t& bucketNum) {
     VLOG("addPastBucket() called.");
+    if (mNumOfPastBuckets == 0) {
+        return;
+    }
     flushPastBuckets(bucketNum);
     // Replace the oldest bucket with the new bucket we are adding.
     mPastBuckets[index(bucketNum)] = bucketValues;