Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c189bdcb authored by David Chen's avatar David Chen
Browse files

Small fix to anomaly tracker in statsd.

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
parent f9420f4d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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;