OSDN Git Service

Add a sampling method to pull gauge when condition changes to true.
authorYangster <yanglu@google.com>
Wed, 9 May 2018 22:51:07 +0000 (15:51 -0700)
committerYangster <yanglu@google.com>
Wed, 9 May 2018 23:02:35 +0000 (16:02 -0700)
Test: statsd test

BUG: b/79490890
Change-Id: I82ed6681151f8a217e74bd0d855f817b4fa0619c

cmds/statsd/src/metrics/GaugeMetricProducer.cpp
cmds/statsd/src/statsd_config.proto

index a940d58..06d8bcd 100644 (file)
@@ -324,6 +324,10 @@ void GaugeMetricProducer::pullLocked(const int64_t timestampNs) {
             triggerPuller = true;
             break;
         }
+        case GaugeMetric::CONDITION_CHANGE_TO_TRUE: {
+            triggerPuller = mCondition;
+            break;
+        }
         default:
             break;
     }
@@ -348,7 +352,7 @@ void GaugeMetricProducer::onConditionChangedLocked(const bool conditionMet,
     flushIfNeededLocked(eventTimeNs);
     mCondition = conditionMet;
 
-    if (mPullTagId != -1 && mCondition) {
+    if (mPullTagId != -1) {
         pullLocked(eventTimeNs);
     }  // else: Push mode. No need to proactively pull the gauge data.
 }
index fd36560..9b5d72b 100644 (file)
@@ -234,6 +234,7 @@ message GaugeMetric {
   enum SamplingType {
     RANDOM_ONE_SAMPLE = 1;
     ALL_CONDITION_CHANGES = 2;
+    CONDITION_CHANGE_TO_TRUE = 3;
   }
   optional SamplingType sampling_type = 9 [default = RANDOM_ONE_SAMPLE] ;