OSDN Git Service

statsd AnomalyDetection improvements
authorBookatz <bookatz@google.com>
Thu, 8 Mar 2018 23:45:14 +0000 (15:45 -0800)
committerBookatz <bookatz@google.com>
Fri, 9 Mar 2018 19:09:51 +0000 (11:09 -0800)
Re-add check to make sure that bad config won't cause duration
anomaly detection to crash stastd

Bug: 74399947
Test: manual
Change-Id: Id175d233685c133ec3d4231272fe5708250dee6b

cmds/statsd/src/metrics/DurationMetricProducer.cpp

index ac39662..7f8c264 100644 (file)
@@ -124,6 +124,13 @@ DurationMetricProducer::~DurationMetricProducer() {
 sp<AnomalyTracker> DurationMetricProducer::addAnomalyTracker(
         const Alert &alert, const sp<AlarmMonitor>& anomalyAlarmMonitor) {
     std::lock_guard<std::mutex> lock(mMutex);
+    if (mAggregationType == DurationMetric_AggregationType_SUM) {
+        if (alert.trigger_if_sum_gt() > alert.num_buckets() * mBucketSizeNs) {
+            ALOGW("invalid alert for SUM: threshold (%f) > possible recordable value (%d x %lld)",
+                  alert.trigger_if_sum_gt(), alert.num_buckets(), (long long)mBucketSizeNs);
+            return nullptr;
+        }
+    }
     sp<DurationAnomalyTracker> anomalyTracker =
         new DurationAnomalyTracker(alert, mConfigKey, anomalyAlarmMonitor);
     if (anomalyTracker != nullptr) {