From 6e2e92d9686d41ccf5367f884a6bfcfae958744d Mon Sep 17 00:00:00 2001 From: tsaichristine Date: Mon, 18 May 2020 14:39:45 -0700 Subject: [PATCH] Pass initial conditions to combination conditions and metrics SimplePredicates have a configurable initial value that can be set to unknown or false. Previously, CombinationPredicates and MetricProducers were automatically initialized with an unknown condition value instead of being synced with the conditions of the SimplePredicates that they rely on. An initial condition cache is used to store initial conditions of ConditionTrackers after they are initialized. CombinationConditionTrackers evaluate their initial condition based on the initial conditions of their child SimpleConditionTrackers. MetricProducers also use the initial condition cache to set its condition during initialization. Added unit tests in SimpleConditionTracker_test to check that SimpleConditionTrackers have the correct initial conditions based on what the InitialValue is set to and the condition is updated properly after the first few condition change events. Added unit test in MetricsManager_test to check that all ConditionTrackers and MetricProducers have the correct initial conditions. Test: m statsd_test && adb sync data && adb shell data/nativetest64/statsd_test/statsd_test64 Bug: b/156762672 Change-Id: I9f6088f8c92fb18eb2ca8632aaa338fb0ed8e679 --- .../condition/CombinationConditionTracker.cpp | 14 +- .../condition/CombinationConditionTracker.h | 4 +- cmds/statsd/src/condition/ConditionTracker.h | 4 +- .../src/condition/SimpleConditionTracker.cpp | 4 +- .../src/condition/SimpleConditionTracker.h | 4 +- .../src/metrics/CountMetricProducer.cpp | 8 +- cmds/statsd/src/metrics/CountMetricProducer.h | 3 +- .../src/metrics/DurationMetricProducer.cpp | 11 +- .../src/metrics/DurationMetricProducer.h | 8 +- .../src/metrics/EventMetricProducer.cpp | 7 +- cmds/statsd/src/metrics/EventMetricProducer.h | 3 +- .../src/metrics/GaugeMetricProducer.cpp | 13 +- cmds/statsd/src/metrics/GaugeMetricProducer.h | 1 + cmds/statsd/src/metrics/MetricProducer.cpp | 5 +- cmds/statsd/src/metrics/MetricProducer.h | 10 +- .../src/metrics/ValueMetricProducer.cpp | 6 +- cmds/statsd/src/metrics/ValueMetricProducer.h | 1 + .../src/metrics/metrics_manager_util.cpp | 55 +++-- .../statsd/src/metrics/metrics_manager_util.h | 5 +- cmds/statsd/tests/MetricsManager_test.cpp | 146 ++++++++++++ .../CombinationConditionTracker_test.cpp | 1 + .../condition/SimpleConditionTracker_test.cpp | 108 +++++++++ .../metrics/CountMetricProducer_test.cpp | 33 +-- .../metrics/DurationMetricProducer_test.cpp | 44 ++-- .../metrics/EventMetricProducer_test.cpp | 10 +- .../metrics/GaugeMetricProducer_test.cpp | 63 ++--- .../metrics/ValueMetricProducer_test.cpp | 224 +++++++++--------- 27 files changed, 553 insertions(+), 242 deletions(-) diff --git a/cmds/statsd/src/condition/CombinationConditionTracker.cpp b/cmds/statsd/src/condition/CombinationConditionTracker.cpp index c829ccd11ec95..e9875baf58c70 100644 --- a/cmds/statsd/src/condition/CombinationConditionTracker.cpp +++ b/cmds/statsd/src/condition/CombinationConditionTracker.cpp @@ -37,7 +37,8 @@ CombinationConditionTracker::~CombinationConditionTracker() { bool CombinationConditionTracker::init(const vector& allConditionConfig, const vector>& allConditionTrackers, const unordered_map& conditionIdIndexMap, - vector& stack) { + vector& stack, + vector& initialConditionCache) { VLOG("Combination predicate init() %lld", (long long)mConditionId); if (mInitialized) { return true; @@ -73,9 +74,9 @@ bool CombinationConditionTracker::init(const vector& allConditionConf return false; } - - bool initChildSucceeded = childTracker->init(allConditionConfig, allConditionTrackers, - conditionIdIndexMap, stack); + bool initChildSucceeded = + childTracker->init(allConditionConfig, allConditionTrackers, conditionIdIndexMap, + stack, initialConditionCache); if (!initChildSucceeded) { ALOGW("Child initialization failed %lld ", (long long)child); @@ -95,6 +96,11 @@ bool CombinationConditionTracker::init(const vector& allConditionConf childTracker->getLogTrackerIndex().end()); } + mUnSlicedPartCondition = evaluateCombinationCondition(mUnSlicedChildren, mLogicalOperation, + initialConditionCache); + initialConditionCache[mIndex] = + evaluateCombinationCondition(mChildren, mLogicalOperation, initialConditionCache); + // unmark this node in the recursion stack. stack[mIndex] = false; diff --git a/cmds/statsd/src/condition/CombinationConditionTracker.h b/cmds/statsd/src/condition/CombinationConditionTracker.h index e3d860127780a..39ff0ab03266d 100644 --- a/cmds/statsd/src/condition/CombinationConditionTracker.h +++ b/cmds/statsd/src/condition/CombinationConditionTracker.h @@ -32,8 +32,8 @@ public: bool init(const std::vector& allConditionConfig, const std::vector>& allConditionTrackers, - const std::unordered_map& conditionIdIndexMap, - std::vector& stack) override; + const std::unordered_map& conditionIdIndexMap, std::vector& stack, + std::vector& initialConditionCache) override; void evaluateCondition(const LogEvent& event, const std::vector& eventMatcherValues, diff --git a/cmds/statsd/src/condition/ConditionTracker.h b/cmds/statsd/src/condition/ConditionTracker.h index f9a2c344c3463..62736c8160bb7 100644 --- a/cmds/statsd/src/condition/ConditionTracker.h +++ b/cmds/statsd/src/condition/ConditionTracker.h @@ -51,10 +51,12 @@ public: // need to call init() on children conditions) // conditionIdIndexMap: the mapping from condition id to its index. // stack: a bit map to keep track which nodes have been visited on the stack in the recursion. + // initialConditionCache: tracks initial conditions of all ConditionTrackers. virtual bool init(const std::vector& allConditionConfig, const std::vector>& allConditionTrackers, const std::unordered_map& conditionIdIndexMap, - std::vector& stack) = 0; + std::vector& stack, + std::vector& initialConditionCache) = 0; // evaluate current condition given the new event. // event: the new log event diff --git a/cmds/statsd/src/condition/SimpleConditionTracker.cpp b/cmds/statsd/src/condition/SimpleConditionTracker.cpp index f23ec50abb509..efb4d4989425e 100644 --- a/cmds/statsd/src/condition/SimpleConditionTracker.cpp +++ b/cmds/statsd/src/condition/SimpleConditionTracker.cpp @@ -95,9 +95,11 @@ SimpleConditionTracker::~SimpleConditionTracker() { bool SimpleConditionTracker::init(const vector& allConditionConfig, const vector>& allConditionTrackers, const unordered_map& conditionIdIndexMap, - vector& stack) { + vector& stack, + vector& initialConditionCache) { // SimpleConditionTracker does not have dependency on other conditions, thus we just return // if the initialization was successful. + initialConditionCache[mIndex] = mInitialValue; return mInitialized; } diff --git a/cmds/statsd/src/condition/SimpleConditionTracker.h b/cmds/statsd/src/condition/SimpleConditionTracker.h index 5c5cc565f783d..ea7f87bde2b80 100644 --- a/cmds/statsd/src/condition/SimpleConditionTracker.h +++ b/cmds/statsd/src/condition/SimpleConditionTracker.h @@ -37,8 +37,8 @@ public: bool init(const std::vector& allConditionConfig, const std::vector>& allConditionTrackers, - const std::unordered_map& conditionIdIndexMap, - std::vector& stack) override; + const std::unordered_map& conditionIdIndexMap, std::vector& stack, + std::vector& initialConditionCache) override; void evaluateCondition(const LogEvent& event, const std::vector& eventMatcherValues, diff --git a/cmds/statsd/src/metrics/CountMetricProducer.cpp b/cmds/statsd/src/metrics/CountMetricProducer.cpp index d865c2176c1ea..573961276e5b4 100644 --- a/cmds/statsd/src/metrics/CountMetricProducer.cpp +++ b/cmds/statsd/src/metrics/CountMetricProducer.cpp @@ -68,14 +68,14 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 6; CountMetricProducer::CountMetricProducer( const ConfigKey& key, const CountMetric& metric, const int conditionIndex, - const sp& wizard, const int64_t timeBaseNs, const int64_t startTimeNs, - + const vector& initialConditionCache, const sp& wizard, + const int64_t timeBaseNs, const int64_t startTimeNs, const unordered_map>& eventActivationMap, const unordered_map>>& eventDeactivationMap, const vector& slicedStateAtoms, const unordered_map>& stateGroupMap) - : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard, eventActivationMap, - eventDeactivationMap, slicedStateAtoms, stateGroupMap) { + : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard, + eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap) { if (metric.has_bucket()) { mBucketSizeNs = TimeUnitToBucketSizeInMillisGuardrailed(key.GetUid(), metric.bucket()) * 1000000; diff --git a/cmds/statsd/src/metrics/CountMetricProducer.h b/cmds/statsd/src/metrics/CountMetricProducer.h index 26b3d3cc67220..f05fb061ccc19 100644 --- a/cmds/statsd/src/metrics/CountMetricProducer.h +++ b/cmds/statsd/src/metrics/CountMetricProducer.h @@ -43,7 +43,8 @@ class CountMetricProducer : public MetricProducer { public: CountMetricProducer( const ConfigKey& key, const CountMetric& countMetric, const int conditionIndex, - const sp& wizard, const int64_t timeBaseNs, const int64_t startTimeNs, + const vector& initialConditionCache, const sp& wizard, + const int64_t timeBaseNs, const int64_t startTimeNs, const std::unordered_map>& eventActivationMap = {}, const std::unordered_map>>& eventDeactivationMap = {}, diff --git a/cmds/statsd/src/metrics/DurationMetricProducer.cpp b/cmds/statsd/src/metrics/DurationMetricProducer.cpp index 6633659248297..e9b043876d3d5 100644 --- a/cmds/statsd/src/metrics/DurationMetricProducer.cpp +++ b/cmds/statsd/src/metrics/DurationMetricProducer.cpp @@ -64,15 +64,16 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 6; DurationMetricProducer::DurationMetricProducer( const ConfigKey& key, const DurationMetric& metric, const int conditionIndex, - const size_t startIndex, const size_t stopIndex, const size_t stopAllIndex, - const bool nesting, const sp& wizard, - const FieldMatcher& internalDimensions, const int64_t timeBaseNs, const int64_t startTimeNs, + const vector& initialConditionCache, const size_t startIndex, + const size_t stopIndex, const size_t stopAllIndex, const bool nesting, + const sp& wizard, const FieldMatcher& internalDimensions, + const int64_t timeBaseNs, const int64_t startTimeNs, const unordered_map>& eventActivationMap, const unordered_map>>& eventDeactivationMap, const vector& slicedStateAtoms, const unordered_map>& stateGroupMap) - : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard, eventActivationMap, - eventDeactivationMap, slicedStateAtoms, stateGroupMap), + : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard, + eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap), mAggregationType(metric.aggregation_type()), mStartIndex(startIndex), mStopIndex(stopIndex), diff --git a/cmds/statsd/src/metrics/DurationMetricProducer.h b/cmds/statsd/src/metrics/DurationMetricProducer.h index 53f0f28c3386c..bfe1010c89def 100644 --- a/cmds/statsd/src/metrics/DurationMetricProducer.h +++ b/cmds/statsd/src/metrics/DurationMetricProducer.h @@ -40,10 +40,10 @@ class DurationMetricProducer : public MetricProducer { public: DurationMetricProducer( const ConfigKey& key, const DurationMetric& durationMetric, const int conditionIndex, - const size_t startIndex, const size_t stopIndex, const size_t stopAllIndex, - const bool nesting, const sp& wizard, - const FieldMatcher& internalDimensions, const int64_t timeBaseNs, - const int64_t startTimeNs, + const vector& initialConditionCache, const size_t startIndex, + const size_t stopIndex, const size_t stopAllIndex, const bool nesting, + const sp& wizard, const FieldMatcher& internalDimensions, + const int64_t timeBaseNs, const int64_t startTimeNs, const unordered_map>& eventActivationMap = {}, const unordered_map>>& eventDeactivationMap = {}, const vector& slicedStateAtoms = {}, diff --git a/cmds/statsd/src/metrics/EventMetricProducer.cpp b/cmds/statsd/src/metrics/EventMetricProducer.cpp index d68f64ae40b04..dc0036a687f31 100644 --- a/cmds/statsd/src/metrics/EventMetricProducer.cpp +++ b/cmds/statsd/src/metrics/EventMetricProducer.cpp @@ -54,13 +54,14 @@ const int FIELD_ID_ATOMS = 2; EventMetricProducer::EventMetricProducer( const ConfigKey& key, const EventMetric& metric, const int conditionIndex, - const sp& wizard, const int64_t startTimeNs, + const vector& initialConditionCache, const sp& wizard, + const int64_t startTimeNs, const unordered_map>& eventActivationMap, const unordered_map>>& eventDeactivationMap, const vector& slicedStateAtoms, const unordered_map>& stateGroupMap) - : MetricProducer(metric.id(), key, startTimeNs, conditionIndex, wizard, eventActivationMap, - eventDeactivationMap, slicedStateAtoms, stateGroupMap) { + : MetricProducer(metric.id(), key, startTimeNs, conditionIndex, initialConditionCache, wizard, + eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap) { if (metric.links().size() > 0) { for (const auto& link : metric.links()) { Metric2Condition mc; diff --git a/cmds/statsd/src/metrics/EventMetricProducer.h b/cmds/statsd/src/metrics/EventMetricProducer.h index e8f2119a170c4..bfb2de36fad41 100644 --- a/cmds/statsd/src/metrics/EventMetricProducer.h +++ b/cmds/statsd/src/metrics/EventMetricProducer.h @@ -35,7 +35,8 @@ class EventMetricProducer : public MetricProducer { public: EventMetricProducer( const ConfigKey& key, const EventMetric& eventMetric, const int conditionIndex, - const sp& wizard, const int64_t startTimeNs, + const vector& initialConditionCache, const sp& wizard, + const int64_t startTimeNs, const std::unordered_map>& eventActivationMap = {}, const std::unordered_map>>& eventDeactivationMap = {}, diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp index 1d4d0b3a5e5d8..020f4b638f4df 100644 --- a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp +++ b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp @@ -70,14 +70,15 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 8; GaugeMetricProducer::GaugeMetricProducer( const ConfigKey& key, const GaugeMetric& metric, const int conditionIndex, - const sp& wizard, const int whatMatcherIndex, - const sp& matcherWizard, const int pullTagId, const int triggerAtomId, - const int atomId, const int64_t timeBaseNs, const int64_t startTimeNs, - const sp& pullerManager, + const vector& initialConditionCache, const sp& wizard, + const int whatMatcherIndex, const sp& matcherWizard, + const int pullTagId, const int triggerAtomId, const int atomId, const int64_t timeBaseNs, + const int64_t startTimeNs, const sp& pullerManager, const unordered_map>& eventActivationMap, const unordered_map>>& eventDeactivationMap) - : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard, eventActivationMap, - eventDeactivationMap, /*slicedStateAtoms=*/{}, /*stateGroupMap=*/{}), + : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard, + eventActivationMap, eventDeactivationMap, /*slicedStateAtoms=*/{}, + /*stateGroupMap=*/{}), mWhatMatcherIndex(whatMatcherIndex), mEventMatcherWizard(matcherWizard), mPullerManager(pullerManager), diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.h b/cmds/statsd/src/metrics/GaugeMetricProducer.h index 2eb584b097ea5..2fc772b6b6410 100644 --- a/cmds/statsd/src/metrics/GaugeMetricProducer.h +++ b/cmds/statsd/src/metrics/GaugeMetricProducer.h @@ -58,6 +58,7 @@ class GaugeMetricProducer : public virtual MetricProducer, public virtual PullDa public: GaugeMetricProducer( const ConfigKey& key, const GaugeMetric& gaugeMetric, const int conditionIndex, + const vector& initialConditionCache, const sp& conditionWizard, const int whatMatcherIndex, const sp& matcherWizard, const int pullTagId, const int triggerAtomId, const int atomId, const int64_t timeBaseNs, diff --git a/cmds/statsd/src/metrics/MetricProducer.cpp b/cmds/statsd/src/metrics/MetricProducer.cpp index bb4f03e81e2e2..cdd20cdd70f9c 100644 --- a/cmds/statsd/src/metrics/MetricProducer.cpp +++ b/cmds/statsd/src/metrics/MetricProducer.cpp @@ -45,7 +45,8 @@ const int FIELD_ID_ACTIVE_EVENT_ACTIVATION_STATE = 3; MetricProducer::MetricProducer( const int64_t& metricId, const ConfigKey& key, const int64_t timeBaseNs, - const int conditionIndex, const sp& wizard, + const int conditionIndex, const vector& initialConditionCache, + const sp& wizard, const std::unordered_map>& eventActivationMap, const std::unordered_map>>& eventDeactivationMap, @@ -56,7 +57,7 @@ MetricProducer::MetricProducer( mTimeBaseNs(timeBaseNs), mCurrentBucketStartTimeNs(timeBaseNs), mCurrentBucketNum(0), - mCondition(initialCondition(conditionIndex)), + mCondition(initialCondition(conditionIndex, initialConditionCache)), mConditionTrackerIndex(conditionIndex), mConditionSliced(false), mWizard(wizard), diff --git a/cmds/statsd/src/metrics/MetricProducer.h b/cmds/statsd/src/metrics/MetricProducer.h index 9d37608149ce3..be4cd6724bb19 100644 --- a/cmds/statsd/src/metrics/MetricProducer.h +++ b/cmds/statsd/src/metrics/MetricProducer.h @@ -129,7 +129,8 @@ struct SkippedBucket { class MetricProducer : public virtual android::RefBase, public virtual StateListener { public: MetricProducer(const int64_t& metricId, const ConfigKey& key, const int64_t timeBaseNs, - const int conditionIndex, const sp& wizard, + const int conditionIndex, const vector& initialConditionCache, + const sp& wizard, const std::unordered_map>& eventActivationMap, const std::unordered_map>>& eventDeactivationMap, @@ -138,8 +139,9 @@ public: virtual ~MetricProducer(){}; - ConditionState initialCondition(const int conditionIndex) const { - return conditionIndex >= 0 ? ConditionState::kUnknown : ConditionState::kTrue; + ConditionState initialCondition(const int conditionIndex, + const vector& initialConditionCache) const { + return conditionIndex >= 0 ? initialConditionCache[conditionIndex] : ConditionState::kTrue; } /** @@ -496,6 +498,8 @@ protected: FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithDimensions); FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithIncorrectDimensions); FRIEND_TEST(ValueMetricE2eTest, TestInitialConditionChanges); + + FRIEND_TEST(MetricsManagerTest, TestInitialConditions); }; } // namespace statsd diff --git a/cmds/statsd/src/metrics/ValueMetricProducer.cpp b/cmds/statsd/src/metrics/ValueMetricProducer.cpp index 71df710ee6479..c0d1174023143 100644 --- a/cmds/statsd/src/metrics/ValueMetricProducer.cpp +++ b/cmds/statsd/src/metrics/ValueMetricProducer.cpp @@ -78,6 +78,7 @@ const Value ZERO_DOUBLE((int64_t)0); // ValueMetric has a minimum bucket size of 10min so that we don't pull too frequently ValueMetricProducer::ValueMetricProducer( const ConfigKey& key, const ValueMetric& metric, const int conditionIndex, + const vector& initialConditionCache, const sp& conditionWizard, const int whatMatcherIndex, const sp& matcherWizard, const int pullTagId, const int64_t timeBaseNs, const int64_t startTimeNs, const sp& pullerManager, @@ -85,8 +86,9 @@ ValueMetricProducer::ValueMetricProducer( const unordered_map>>& eventDeactivationMap, const vector& slicedStateAtoms, const unordered_map>& stateGroupMap) - : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, conditionWizard, - eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap), + : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, + conditionWizard, eventActivationMap, eventDeactivationMap, slicedStateAtoms, + stateGroupMap), mWhatMatcherIndex(whatMatcherIndex), mEventMatcherWizard(matcherWizard), mPullerManager(pullerManager), diff --git a/cmds/statsd/src/metrics/ValueMetricProducer.h b/cmds/statsd/src/metrics/ValueMetricProducer.h index aaf7df5c97717..3de5b99a2b090 100644 --- a/cmds/statsd/src/metrics/ValueMetricProducer.h +++ b/cmds/statsd/src/metrics/ValueMetricProducer.h @@ -52,6 +52,7 @@ class ValueMetricProducer : public virtual MetricProducer, public virtual PullDa public: ValueMetricProducer( const ConfigKey& key, const ValueMetric& valueMetric, const int conditionIndex, + const vector& initialConditionCache, const sp& conditionWizard, const int whatMatcherIndex, const sp& matcherWizard, const int pullTagId, const int64_t timeBaseNs, const int64_t startTimeNs, diff --git a/cmds/statsd/src/metrics/metrics_manager_util.cpp b/cmds/statsd/src/metrics/metrics_manager_util.cpp index 210d382b1363f..8917c36bb608a 100644 --- a/cmds/statsd/src/metrics/metrics_manager_util.cpp +++ b/cmds/statsd/src/metrics/metrics_manager_util.cpp @@ -285,11 +285,14 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config, const unordered_map& logTrackerMap, unordered_map& conditionTrackerMap, vector>& allConditionTrackers, - unordered_map>& trackerToConditionMap) { + unordered_map>& trackerToConditionMap, + vector& initialConditionCache) { vector conditionConfigs; const int conditionTrackerCount = config.predicate_size(); conditionConfigs.reserve(conditionTrackerCount); allConditionTrackers.reserve(conditionTrackerCount); + initialConditionCache.reserve(conditionTrackerCount); + std::fill(initialConditionCache.begin(), initialConditionCache.end(), ConditionState::kUnknown); for (int i = 0; i < conditionTrackerCount; i++) { const Predicate& condition = config.predicate(i); @@ -321,7 +324,7 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config, for (size_t i = 0; i < allConditionTrackers.size(); i++) { auto& conditionTracker = allConditionTrackers[i]; if (!conditionTracker->init(conditionConfigs, allConditionTrackers, conditionTrackerMap, - stackTracker)) { + stackTracker, initialConditionCache)) { return false; } for (const int trackerIndex : conditionTracker->getLogTrackerIndex()) { @@ -351,14 +354,14 @@ bool initStates(const StatsdConfig& config, unordered_map& stateAt } bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseTimeNs, - const int64_t currentTimeNs, - const sp& pullerManager, + const int64_t currentTimeNs, const sp& pullerManager, const unordered_map& logTrackerMap, const unordered_map& conditionTrackerMap, const vector>& allAtomMatchers, const unordered_map& stateAtomIdMap, const unordered_map>& allStateGroupMaps, vector>& allConditionTrackers, + const vector& initialConditionCache, vector>& allMetricProducers, unordered_map>& conditionToMetricMap, unordered_map>& trackerToMetricMap, @@ -441,9 +444,10 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t eventDeactivationMap); if (!success) return false; - sp countProducer = new CountMetricProducer( - key, metric, conditionIndex, wizard, timeBaseTimeNs, currentTimeNs, - eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap); + sp countProducer = + new CountMetricProducer(key, metric, conditionIndex, initialConditionCache, wizard, + timeBaseTimeNs, currentTimeNs, eventActivationMap, + eventDeactivationMap, slicedStateAtoms, stateGroupMap); allMetricProducers.push_back(countProducer); } @@ -547,10 +551,10 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t if (!success) return false; sp durationMetric = new DurationMetricProducer( - key, metric, conditionIndex, trackerIndices[0], trackerIndices[1], - trackerIndices[2], nesting, wizard, internalDimensions, timeBaseTimeNs, - currentTimeNs, eventActivationMap, eventDeactivationMap, slicedStateAtoms, - stateGroupMap); + key, metric, conditionIndex, initialConditionCache, trackerIndices[0], + trackerIndices[1], trackerIndices[2], nesting, wizard, internalDimensions, + timeBaseTimeNs, currentTimeNs, eventActivationMap, eventDeactivationMap, + slicedStateAtoms, stateGroupMap); allMetricProducers.push_back(durationMetric); } @@ -593,9 +597,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t eventDeactivationMap); if (!success) return false; - sp eventMetric = new EventMetricProducer( - key, metric, conditionIndex, wizard, timeBaseTimeNs, eventActivationMap, - eventDeactivationMap); + sp eventMetric = + new EventMetricProducer(key, metric, conditionIndex, initialConditionCache, wizard, + timeBaseTimeNs, eventActivationMap, eventDeactivationMap); allMetricProducers.push_back(eventMetric); } @@ -683,9 +687,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t if (!success) return false; sp valueProducer = new ValueMetricProducer( - key, metric, conditionIndex, wizard, trackerIndex, matcherWizard, pullTagId, - timeBaseTimeNs, currentTimeNs, pullerManager, eventActivationMap, - eventDeactivationMap, slicedStateAtoms, stateGroupMap); + key, metric, conditionIndex, initialConditionCache, wizard, trackerIndex, + matcherWizard, pullTagId, timeBaseTimeNs, currentTimeNs, pullerManager, + eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap); allMetricProducers.push_back(valueProducer); } @@ -778,9 +782,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t if (!success) return false; sp gaugeProducer = new GaugeMetricProducer( - key, metric, conditionIndex, wizard, trackerIndex, matcherWizard, pullTagId, - triggerAtomId, atomTagId, timeBaseTimeNs, currentTimeNs, pullerManager, - eventActivationMap, eventDeactivationMap); + key, metric, conditionIndex, initialConditionCache, wizard, trackerIndex, + matcherWizard, pullTagId, triggerAtomId, atomTagId, timeBaseTimeNs, currentTimeNs, + pullerManager, eventActivationMap, eventDeactivationMap); allMetricProducers.push_back(gaugeProducer); } for (int i = 0; i < config.no_report_metric_size(); ++i) { @@ -930,6 +934,7 @@ bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap& std::set& noReportMetricIds) { unordered_map logTrackerMap; unordered_map conditionTrackerMap; + vector initialConditionCache; unordered_map metricProducerMap; unordered_map stateAtomIdMap; unordered_map> allStateGroupMaps; @@ -941,7 +946,7 @@ bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap& VLOG("initLogMatchingTrackers succeed..."); if (!initConditions(key, config, logTrackerMap, conditionTrackerMap, allConditionTrackers, - trackerToConditionMap)) { + trackerToConditionMap, initialConditionCache)) { ALOGE("initConditionTrackers failed"); return false; } @@ -952,10 +957,10 @@ bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap& } if (!initMetrics(key, config, timeBaseNs, currentTimeNs, pullerManager, logTrackerMap, conditionTrackerMap, allAtomMatchers, stateAtomIdMap, allStateGroupMaps, - allConditionTrackers, allMetricProducers, - conditionToMetricMap, trackerToMetricMap, metricProducerMap, - noReportMetricIds, activationAtomTrackerToMetricMap, - deactivationAtomTrackerToMetricMap, metricsWithActivation)) { + allConditionTrackers, initialConditionCache, allMetricProducers, + conditionToMetricMap, trackerToMetricMap, metricProducerMap, noReportMetricIds, + activationAtomTrackerToMetricMap, deactivationAtomTrackerToMetricMap, + metricsWithActivation)) { ALOGE("initMetricProducers failed"); return false; } diff --git a/cmds/statsd/src/metrics/metrics_manager_util.h b/cmds/statsd/src/metrics/metrics_manager_util.h index 6af7a9adca209..96b5c26ff7893 100644 --- a/cmds/statsd/src/metrics/metrics_manager_util.h +++ b/cmds/statsd/src/metrics/metrics_manager_util.h @@ -60,12 +60,14 @@ bool initLogTrackers(const StatsdConfig& config, // [allConditionTrackers]: stores the sp to all the ConditionTrackers // [trackerToConditionMap]: contain the mapping from index of // log tracker to condition trackers that use the log tracker +// [initialConditionCache]: stores the initial conditions for each ConditionTracker bool initConditions(const ConfigKey& key, const StatsdConfig& config, const std::unordered_map& logTrackerMap, std::unordered_map& conditionTrackerMap, std::vector>& allConditionTrackers, std::unordered_map>& trackerToConditionMap, - std::unordered_map>& eventConditionLinks); + std::unordered_map>& eventConditionLinks, + std::vector& initialConditionCache); // Initialize State maps using State protos in the config. These maps will // eventually be passed to MetricProducers to initialize their state info. @@ -103,6 +105,7 @@ bool initMetrics( const unordered_map& stateAtomIdMap, const unordered_map>& allStateGroupMaps, vector>& allConditionTrackers, + const std::vector& initialConditionCache, std::vector>& allMetricProducers, std::unordered_map>& conditionToMetricMap, std::unordered_map>& trackerToMetricMap, diff --git a/cmds/statsd/tests/MetricsManager_test.cpp b/cmds/statsd/tests/MetricsManager_test.cpp index b3b095bf4bff6..6259757fe0929 100644 --- a/cmds/statsd/tests/MetricsManager_test.cpp +++ b/cmds/statsd/tests/MetricsManager_test.cpp @@ -276,11 +276,157 @@ StatsdConfig buildCirclePredicates() { return config; } +StatsdConfig buildConfigWithDifferentPredicates() { + StatsdConfig config; + config.set_id(12345); + + auto pulledAtomMatcher = + CreateSimpleAtomMatcher("SUBSYSTEM_SLEEP", util::SUBSYSTEM_SLEEP_STATE); + *config.add_atom_matcher() = pulledAtomMatcher; + auto screenOnAtomMatcher = CreateScreenTurnedOnAtomMatcher(); + *config.add_atom_matcher() = screenOnAtomMatcher; + auto screenOffAtomMatcher = CreateScreenTurnedOffAtomMatcher(); + *config.add_atom_matcher() = screenOffAtomMatcher; + auto batteryNoneAtomMatcher = CreateBatteryStateNoneMatcher(); + *config.add_atom_matcher() = batteryNoneAtomMatcher; + auto batteryUsbAtomMatcher = CreateBatteryStateUsbMatcher(); + *config.add_atom_matcher() = batteryUsbAtomMatcher; + + // Simple condition with InitialValue set to default (unknown). + auto screenOnUnknownPredicate = CreateScreenIsOnPredicate(); + *config.add_predicate() = screenOnUnknownPredicate; + + // Simple condition with InitialValue set to false. + auto screenOnFalsePredicate = config.add_predicate(); + screenOnFalsePredicate->set_id(StringToId("ScreenIsOnInitialFalse")); + SimplePredicate* simpleScreenOnFalsePredicate = + screenOnFalsePredicate->mutable_simple_predicate(); + simpleScreenOnFalsePredicate->set_start(screenOnAtomMatcher.id()); + simpleScreenOnFalsePredicate->set_stop(screenOffAtomMatcher.id()); + simpleScreenOnFalsePredicate->set_initial_value(SimplePredicate_InitialValue_FALSE); + + // Simple condition with InitialValue set to false. + auto onBatteryFalsePredicate = config.add_predicate(); + onBatteryFalsePredicate->set_id(StringToId("OnBatteryInitialFalse")); + SimplePredicate* simpleOnBatteryFalsePredicate = + onBatteryFalsePredicate->mutable_simple_predicate(); + simpleOnBatteryFalsePredicate->set_start(batteryNoneAtomMatcher.id()); + simpleOnBatteryFalsePredicate->set_stop(batteryUsbAtomMatcher.id()); + simpleOnBatteryFalsePredicate->set_initial_value(SimplePredicate_InitialValue_FALSE); + + // Combination condition with both simple condition InitialValues set to false. + auto screenOnFalseOnBatteryFalsePredicate = config.add_predicate(); + screenOnFalseOnBatteryFalsePredicate->set_id(StringToId("ScreenOnFalseOnBatteryFalse")); + screenOnFalseOnBatteryFalsePredicate->mutable_combination()->set_operation( + LogicalOperation::AND); + addPredicateToPredicateCombination(*screenOnFalsePredicate, + screenOnFalseOnBatteryFalsePredicate); + addPredicateToPredicateCombination(*onBatteryFalsePredicate, + screenOnFalseOnBatteryFalsePredicate); + + // Combination condition with one simple condition InitialValue set to unknown and one set to + // false. + auto screenOnUnknownOnBatteryFalsePredicate = config.add_predicate(); + screenOnUnknownOnBatteryFalsePredicate->set_id(StringToId("ScreenOnUnknowneOnBatteryFalse")); + screenOnUnknownOnBatteryFalsePredicate->mutable_combination()->set_operation( + LogicalOperation::AND); + addPredicateToPredicateCombination(screenOnUnknownPredicate, + screenOnUnknownOnBatteryFalsePredicate); + addPredicateToPredicateCombination(*onBatteryFalsePredicate, + screenOnUnknownOnBatteryFalsePredicate); + + // Simple condition metric with initial value false. + ValueMetric* metric1 = config.add_value_metric(); + metric1->set_id(StringToId("ValueSubsystemSleepWhileScreenOnInitialFalse")); + metric1->set_what(pulledAtomMatcher.id()); + *metric1->mutable_value_field() = + CreateDimensions(util::SUBSYSTEM_SLEEP_STATE, {4 /* time sleeping field */}); + metric1->set_bucket(FIVE_MINUTES); + metric1->set_condition(screenOnFalsePredicate->id()); + + // Simple condition metric with initial value unknown. + ValueMetric* metric2 = config.add_value_metric(); + metric2->set_id(StringToId("ValueSubsystemSleepWhileScreenOnInitialUnknown")); + metric2->set_what(pulledAtomMatcher.id()); + *metric2->mutable_value_field() = + CreateDimensions(util::SUBSYSTEM_SLEEP_STATE, {4 /* time sleeping field */}); + metric2->set_bucket(FIVE_MINUTES); + metric2->set_condition(screenOnUnknownPredicate.id()); + + // Combination condition metric with initial values false and false. + ValueMetric* metric3 = config.add_value_metric(); + metric3->set_id(StringToId("ValueSubsystemSleepWhileScreenOnFalseDeviceUnpluggedFalse")); + metric3->set_what(pulledAtomMatcher.id()); + *metric3->mutable_value_field() = + CreateDimensions(util::SUBSYSTEM_SLEEP_STATE, {4 /* time sleeping field */}); + metric3->set_bucket(FIVE_MINUTES); + metric3->set_condition(screenOnFalseOnBatteryFalsePredicate->id()); + + // Combination condition metric with initial values unknown and false. + ValueMetric* metric4 = config.add_value_metric(); + metric4->set_id(StringToId("ValueSubsystemSleepWhileScreenOnUnknownDeviceUnpluggedFalse")); + metric4->set_what(pulledAtomMatcher.id()); + *metric4->mutable_value_field() = + CreateDimensions(util::SUBSYSTEM_SLEEP_STATE, {4 /* time sleeping field */}); + metric4->set_bucket(FIVE_MINUTES); + metric4->set_condition(screenOnUnknownOnBatteryFalsePredicate->id()); + + return config; +} + bool isSubset(const set& set1, const set& set2) { return std::includes(set2.begin(), set2.end(), set1.begin(), set1.end()); } } // anonymous namespace +TEST(MetricsManagerTest, TestInitialConditions) { + UidMap uidMap; + sp pullerManager = new StatsPullerManager(); + sp anomalyAlarmMonitor; + sp periodicAlarmMonitor; + StatsdConfig config = buildConfigWithDifferentPredicates(); + set allTagIds; + vector> allAtomMatchers; + vector> allConditionTrackers; + vector> allMetricProducers; + std::vector> allAnomalyTrackers; + std::vector> allAlarmTrackers; + unordered_map> conditionToMetricMap; + unordered_map> trackerToMetricMap; + unordered_map> trackerToConditionMap; + unordered_map> activationAtomTrackerToMetricMap; + unordered_map> deactivationAtomTrackerToMetricMap; + unordered_map alertTrackerMap; + vector metricsWithActivation; + std::set noReportMetricIds; + + EXPECT_TRUE(initStatsdConfig( + kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor, + timeBaseSec, timeBaseSec, allTagIds, allAtomMatchers, allConditionTrackers, + allMetricProducers, allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap, + trackerToMetricMap, trackerToConditionMap, activationAtomTrackerToMetricMap, + deactivationAtomTrackerToMetricMap, alertTrackerMap, metricsWithActivation, + noReportMetricIds)); + ASSERT_EQ(4u, allMetricProducers.size()); + ASSERT_EQ(5u, allConditionTrackers.size()); + + ConditionKey queryKey; + vector conditionCache(5, ConditionState::kNotEvaluated); + + allConditionTrackers[3]->isConditionMet(queryKey, allConditionTrackers, false, conditionCache); + allConditionTrackers[4]->isConditionMet(queryKey, allConditionTrackers, false, conditionCache); + EXPECT_EQ(ConditionState::kUnknown, conditionCache[0]); + EXPECT_EQ(ConditionState::kFalse, conditionCache[1]); + EXPECT_EQ(ConditionState::kFalse, conditionCache[2]); + EXPECT_EQ(ConditionState::kFalse, conditionCache[3]); + EXPECT_EQ(ConditionState::kUnknown, conditionCache[4]); + + EXPECT_EQ(ConditionState::kFalse, allMetricProducers[0]->mCondition); + EXPECT_EQ(ConditionState::kUnknown, allMetricProducers[1]->mCondition); + EXPECT_EQ(ConditionState::kFalse, allMetricProducers[2]->mCondition); + EXPECT_EQ(ConditionState::kUnknown, allMetricProducers[3]->mCondition); +} + TEST(MetricsManagerTest, TestGoodConfig) { UidMap uidMap; sp pullerManager = new StatsPullerManager(); diff --git a/cmds/statsd/tests/condition/CombinationConditionTracker_test.cpp b/cmds/statsd/tests/condition/CombinationConditionTracker_test.cpp index 6529d65a5825e..1d501fd5a87ce 100644 --- a/cmds/statsd/tests/condition/CombinationConditionTracker_test.cpp +++ b/cmds/statsd/tests/condition/CombinationConditionTracker_test.cpp @@ -24,6 +24,7 @@ using namespace android::os::statsd; using std::vector; #ifdef __ANDROID__ + TEST(ConditionTrackerTest, TestUnknownCondition) { LogicalOperation operation = LogicalOperation::AND; diff --git a/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp b/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp index 86e24fb0c80b2..07b5311b1207f 100644 --- a/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp +++ b/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp @@ -112,6 +112,114 @@ std::map getWakeLockQueryKey( return outputKeyMap; } +TEST(SimpleConditionTrackerTest, TestNonSlicedInitialValueFalse) { + SimplePredicate simplePredicate; + simplePredicate.set_start(StringToId("SCREEN_TURNED_ON")); + simplePredicate.set_stop(StringToId("SCREEN_TURNED_OFF")); + simplePredicate.set_count_nesting(false); + simplePredicate.set_initial_value(SimplePredicate_InitialValue_FALSE); + + unordered_map trackerNameIndexMap; + trackerNameIndexMap[StringToId("SCREEN_TURNED_ON")] = 0; + trackerNameIndexMap[StringToId("SCREEN_TURNED_OFF")] = 1; + + SimpleConditionTracker conditionTracker(kConfigKey, StringToId("SCREEN_IS_ON"), + 0 /*tracker index*/, simplePredicate, + trackerNameIndexMap); + + ConditionKey queryKey; + vector> allPredicates; + vector conditionCache(1, ConditionState::kNotEvaluated); + + // Check that initial condition is false. + conditionTracker.isConditionMet(queryKey, allPredicates, false, conditionCache); + EXPECT_EQ(ConditionState::kFalse, conditionCache[0]); + + vector matcherState; + vector changedCache(1, false); + + // Matched stop event. + // Check that condition is still false. + unique_ptr screenOffEvent = + CreateScreenStateChangedEvent(/*timestamp=*/50, android::view::DISPLAY_STATE_OFF); + matcherState.clear(); + matcherState.push_back(MatchingState::kNotMatched); // On matcher not matched + matcherState.push_back(MatchingState::kMatched); // Off matcher matched + conditionCache[0] = ConditionState::kNotEvaluated; + conditionTracker.evaluateCondition(*screenOffEvent, matcherState, allPredicates, conditionCache, + changedCache); + EXPECT_EQ(ConditionState::kFalse, conditionCache[0]); + EXPECT_FALSE(changedCache[0]); + + // Matched start event. + // Check that condition has changed to true. + unique_ptr screenOnEvent = + CreateScreenStateChangedEvent(/*timestamp=*/100, android::view::DISPLAY_STATE_ON); + matcherState.clear(); + matcherState.push_back(MatchingState::kMatched); // On matcher matched + matcherState.push_back(MatchingState::kNotMatched); // Off matcher not matched + conditionCache[0] = ConditionState::kNotEvaluated; + changedCache[0] = false; + conditionTracker.evaluateCondition(*screenOnEvent, matcherState, allPredicates, conditionCache, + changedCache); + EXPECT_EQ(ConditionState::kTrue, conditionCache[0]); + EXPECT_TRUE(changedCache[0]); +} + +TEST(SimpleConditionTrackerTest, TestNonSlicedInitialValueUnknown) { + SimplePredicate simplePredicate; + simplePredicate.set_start(StringToId("SCREEN_TURNED_ON")); + simplePredicate.set_stop(StringToId("SCREEN_TURNED_OFF")); + simplePredicate.set_count_nesting(false); + simplePredicate.set_initial_value(SimplePredicate_InitialValue_UNKNOWN); + + unordered_map trackerNameIndexMap; + trackerNameIndexMap[StringToId("SCREEN_TURNED_ON")] = 0; + trackerNameIndexMap[StringToId("SCREEN_TURNED_OFF")] = 1; + + SimpleConditionTracker conditionTracker(kConfigKey, StringToId("SCREEN_IS_ON"), + 0 /*tracker index*/, simplePredicate, + trackerNameIndexMap); + + ConditionKey queryKey; + vector> allPredicates; + vector conditionCache(1, ConditionState::kNotEvaluated); + + // Check that initial condition is unknown. + conditionTracker.isConditionMet(queryKey, allPredicates, false, conditionCache); + EXPECT_EQ(ConditionState::kUnknown, conditionCache[0]); + + vector matcherState; + vector changedCache(1, false); + + // Matched stop event. + // Check that condition is changed to false. + unique_ptr screenOffEvent = + CreateScreenStateChangedEvent(/*timestamp=*/50, android::view::DISPLAY_STATE_OFF); + matcherState.clear(); + matcherState.push_back(MatchingState::kNotMatched); // On matcher not matched + matcherState.push_back(MatchingState::kMatched); // Off matcher matched + conditionCache[0] = ConditionState::kNotEvaluated; + conditionTracker.evaluateCondition(*screenOffEvent, matcherState, allPredicates, conditionCache, + changedCache); + EXPECT_EQ(ConditionState::kFalse, conditionCache[0]); + EXPECT_TRUE(changedCache[0]); + + // Matched start event. + // Check that condition has changed to true. + unique_ptr screenOnEvent = + CreateScreenStateChangedEvent(/*timestamp=*/100, android::view::DISPLAY_STATE_ON); + matcherState.clear(); + matcherState.push_back(MatchingState::kMatched); // On matcher matched + matcherState.push_back(MatchingState::kNotMatched); // Off matcher not matched + conditionCache[0] = ConditionState::kNotEvaluated; + changedCache[0] = false; + conditionTracker.evaluateCondition(*screenOnEvent, matcherState, allPredicates, conditionCache, + changedCache); + EXPECT_EQ(ConditionState::kTrue, conditionCache[0]); + EXPECT_TRUE(changedCache[0]); +} + TEST(SimpleConditionTrackerTest, TestNonSlicedCondition) { SimplePredicate simplePredicate; simplePredicate.set_start(StringToId("SCREEN_TURNED_ON")); diff --git a/cmds/statsd/tests/metrics/CountMetricProducer_test.cpp b/cmds/statsd/tests/metrics/CountMetricProducer_test.cpp index 74ecaac0f9e35..bb8e7bfd90f42 100644 --- a/cmds/statsd/tests/metrics/CountMetricProducer_test.cpp +++ b/cmds/statsd/tests/metrics/CountMetricProducer_test.cpp @@ -74,8 +74,8 @@ TEST(CountMetricProducerTest, TestFirstBucket) { metric.set_bucket(ONE_MINUTE); sp wizard = new NaggyMock(); - CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, 5, - 600 * NS_PER_SEC + NS_PER_SEC / 2); + CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2); EXPECT_EQ(600500000000, countProducer.mCurrentBucketStartTimeNs); EXPECT_EQ(10, countProducer.mCurrentBucketNum); EXPECT_EQ(660000000005, countProducer.getCurrentBucketEndTimeNs()); @@ -94,8 +94,8 @@ TEST(CountMetricProducerTest, TestNonDimensionalEvents) { sp wizard = new NaggyMock(); - CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - bucketStartTimeNs, bucketStartTimeNs); + CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, bucketStartTimeNs, bucketStartTimeNs); // 2 events in bucket 1. LogEvent event1(/*uid=*/0, /*pid=*/0); @@ -157,8 +157,8 @@ TEST(CountMetricProducerTest, TestEventsWithNonSlicedCondition) { sp wizard = new NaggyMock(); - CountMetricProducer countProducer(kConfigKey, metric, 1, wizard, bucketStartTimeNs, - bucketStartTimeNs); + CountMetricProducer countProducer(kConfigKey, metric, 0, {ConditionState::kUnknown}, wizard, + bucketStartTimeNs, bucketStartTimeNs); countProducer.onConditionChanged(true, bucketStartTimeNs); @@ -220,12 +220,14 @@ TEST(CountMetricProducerTest, TestEventsWithSlicedCondition) { getMockedDimensionKey(conditionTagId, 2, "222")}; sp wizard = new NaggyMock(); + EXPECT_CALL(*wizard, query(_, key1, _)).WillOnce(Return(ConditionState::kFalse)); EXPECT_CALL(*wizard, query(_, key2, _)).WillOnce(Return(ConditionState::kTrue)); - CountMetricProducer countProducer(kConfigKey, metric, 1 /*condition tracker index*/, wizard, - bucketStartTimeNs, bucketStartTimeNs); + CountMetricProducer countProducer(kConfigKey, metric, 0 /*condition tracker index*/, + {ConditionState::kUnknown}, wizard, bucketStartTimeNs, + bucketStartTimeNs); countProducer.onMatchedLogEvent(1 /*log matcher index*/, event1); countProducer.flushIfNeededLocked(bucketStartTimeNs + 1); @@ -261,7 +263,8 @@ TEST_P(CountMetricProducerTest_PartialBucket, TestSplitInCurrentBucket) { alert.set_trigger_if_sum_gt(2); sp wizard = new NaggyMock(); - CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, wizard, + + CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, {}, wizard, bucketStartTimeNs, bucketStartTimeNs); sp anomalyTracker = countProducer.addAnomalyTracker(alert, alarmMonitor); @@ -327,7 +330,8 @@ TEST_P(CountMetricProducerTest_PartialBucket, TestSplitInNextBucket) { metric.set_bucket(ONE_MINUTE); sp wizard = new NaggyMock(); - CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, wizard, + + CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, {}, wizard, bucketStartTimeNs, bucketStartTimeNs); // Bucket is flushed yet. @@ -391,8 +395,9 @@ TEST(CountMetricProducerTest, TestAnomalyDetectionUnSliced) { metric.set_bucket(ONE_MINUTE); sp wizard = new NaggyMock(); - CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - bucketStartTimeNs, bucketStartTimeNs); + + CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, bucketStartTimeNs, bucketStartTimeNs); sp anomalyTracker = countProducer.addAnomalyTracker(alert, alarmMonitor); @@ -453,8 +458,8 @@ TEST(CountMetricProducerTest, TestOneWeekTimeUnit) { int64_t oneDayNs = 24 * 60 * 60 * 1e9; int64_t fiveWeeksNs = 5 * 7 * oneDayNs; - CountMetricProducer countProducer( - kConfigKey, metric, -1 /* meaning no condition */, wizard, oneDayNs, fiveWeeksNs); + CountMetricProducer countProducer(kConfigKey, metric, -1 /* meaning no condition */, {}, wizard, + oneDayNs, fiveWeeksNs); int64_t fiveWeeksOneDayNs = fiveWeeksNs + oneDayNs; diff --git a/cmds/statsd/tests/metrics/DurationMetricProducer_test.cpp b/cmds/statsd/tests/metrics/DurationMetricProducer_test.cpp index ddda71db4bd42..05cfa37b0ee10 100644 --- a/cmds/statsd/tests/metrics/DurationMetricProducer_test.cpp +++ b/cmds/statsd/tests/metrics/DurationMetricProducer_test.cpp @@ -70,9 +70,11 @@ TEST(DurationMetricTrackerTest, TestFirstBucket) { metric.set_aggregation_type(DurationMetric_AggregationType_SUM); FieldMatcher dimensions; - DurationMetricProducer durationProducer( - kConfigKey, metric, -1 /*no condition*/, 1 /* start index */, 2 /* stop index */, - 3 /* stop_all index */, false /*nesting*/, wizard, dimensions, 5, 600 * NS_PER_SEC + NS_PER_SEC/2); + + DurationMetricProducer durationProducer(kConfigKey, metric, -1 /*no condition*/, {}, + 1 /* start index */, 2 /* stop index */, + 3 /* stop_all index */, false /*nesting*/, wizard, + dimensions, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2); EXPECT_EQ(600500000000, durationProducer.mCurrentBucketStartTimeNs); EXPECT_EQ(10, durationProducer.mCurrentBucketNum); @@ -96,7 +98,8 @@ TEST(DurationMetricTrackerTest, TestNoCondition) { makeLogEvent(&event2, bucketStartTimeNs + bucketSizeNs + 2, tagId); FieldMatcher dimensions; - DurationMetricProducer durationProducer(kConfigKey, metric, -1 /*no condition*/, + + DurationMetricProducer durationProducer(kConfigKey, metric, -1 /*no condition*/, {}, 1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/, wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs); @@ -138,10 +141,11 @@ TEST(DurationMetricTrackerTest, TestNonSlicedCondition) { makeLogEvent(&event4, bucketStartTimeNs + bucketSizeNs + 3, tagId); FieldMatcher dimensions; - DurationMetricProducer durationProducer(kConfigKey, metric, 0 /* condition index */, - 1 /* start index */, 2 /* stop index */, - 3 /* stop_all index */, false /*nesting*/, wizard, - dimensions, bucketStartTimeNs, bucketStartTimeNs); + + DurationMetricProducer durationProducer( + kConfigKey, metric, 0 /* condition index */, {ConditionState::kUnknown}, + 1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/, + wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs); durationProducer.mCondition = ConditionState::kFalse; EXPECT_FALSE(durationProducer.mCondition); @@ -187,10 +191,11 @@ TEST(DurationMetricTrackerTest, TestNonSlicedConditionUnknownState) { makeLogEvent(&event4, bucketStartTimeNs + bucketSizeNs + 3, tagId); FieldMatcher dimensions; - DurationMetricProducer durationProducer(kConfigKey, metric, 0 /* condition index */, - 1 /* start index */, 2 /* stop index */, - 3 /* stop_all index */, false /*nesting*/, wizard, - dimensions, bucketStartTimeNs, bucketStartTimeNs); + + DurationMetricProducer durationProducer( + kConfigKey, metric, 0 /* condition index */, {ConditionState::kUnknown}, + 1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/, + wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs); EXPECT_EQ(ConditionState::kUnknown, durationProducer.mCondition); EXPECT_FALSE(durationProducer.isConditionSliced()); @@ -232,7 +237,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestSumDuration) { metric.set_aggregation_type(DurationMetric_AggregationType_SUM); sp wizard = new NaggyMock(); FieldMatcher dimensions; - DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, + + DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {}, 1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/, wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs); @@ -294,7 +300,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestSumDurationWithSplitInFollo metric.set_aggregation_type(DurationMetric_AggregationType_SUM); sp wizard = new NaggyMock(); FieldMatcher dimensions; - DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, + + DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {}, 1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/, wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs); @@ -357,7 +364,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestSumDurationAnomaly) { sp wizard = new NaggyMock(); FieldMatcher dimensions; - DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, + + DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {}, 1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/, wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs); @@ -402,7 +410,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestMaxDuration) { sp wizard = new NaggyMock(); FieldMatcher dimensions; - DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, + + DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {}, 1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/, wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs); @@ -455,7 +464,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestMaxDurationWithSplitInNextB sp wizard = new NaggyMock(); FieldMatcher dimensions; - DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, + + DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {}, 1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/, wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs); diff --git a/cmds/statsd/tests/metrics/EventMetricProducer_test.cpp b/cmds/statsd/tests/metrics/EventMetricProducer_test.cpp index 5bae3648bd801..dfbb9da568b0d 100644 --- a/cmds/statsd/tests/metrics/EventMetricProducer_test.cpp +++ b/cmds/statsd/tests/metrics/EventMetricProducer_test.cpp @@ -65,8 +65,8 @@ TEST(EventMetricProducerTest, TestNoCondition) { sp wizard = new NaggyMock(); - EventMetricProducer eventProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - bucketStartTimeNs); + EventMetricProducer eventProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, bucketStartTimeNs); eventProducer.onMatchedLogEvent(1 /*matcher index*/, event1); eventProducer.onMatchedLogEvent(1 /*matcher index*/, event2); @@ -101,7 +101,8 @@ TEST(EventMetricProducerTest, TestEventsWithNonSlicedCondition) { sp wizard = new NaggyMock(); - EventMetricProducer eventProducer(kConfigKey, metric, 1, wizard, bucketStartTimeNs); + EventMetricProducer eventProducer(kConfigKey, metric, 0 /*condition index*/, + {ConditionState::kUnknown}, wizard, bucketStartTimeNs); eventProducer.onConditionChanged(true /*condition*/, bucketStartTimeNs); eventProducer.onMatchedLogEvent(1 /*matcher index*/, event1); @@ -155,7 +156,8 @@ TEST(EventMetricProducerTest, TestEventsWithSlicedCondition) { // Condition is true for second event. EXPECT_CALL(*wizard, query(_, key2, _)).WillOnce(Return(ConditionState::kTrue)); - EventMetricProducer eventProducer(kConfigKey, metric, 1, wizard, bucketStartTimeNs); + EventMetricProducer eventProducer(kConfigKey, metric, 0 /*condition index*/, + {ConditionState::kUnknown}, wizard, bucketStartTimeNs); eventProducer.onMatchedLogEvent(1 /*matcher index*/, event1); eventProducer.onMatchedLogEvent(1 /*matcher index*/, event2); diff --git a/cmds/statsd/tests/metrics/GaugeMetricProducer_test.cpp b/cmds/statsd/tests/metrics/GaugeMetricProducer_test.cpp index cc5f45922d452..5997bedcdf2d7 100644 --- a/cmds/statsd/tests/metrics/GaugeMetricProducer_test.cpp +++ b/cmds/statsd/tests/metrics/GaugeMetricProducer_test.cpp @@ -104,10 +104,9 @@ TEST(GaugeMetricProducerTest, TestFirstBucket) { // statsd started long ago. // The metric starts in the middle of the bucket - GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, - -1, -1, tagId, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2, - pullerManager); + GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, -1, -1, + tagId, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2, pullerManager); gaugeProducer.prepareFirstBucket(); EXPECT_EQ(600500000000, gaugeProducer.mCurrentBucketStartTimeNs); @@ -147,9 +146,9 @@ TEST(GaugeMetricProducerTest, TestPulledEventsNoCondition) { return true; })); - GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId, - bucketStartTimeNs, bucketStartTimeNs, pullerManager); + GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1, + tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); gaugeProducer.prepareFirstBucket(); vector> allData; @@ -225,8 +224,8 @@ TEST_P(GaugeMetricProducerTest_PartialBucket, TestPushedEvents) { new EventMatcherWizard({new SimpleLogMatchingTracker( atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)}); - GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, + GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, -1 /* -1 means no pulling */, -1, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); gaugeProducer.prepareFirstBucket(); @@ -308,7 +307,6 @@ TEST_P(GaugeMetricProducerTest_PartialBucket, TestPulled) { sp eventMatcherWizard = new EventMatcherWizard({new SimpleLogMatchingTracker( atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)}); - sp pullerManager = new StrictMock(); EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); @@ -322,9 +320,9 @@ TEST_P(GaugeMetricProducerTest_PartialBucket, TestPulled) { return true; })); - GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId, - bucketStartTimeNs, bucketStartTimeNs, pullerManager); + GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1, + tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); gaugeProducer.prepareFirstBucket(); vector> allData; @@ -393,9 +391,9 @@ TEST(GaugeMetricProducerTest, TestPulledWithAppUpgradeDisabled) { EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) .WillOnce(Return(false)); - GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId, - bucketStartTimeNs, bucketStartTimeNs, pullerManager); + GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1, + tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); gaugeProducer.prepareFirstBucket(); vector> allData; @@ -450,7 +448,8 @@ TEST(GaugeMetricProducerTest, TestPulledEventsWithCondition) { return true; })); - GaugeMetricProducer gaugeProducer(kConfigKey, metric, 1, wizard, logEventMatcherIndex, + GaugeMetricProducer gaugeProducer(kConfigKey, metric, 0 /*condition index*/, + {ConditionState::kUnknown}, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); gaugeProducer.prepareFirstBucket(); @@ -536,7 +535,8 @@ TEST(GaugeMetricProducerTest, TestPulledEventsWithSlicedCondition) { return true; })); - GaugeMetricProducer gaugeProducer(kConfigKey, metric, 1, wizard, logEventMatcherIndex, + GaugeMetricProducer gaugeProducer(kConfigKey, metric, 0 /*condition index*/, + {ConditionState::kUnknown}, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); gaugeProducer.prepareFirstBucket(); @@ -584,9 +584,9 @@ TEST(GaugeMetricProducerTest, TestPulledEventsAnomalyDetection) { new EventMatcherWizard({new SimpleLogMatchingTracker( atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)}); - GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId, - bucketStartTimeNs, bucketStartTimeNs, pullerManager); + GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1, + tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); gaugeProducer.prepareFirstBucket(); Alert alert; @@ -683,9 +683,10 @@ TEST(GaugeMetricProducerTest, TestPullOnTrigger) { .WillOnce(Return(true)); int triggerId = 5; - GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, tagId, triggerId, - tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); + GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, tagId, + triggerId, tagId, bucketStartTimeNs, bucketStartTimeNs, + pullerManager); gaugeProducer.prepareFirstBucket(); ASSERT_EQ(0UL, gaugeProducer.mCurrentSlicedBucket->size()); @@ -761,9 +762,10 @@ TEST(GaugeMetricProducerTest, TestRemoveDimensionInOutput) { .WillOnce(Return(true)); int triggerId = 5; - GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, tagId, triggerId, - tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); + GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, tagId, + triggerId, tagId, bucketStartTimeNs, bucketStartTimeNs, + pullerManager); gaugeProducer.prepareFirstBucket(); LogEvent triggerEvent(/*uid=*/0, /*pid=*/0); @@ -823,9 +825,10 @@ TEST(GaugeMetricProducerTest_BucketDrop, TestBucketDropWhenBucketTooSmall) { })); int triggerId = 5; - GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, tagId, triggerId, - tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); + GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, tagId, + triggerId, tagId, bucketStartTimeNs, bucketStartTimeNs, + pullerManager); gaugeProducer.prepareFirstBucket(); LogEvent triggerEvent(/*uid=*/0, /*pid=*/0); diff --git a/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp b/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp index 52eb7409aa5dd..1bcc35d99d18f 100644 --- a/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp +++ b/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp @@ -111,15 +111,17 @@ public: EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)) .WillRepeatedly(Return()); - sp valueProducer = new ValueMetricProducer( - kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, logEventMatcherIndex, - eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); + sp valueProducer = + new ValueMetricProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, tagId, + bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer->prepareFirstBucket(); return valueProducer; } static sp createValueProducerWithCondition( - sp& pullerManager, ValueMetric& metric) { + sp& pullerManager, ValueMetric& metric, + ConditionState conditionAfterFirstBucketPrepared) { UidMap uidMap; SimpleAtomMatcher atomMatcher; atomMatcher.set_atom_id(tagId); @@ -133,31 +135,11 @@ public: .WillRepeatedly(Return()); sp valueProducer = new ValueMetricProducer( - kConfigKey, metric, 1, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, - bucketStartTimeNs, bucketStartTimeNs, pullerManager); - valueProducer->prepareFirstBucket(); - valueProducer->mCondition = ConditionState::kFalse; - return valueProducer; - } - - static sp createValueProducerWithNoInitialCondition( - sp& pullerManager, ValueMetric& metric) { - UidMap uidMap; - SimpleAtomMatcher atomMatcher; - atomMatcher.set_atom_id(tagId); - sp eventMatcherWizard = - new EventMatcherWizard({new SimpleLogMatchingTracker( - atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)}); - sp wizard = new NaggyMock(); - EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)) - .WillOnce(Return()); - EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)) - .WillRepeatedly(Return()); - - sp valueProducer = new ValueMetricProducer( - kConfigKey, metric, 1, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, - bucketStartTimeNs, bucketStartTimeNs, pullerManager); + kConfigKey, metric, 0 /*condition index*/, {ConditionState::kUnknown}, wizard, + logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs, + bucketStartTimeNs, pullerManager); valueProducer->prepareFirstBucket(); + valueProducer->mCondition = conditionAfterFirstBucketPrepared; return valueProducer; } @@ -176,8 +158,9 @@ public: .WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)) .WillRepeatedly(Return()); + sp valueProducer = new ValueMetricProducer( - kConfigKey, metric, -1 /* no condition */, wizard, logEventMatcherIndex, + kConfigKey, metric, -1 /* no condition */, {}, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager, {}, {}, slicedStateAtoms, stateGroupMap); valueProducer->prepareFirstBucket(); @@ -232,9 +215,9 @@ TEST(ValueMetricProducerTest, TestCalcPreviousBucketEndTime) { // statsd started long ago. // The metric starts in the middle of the bucket - ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, -1, startTimeBase, - 22, pullerManager); + ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, -1, + startTimeBase, 22, pullerManager); valueProducer.prepareFirstBucket(); EXPECT_EQ(startTimeBase, valueProducer.calcPreviousBucketEndTime(60 * NS_PER_SEC + 10)); @@ -262,8 +245,8 @@ TEST(ValueMetricProducerTest, TestFirstBucket) { // statsd started long ago. // The metric starts in the middle of the bucket - ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, -1, 5, + ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, -1, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2, pullerManager); valueProducer.prepareFirstBucket(); @@ -427,7 +410,7 @@ TEST(ValueMetricProducerTest, TestPulledEventsWithFiltering) { })); sp valueProducer = new ValueMetricProducer( - kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, logEventMatcherIndex, + kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer->prepareFirstBucket(); @@ -629,7 +612,8 @@ TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 8); @@ -689,7 +673,8 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPushedEvents) { atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)}); sp wizard = new NaggyMock(); sp pullerManager = new StrictMock(); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -762,7 +747,8 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValue) { data->push_back(CreateRepeatedValueLogEvent(tagId, partialBucketSplitTimeNs, 120)); return true; })); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -813,7 +799,8 @@ TEST(ValueMetricProducerTest, TestPulledWithAppUpgradeDisabled) { EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) .WillOnce(Return(true)); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -851,7 +838,8 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValueWhileConditionFalse return true; })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 1); @@ -875,6 +863,7 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValueWhileConditionFalse {bucketStartTimeNs}, {partialBucketSplitTimeNs}); EXPECT_FALSE(valueProducer->mCondition); } + TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) { ValueMetric metric = ValueMetricProducerTestHelper::createMetric(); @@ -887,7 +876,7 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) { sp wizard = new NaggyMock(); sp pullerManager = new StrictMock(); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -931,9 +920,9 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithCondition) { sp wizard = new NaggyMock(); sp pullerManager = new StrictMock(); - ValueMetricProducer valueProducer(kConfigKey, metric, 1, wizard, logEventMatcherIndex, - eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs, - pullerManager); + ValueMetricProducer valueProducer(kConfigKey, metric, 0, {ConditionState::kUnknown}, wizard, + logEventMatcherIndex, eventMatcherWizard, -1, + bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); valueProducer.mCondition = ConditionState::kFalse; @@ -1001,9 +990,11 @@ TEST(ValueMetricProducerTest, TestAnomalyDetection) { atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)}); sp wizard = new NaggyMock(); sp pullerManager = new StrictMock(); - ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, - logEventMatcherIndex, eventMatcherWizard, -1 /*not pulled*/, - bucketStartTimeNs, bucketStartTimeNs, pullerManager); + + ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, + wizard, logEventMatcherIndex, eventMatcherWizard, + -1 /*not pulled*/, bucketStartTimeNs, bucketStartTimeNs, + pullerManager); valueProducer.prepareFirstBucket(); sp anomalyTracker = valueProducer.addAnomalyTracker(alert, alarmMonitor); @@ -1158,7 +1149,8 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition) { return true; })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 8); @@ -1229,7 +1221,8 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition2) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 8); @@ -1300,7 +1293,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateMin) { sp wizard = new NaggyMock(); sp pullerManager = new StrictMock(); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -1344,7 +1337,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateMax) { sp wizard = new NaggyMock(); sp pullerManager = new StrictMock(); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -1387,7 +1380,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateAvg) { sp wizard = new NaggyMock(); sp pullerManager = new StrictMock(); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -1435,7 +1428,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateSum) { sp wizard = new NaggyMock(); sp pullerManager = new StrictMock(); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -1479,7 +1472,7 @@ TEST(ValueMetricProducerTest, TestSkipZeroDiffOutput) { sp wizard = new NaggyMock(); sp pullerManager = new StrictMock(); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -1551,7 +1544,7 @@ TEST(ValueMetricProducerTest, TestSkipZeroDiffOutputMultiValue) { sp wizard = new NaggyMock(); sp pullerManager = new StrictMock(); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -1944,7 +1937,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailAfterConditionChange_EndOfB })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 8); // has one slice @@ -1979,7 +1973,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailAfterConditionChange) { .WillOnce(Return(false)); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 8); @@ -2023,7 +2018,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailBeforeConditionChange) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); // Don't directly set mCondition; the real code never does that. Go through regular code path // to avoid unexpected behaviors. @@ -2057,9 +2053,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullDelayExceeded) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - - valueProducer->mCondition = ConditionState::kFalse; + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); // Max delay is set to 0 so pull will exceed max delay. valueProducer->onConditionChanged(true, bucketStartTimeNs + 1); @@ -2080,9 +2075,9 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullTooLate) { EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillRepeatedly(Return()); - ValueMetricProducer valueProducer(kConfigKey, metric, 1, wizard, logEventMatcherIndex, - eventMatcherWizard, tagId, bucket2StartTimeNs, - bucket2StartTimeNs, pullerManager); + ValueMetricProducer valueProducer(kConfigKey, metric, 0, {ConditionState::kUnknown}, wizard, + logEventMatcherIndex, eventMatcherWizard, tagId, + bucket2StartTimeNs, bucket2StartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); valueProducer.mCondition = ConditionState::kFalse; @@ -2105,9 +2100,8 @@ TEST(ValueMetricProducerTest, TestBaseSetOnConditionChange) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - - valueProducer->mCondition = ConditionState::kFalse; + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->mHasGlobalBase = false; valueProducer->onConditionChanged(true, bucketStartTimeNs + 1); @@ -2142,9 +2136,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenOneConditionFailed })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - - valueProducer->mCondition = ConditionState::kTrue; + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kTrue); // Bucket start. vector> allData; @@ -2218,8 +2211,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenGuardRailHit) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - valueProducer->mCondition = ConditionState::kFalse; + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 2); EXPECT_EQ(true, valueProducer->mCurrentBucketIsSkipped); @@ -2283,9 +2276,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenInitialPullFailed) })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - - valueProducer->mCondition = ConditionState::kTrue; + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kTrue); // Bucket start. vector> allData; @@ -2363,9 +2355,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenLastPullFailed) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - - valueProducer->mCondition = ConditionState::kTrue; + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kTrue); // Bucket start. vector> allData; @@ -2468,7 +2459,8 @@ TEST(ValueMetricProducerTest, TestEmptyDataResetsBase_onConditionChanged) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 10); ASSERT_EQ(1UL, valueProducer->mCurrentSlicedBucket.size()); @@ -2518,7 +2510,8 @@ TEST(ValueMetricProducerTest, TestEmptyDataResetsBase_onBucketBoundary) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 10); valueProducer->onConditionChanged(false, bucketStartTimeNs + 11); @@ -2566,7 +2559,8 @@ TEST(ValueMetricProducerTest, TestPartialResetOnBucketBoundaries) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 10); ASSERT_EQ(1UL, valueProducer->mCurrentSlicedBucket.size()); @@ -2673,8 +2667,8 @@ TEST(ValueMetricProducerTest, TestBucketBoundariesOnConditionChange) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - valueProducer->mCondition = ConditionState::kUnknown; + ValueMetricProducerTestHelper::createValueProducerWithCondition( + pullerManager, metric, ConditionState::kUnknown); valueProducer->onConditionChanged(false, bucketStartTimeNs); ASSERT_EQ(0UL, valueProducer->mCurrentSlicedBucket.size()); @@ -2814,7 +2808,8 @@ TEST(ValueMetricProducerTest, TestDataIsNotUpdatedWhenNoConditionChanged) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 8); valueProducer->onConditionChanged(false, bucketStartTimeNs + 10); @@ -2866,7 +2861,8 @@ TEST(ValueMetricProducerTest, TestBucketInvalidIfGlobalBaseIsNotSet) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucket2StartTimeNs + 10); vector> allData; @@ -2911,7 +2907,7 @@ TEST(ValueMetricProducerTest, TestPullNeededFastDump) { return true; })); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -2949,7 +2945,7 @@ TEST(ValueMetricProducerTest, TestFastDumpWithoutCurrentBucket) { return true; })); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -3002,7 +2998,7 @@ TEST(ValueMetricProducerTest, TestPullNeededNoTimeConstraints) { return true; })); - ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, + ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); valueProducer.prepareFirstBucket(); @@ -3058,8 +3054,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_withMultipleConditionChanges return true; })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - valueProducer->mCondition = ConditionState::kFalse; + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 8); valueProducer->onConditionChanged(false, bucketStartTimeNs + 50); @@ -3099,8 +3095,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_bucketBoundaryTrue) { return true; })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - valueProducer->mCondition = ConditionState::kFalse; + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 8); @@ -3124,8 +3120,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_bucketBoundaryFalse) { sp pullerManager = new StrictMock(); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - valueProducer->mCondition = ConditionState::kFalse; + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); // Now the alarm is delivered. Condition is off though. vector> allData; @@ -3152,8 +3148,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_withFailure) { })) .WillOnce(Return(false)); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); - valueProducer->mCondition = ConditionState::kFalse; + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); valueProducer->onConditionChanged(true, bucketStartTimeNs + 8); valueProducer->onConditionChanged(false, bucketStartTimeNs + 50); @@ -3191,7 +3187,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenDumpReportRequeste })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); // Condition change event. valueProducer->onConditionChanged(true, bucketStartTimeNs + 20); @@ -3236,7 +3233,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenConditionEventWron })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); // Condition change event. valueProducer->onConditionChanged(true, bucketStartTimeNs + 50); @@ -3298,7 +3296,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenAccumulateEventWro })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); // Condition change event. valueProducer->onConditionChanged(true, bucketStartTimeNs + 50); @@ -3363,8 +3362,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenConditionUnknown) })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithNoInitialCondition(pullerManager, - metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition( + pullerManager, metric, ConditionState::kUnknown); // Condition change event. valueProducer->onConditionChanged(true, bucketStartTimeNs + 50); @@ -3413,7 +3412,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenPullFailed) { .WillOnce(Return(false)); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); // Condition change event. valueProducer->onConditionChanged(true, bucketStartTimeNs + 50); @@ -3468,7 +3468,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenMultipleBucketsSki })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); // Condition change event. valueProducer->onConditionChanged(true, bucketStartTimeNs + 10); @@ -3542,7 +3543,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestBucketDropWhenBucketTooSmall) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); // Condition change event. valueProducer->onConditionChanged(true, bucketStartTimeNs + 10); @@ -3579,7 +3581,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestBucketDropWhenDataUnavailable) { sp pullerManager = new StrictMock(); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition( + pullerManager, metric, ConditionState::kUnknown); // Check dump report. ProtoOutputStream output; @@ -3632,7 +3635,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestBucketDropWhenForceBucketSplitBefor })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric, + ConditionState::kFalse); // Condition changed event int64_t conditionChangeTimeNs = bucketStartTimeNs + 10; @@ -3687,8 +3691,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestMultipleBucketDropEvents) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithNoInitialCondition(pullerManager, - metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition( + pullerManager, metric, ConditionState::kUnknown); // Condition change event. valueProducer->onConditionChanged(true, bucketStartTimeNs + 10); @@ -3756,8 +3760,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestMaxBucketDropEvents) { })); sp valueProducer = - ValueMetricProducerTestHelper::createValueProducerWithNoInitialCondition(pullerManager, - metric); + ValueMetricProducerTestHelper::createValueProducerWithCondition( + pullerManager, metric, ConditionState::kUnknown); // First condition change event causes guardrail to be reached. valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);