From 7b975a85db963e8e4a75fdaed13aec52a8d0f316 Mon Sep 17 00:00:00 2001 From: Tej Singh Date: Mon, 11 May 2020 11:05:08 -0700 Subject: [PATCH] Statsd: pull once per event time If a pull happens at the same event time, we should reuse the existing data, regardless of whether or not the cool down has been met. For example, if an app upgrade happens at time t, and two metrics need to pull atom a, if metric one pulls at time t, but metric two initiates the pull at time t+2, we should still reuse the pull from time t since that is when the app upgrade happened. Bug: 156294650 Test: atest statsd_test Change-Id: I4efc49545093f6683bf6dd89ed68c5dfa5b44d8f --- cmds/statsd/src/StatsService.cpp | 2 +- cmds/statsd/src/external/StatsPuller.cpp | 13 +- cmds/statsd/src/external/StatsPuller.h | 7 +- .../src/external/StatsPullerManager.cpp | 23 +- cmds/statsd/src/external/StatsPullerManager.h | 12 +- .../src/metrics/GaugeMetricProducer.cpp | 2 +- .../src/metrics/ValueMetricProducer.cpp | 2 +- cmds/statsd/src/shell/ShellSubscriber.cpp | 3 +- .../external/StatsCallbackPuller_test.cpp | 6 +- .../external/StatsPullerManager_test.cpp | 10 +- .../tests/external/StatsPuller_test.cpp | 119 +++- .../metrics/GaugeMetricProducer_test.cpp | 100 +-- .../metrics/ValueMetricProducer_test.cpp | 600 ++++++++++-------- .../tests/metrics/metrics_test_helper.h | 7 +- .../tests/shell/ShellSubscriber_test.cpp | 4 +- 15 files changed, 544 insertions(+), 366 deletions(-) diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp index a65f5f792daae..4ffa040fafd41 100644 --- a/cmds/statsd/src/StatsService.cpp +++ b/cmds/statsd/src/StatsService.cpp @@ -826,7 +826,7 @@ status_t StatsService::cmd_print_pulled_metrics(int out, const Vector& uids.push_back(AID_SYSTEM); } vector> stats; - if (mPullerManager->Pull(s, uids, &stats)) { + if (mPullerManager->Pull(s, uids, getElapsedRealtimeNs(), &stats)) { for (const auto& it : stats) { dprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str()); } diff --git a/cmds/statsd/src/external/StatsPuller.cpp b/cmds/statsd/src/external/StatsPuller.cpp index 829a60345ba70..9df4d1f8ce24a 100644 --- a/cmds/statsd/src/external/StatsPuller.cpp +++ b/cmds/statsd/src/external/StatsPuller.cpp @@ -38,14 +38,16 @@ StatsPuller::StatsPuller(const int tagId, const int64_t coolDownNs, const int64_ mPullTimeoutNs(pullTimeoutNs), mCoolDownNs(coolDownNs), mAdditiveFields(additiveFields), - mLastPullTimeNs(0) { + mLastPullTimeNs(0), + mLastEventTimeNs(0) { } -bool StatsPuller::Pull(std::vector>* data) { +bool StatsPuller::Pull(const int64_t eventTimeNs, std::vector>* data) { lock_guard lock(mLock); int64_t elapsedTimeNs = getElapsedRealtimeNs(); StatsdStats::getInstance().notePull(mTagId); - const bool shouldUseCache = elapsedTimeNs - mLastPullTimeNs < mCoolDownNs; + const bool shouldUseCache = + (mLastEventTimeNs == eventTimeNs) || (elapsedTimeNs - mLastPullTimeNs < mCoolDownNs); if (shouldUseCache) { if (mHasGoodData) { (*data) = mCachedData; @@ -54,13 +56,13 @@ bool StatsPuller::Pull(std::vector>* data) { } return mHasGoodData; } - if (mLastPullTimeNs > 0) { StatsdStats::getInstance().updateMinPullIntervalSec( mTagId, (elapsedTimeNs - mLastPullTimeNs) / NS_PER_SEC); } mCachedData.clear(); mLastPullTimeNs = elapsedTimeNs; + mLastEventTimeNs = eventTimeNs; mHasGoodData = PullInternal(&mCachedData); if (!mHasGoodData) { return mHasGoodData; @@ -70,7 +72,7 @@ bool StatsPuller::Pull(std::vector>* data) { const bool pullTimeOut = pullDurationNs > mPullTimeoutNs; if (pullTimeOut) { // Something went wrong. Discard the data. - clearCacheLocked(); + mCachedData.clear(); mHasGoodData = false; StatsdStats::getInstance().notePullTimeout(mTagId); ALOGW("Pull for atom %d exceeds timeout %lld nano seconds.", mTagId, @@ -104,6 +106,7 @@ int StatsPuller::clearCacheLocked() { int ret = mCachedData.size(); mCachedData.clear(); mLastPullTimeNs = 0; + mLastEventTimeNs = 0; return ret; } diff --git a/cmds/statsd/src/external/StatsPuller.h b/cmds/statsd/src/external/StatsPuller.h index fee571c52a5f4..470d15e6fbd1f 100644 --- a/cmds/statsd/src/external/StatsPuller.h +++ b/cmds/statsd/src/external/StatsPuller.h @@ -51,7 +51,7 @@ public: // 2) pull takes longer than mPullTimeoutNs (intrinsic to puller) // If a metric wants to make any change to the data, like timestamps, it // should make a copy as this data may be shared with multiple metrics. - bool Pull(std::vector>* data); + bool Pull(const int64_t eventTimeNs, std::vector>* data); // Clear cache immediately int ForceClearCache(); @@ -94,6 +94,11 @@ private: int64_t mLastPullTimeNs; + // All pulls happen due to an event (app upgrade, bucket boundary, condition change, etc). + // If multiple pulls need to be done at the same event time, we will always use the cache after + // the first pull. + int64_t mLastEventTimeNs; + // Cache of data from last pull. If next request comes before cool down finishes, // cached data will be returned. // Cached data is cleared when diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp index 1a52eb928777e..8a9ec7456e557 100644 --- a/cmds/statsd/src/external/StatsPullerManager.cpp +++ b/cmds/statsd/src/external/StatsPullerManager.cpp @@ -91,20 +91,21 @@ StatsPullerManager::StatsPullerManager() mPullAtomCallbackDeathRecipient(AIBinder_DeathRecipient_new(pullAtomCallbackDied)) { } -bool StatsPullerManager::Pull(int tagId, const ConfigKey& configKey, +bool StatsPullerManager::Pull(int tagId, const ConfigKey& configKey, const int64_t eventTimeNs, vector>* data, bool useUids) { std::lock_guard _l(mLock); - return PullLocked(tagId, configKey, data, useUids); + return PullLocked(tagId, configKey, eventTimeNs, data, useUids); } -bool StatsPullerManager::Pull(int tagId, const vector& uids, +bool StatsPullerManager::Pull(int tagId, const vector& uids, const int64_t eventTimeNs, vector>* data, bool useUids) { std::lock_guard _l(mLock); - return PullLocked(tagId, uids, data, useUids); + return PullLocked(tagId, uids, eventTimeNs, data, useUids); } bool StatsPullerManager::PullLocked(int tagId, const ConfigKey& configKey, - vector>* data, bool useUids) { + const int64_t eventTimeNs, vector>* data, + bool useUids) { vector uids; if (useUids) { auto uidProviderIt = mPullUidProviders.find(configKey); @@ -123,18 +124,19 @@ bool StatsPullerManager::PullLocked(int tagId, const ConfigKey& configKey, } uids = pullUidProvider->getPullAtomUids(tagId); } - return PullLocked(tagId, uids, data, useUids); + return PullLocked(tagId, uids, eventTimeNs, data, useUids); } bool StatsPullerManager::PullLocked(int tagId, const vector& uids, - vector>* data, bool useUids) { + const int64_t eventTimeNs, vector>* data, + bool useUids) { VLOG("Initiating pulling %d", tagId); if (useUids) { for (int32_t uid : uids) { PullerKey key = {.atomTag = tagId, .uid = uid}; auto pullerIt = kAllPullAtomInfo.find(key); if (pullerIt != kAllPullAtomInfo.end()) { - bool ret = pullerIt->second->Pull(data); + bool ret = pullerIt->second->Pull(eventTimeNs, data); VLOG("pulled %zu items", data->size()); if (!ret) { StatsdStats::getInstance().notePullFailed(tagId); @@ -149,7 +151,7 @@ bool StatsPullerManager::PullLocked(int tagId, const vector& uids, PullerKey key = {.atomTag = tagId, .uid = -1}; auto pullerIt = kAllPullAtomInfo.find(key); if (pullerIt != kAllPullAtomInfo.end()) { - bool ret = pullerIt->second->Pull(data); + bool ret = pullerIt->second->Pull(eventTimeNs, data); VLOG("pulled %zu items", data->size()); if (!ret) { StatsdStats::getInstance().notePullFailed(tagId); @@ -290,7 +292,8 @@ void StatsPullerManager::OnAlarmFired(int64_t elapsedTimeNs) { } for (const auto& pullInfo : needToPull) { vector> data; - bool pullSuccess = PullLocked(pullInfo.first->atomTag, pullInfo.first->configKey, &data); + bool pullSuccess = PullLocked(pullInfo.first->atomTag, pullInfo.first->configKey, + elapsedTimeNs, &data); if (!pullSuccess) { VLOG("pull failed at %lld, will try again later", (long long)elapsedTimeNs); } diff --git a/cmds/statsd/src/external/StatsPullerManager.h b/cmds/statsd/src/external/StatsPullerManager.h index 5e18aaa6ed610..194a0f5edba85 100644 --- a/cmds/statsd/src/external/StatsPullerManager.h +++ b/cmds/statsd/src/external/StatsPullerManager.h @@ -101,11 +101,11 @@ public: // registered for any of the uids for this atom. // If the metric wants to make any change to the data, like timestamps, they // should make a copy as this data may be shared with multiple metrics. - virtual bool Pull(int tagId, const ConfigKey& configKey, + virtual bool Pull(int tagId, const ConfigKey& configKey, const int64_t eventTimeNs, vector>* data, bool useUids = true); // Same as above, but directly specify the allowed uids to pull from. - virtual bool Pull(int tagId, const vector& uids, + virtual bool Pull(int tagId, const vector& uids, const int64_t eventTimeNs, vector>* data, bool useUids = true); // Clear pull data cache immediately. @@ -152,11 +152,11 @@ private: // mapping from Config Key to the PullUidProvider for that config std::map> mPullUidProviders; - bool PullLocked(int tagId, const ConfigKey& configKey, vector>* data, - bool useUids = true); + bool PullLocked(int tagId, const ConfigKey& configKey, const int64_t eventTimeNs, + vector>* data, bool useUids = true); - bool PullLocked(int tagId, const vector& uids, vector>* data, - bool useUids); + bool PullLocked(int tagId, const vector& uids, const int64_t eventTimeNs, + vector>* data, bool useUids); // locks for data receiver and StatsCompanionService changes std::mutex mLock; diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp index cc4c56537c4c6..1d4d0b3a5e5d8 100644 --- a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp +++ b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp @@ -321,7 +321,7 @@ void GaugeMetricProducer::pullAndMatchEventsLocked(const int64_t timestampNs) { return; } vector> allData; - if (!mPullerManager->Pull(mPullTagId, mConfigKey, &allData)) { + if (!mPullerManager->Pull(mPullTagId, mConfigKey, timestampNs, &allData)) { ALOGE("Gauge Stats puller failed for tag: %d at %lld", mPullTagId, (long long)timestampNs); return; } diff --git a/cmds/statsd/src/metrics/ValueMetricProducer.cpp b/cmds/statsd/src/metrics/ValueMetricProducer.cpp index e5ec72e3d0f50..bf636a4f048d6 100644 --- a/cmds/statsd/src/metrics/ValueMetricProducer.cpp +++ b/cmds/statsd/src/metrics/ValueMetricProducer.cpp @@ -508,7 +508,7 @@ void ValueMetricProducer::prepareFirstBucketLocked() { void ValueMetricProducer::pullAndMatchEventsLocked(const int64_t timestampNs) { vector> allData; - if (!mPullerManager->Pull(mPullTagId, mConfigKey, &allData)) { + if (!mPullerManager->Pull(mPullTagId, mConfigKey, timestampNs, &allData)) { ALOGE("Stats puller failed for tag: %d at %lld", mPullTagId, (long long)timestampNs); invalidateCurrentBucket(timestampNs, BucketDropReason::PULL_FAILED); return; diff --git a/cmds/statsd/src/shell/ShellSubscriber.cpp b/cmds/statsd/src/shell/ShellSubscriber.cpp index 7b687210ce33b..361b161c76ac0 100644 --- a/cmds/statsd/src/shell/ShellSubscriber.cpp +++ b/cmds/statsd/src/shell/ShellSubscriber.cpp @@ -152,6 +152,7 @@ void ShellSubscriber::startPull(int myToken) { } int64_t nowMillis = getElapsedRealtimeMillis(); + int64_t nowNanos = getElapsedRealtimeNs(); for (PullInfo& pullInfo : mSubscriptionInfo->mPulledInfo) { if (pullInfo.mPrevPullElapsedRealtimeMs + pullInfo.mInterval >= nowMillis) { continue; @@ -161,7 +162,7 @@ void ShellSubscriber::startPull(int myToken) { getUidsForPullAtom(&uids, pullInfo); vector> data; - mPullerMgr->Pull(pullInfo.mPullerMatcher.atom_id(), uids, &data); + mPullerMgr->Pull(pullInfo.mPullerMatcher.atom_id(), uids, nowNanos, &data); VLOG("Pulled %zu atoms with id %d", data.size(), pullInfo.mPullerMatcher.atom_id()); writePulledAtomsLocked(data, pullInfo.mPullerMatcher); diff --git a/cmds/statsd/tests/external/StatsCallbackPuller_test.cpp b/cmds/statsd/tests/external/StatsCallbackPuller_test.cpp index e37c72ed0ee30..13cdfc292d490 100644 --- a/cmds/statsd/tests/external/StatsCallbackPuller_test.cpp +++ b/cmds/statsd/tests/external/StatsCallbackPuller_test.cpp @@ -155,7 +155,7 @@ TEST_F(StatsCallbackPullerTest, PullFail) { TEST_F(StatsCallbackPullerTest, PullTimeout) { shared_ptr cb = SharedRefBase::make(); pullSuccess = true; - pullDelayNs = 500000000; // 500ms. + pullDelayNs = MillisToNano(5); // 5ms. pullTimeoutNs = 10000; // 10 microseconds. int64_t value = 4321; values.push_back(value); @@ -184,7 +184,7 @@ TEST_F(StatsCallbackPullerTest, PullTimeout) { TEST_F(StatsCallbackPullerTest, RegisterAndTimeout) { shared_ptr cb = SharedRefBase::make(); pullSuccess = true; - pullDelayNs = 500000000; // 500 ms. + pullDelayNs = MillisToNano(5); // 5 ms. pullTimeoutNs = 10000; // 10 microsseconds. int64_t value = 4321; int32_t uid = 123; @@ -196,7 +196,7 @@ TEST_F(StatsCallbackPullerTest, RegisterAndTimeout) { vector> dataHolder; int64_t startTimeNs = getElapsedRealtimeNs(); // Returns false, since StatsPuller code will evaluate the timeout. - EXPECT_FALSE(pullerManager->Pull(pullTagId, {uid}, &dataHolder)); + EXPECT_FALSE(pullerManager->Pull(pullTagId, {uid}, startTimeNs, &dataHolder)); int64_t endTimeNs = getElapsedRealtimeNs(); int64_t actualPullDurationNs = endTimeNs - startTimeNs; diff --git a/cmds/statsd/tests/external/StatsPullerManager_test.cpp b/cmds/statsd/tests/external/StatsPullerManager_test.cpp index 6b3f4cccb95be..c76e85ec75e64 100644 --- a/cmds/statsd/tests/external/StatsPullerManager_test.cpp +++ b/cmds/statsd/tests/external/StatsPullerManager_test.cpp @@ -101,14 +101,14 @@ TEST(StatsPullerManagerTest, TestPullInvalidUid) { sp pullerManager = createPullerManagerAndRegister(); vector> data; - EXPECT_FALSE(pullerManager->Pull(pullTagId1, {unregisteredUid}, &data, true)); + EXPECT_FALSE(pullerManager->Pull(pullTagId1, {unregisteredUid}, /*timestamp =*/1, &data, true)); } TEST(StatsPullerManagerTest, TestPullChoosesCorrectUid) { sp pullerManager = createPullerManagerAndRegister(); vector> data; - EXPECT_TRUE(pullerManager->Pull(pullTagId1, {uid1}, &data, true)); + EXPECT_TRUE(pullerManager->Pull(pullTagId1, {uid1}, /*timestamp =*/1, &data, true)); ASSERT_EQ(data.size(), 1); EXPECT_EQ(data[0]->GetTagId(), pullTagId1); ASSERT_EQ(data[0]->getValues().size(), 1); @@ -121,7 +121,7 @@ TEST(StatsPullerManagerTest, TestPullInvalidConfigKey) { pullerManager->RegisterPullUidProvider(configKey, uidProvider); vector> data; - EXPECT_FALSE(pullerManager->Pull(pullTagId1, badConfigKey, &data, true)); + EXPECT_FALSE(pullerManager->Pull(pullTagId1, badConfigKey, /*timestamp =*/1, &data, true)); } TEST(StatsPullerManagerTest, TestPullConfigKeyGood) { @@ -130,7 +130,7 @@ TEST(StatsPullerManagerTest, TestPullConfigKeyGood) { pullerManager->RegisterPullUidProvider(configKey, uidProvider); vector> data; - EXPECT_TRUE(pullerManager->Pull(pullTagId1, configKey, &data, true)); + EXPECT_TRUE(pullerManager->Pull(pullTagId1, configKey, /*timestamp =*/1, &data, true)); EXPECT_EQ(data[0]->GetTagId(), pullTagId1); ASSERT_EQ(data[0]->getValues().size(), 1); EXPECT_EQ(data[0]->getValues()[0].mValue.int_value, uid2); @@ -142,7 +142,7 @@ TEST(StatsPullerManagerTest, TestPullConfigKeyNoPullerWithUid) { pullerManager->RegisterPullUidProvider(configKey, uidProvider); vector> data; - EXPECT_FALSE(pullerManager->Pull(pullTagId2, configKey, &data, true)); + EXPECT_FALSE(pullerManager->Pull(pullTagId2, configKey, /*timestamp =*/1, &data, true)); } } // namespace statsd diff --git a/cmds/statsd/tests/external/StatsPuller_test.cpp b/cmds/statsd/tests/external/StatsPuller_test.cpp index 02a43e4e179a9..55a90365e1511 100644 --- a/cmds/statsd/tests/external/StatsPuller_test.cpp +++ b/cmds/statsd/tests/external/StatsPuller_test.cpp @@ -39,7 +39,6 @@ using std::this_thread::sleep_for; using testing::Contains; namespace { -// cooldown time 1sec. int pullTagId = 10014; bool pullSuccess; @@ -48,7 +47,8 @@ long pullDelayNs; class FakePuller : public StatsPuller { public: - FakePuller() : StatsPuller(pullTagId, /*coolDown=*/NS_PER_SEC, /*timeout=*/NS_PER_SEC / 2){}; + FakePuller() + : StatsPuller(pullTagId, /*coolDownNs=*/MillisToNano(10), /*timeoutNs=*/MillisToNano(5)){}; private: bool PullInternal(vector>* data) override { @@ -92,21 +92,21 @@ TEST_F(StatsPullerTest, PullSuccess) { pullSuccess = true; vector> dataHolder; - EXPECT_TRUE(puller.Pull(&dataHolder)); + EXPECT_TRUE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(1, dataHolder.size()); EXPECT_EQ(pullTagId, dataHolder[0]->GetTagId()); EXPECT_EQ(1111L, dataHolder[0]->GetElapsedTimestampNs()); ASSERT_EQ(1, dataHolder[0]->size()); EXPECT_EQ(33, dataHolder[0]->getValues()[0].mValue.int_value); - sleep_for(std::chrono::seconds(1)); + sleep_for(std::chrono::milliseconds(11)); pullData.clear(); pullData.push_back(createSimpleEvent(2222L, 44)); pullSuccess = true; - EXPECT_TRUE(puller.Pull(&dataHolder)); + EXPECT_TRUE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(1, dataHolder.size()); EXPECT_EQ(pullTagId, dataHolder[0]->GetTagId()); EXPECT_EQ(2222L, dataHolder[0]->GetElapsedTimestampNs()); @@ -120,26 +120,27 @@ TEST_F(StatsPullerTest, PullFailAfterSuccess) { pullSuccess = true; vector> dataHolder; - EXPECT_TRUE(puller.Pull(&dataHolder)); + EXPECT_TRUE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(1, dataHolder.size()); EXPECT_EQ(pullTagId, dataHolder[0]->GetTagId()); EXPECT_EQ(1111L, dataHolder[0]->GetElapsedTimestampNs()); ASSERT_EQ(1, dataHolder[0]->size()); EXPECT_EQ(33, dataHolder[0]->getValues()[0].mValue.int_value); - sleep_for(std::chrono::seconds(1)); + sleep_for(std::chrono::milliseconds(11)); pullData.clear(); pullData.push_back(createSimpleEvent(2222L, 44)); pullSuccess = false; dataHolder.clear(); - EXPECT_FALSE(puller.Pull(&dataHolder)); + EXPECT_FALSE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(0, dataHolder.size()); + // Fails due to hitting the cool down. pullSuccess = true; dataHolder.clear(); - EXPECT_FALSE(puller.Pull(&dataHolder)); + EXPECT_FALSE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(0, dataHolder.size()); } @@ -147,19 +148,20 @@ TEST_F(StatsPullerTest, PullFailAfterSuccess) { TEST_F(StatsPullerTest, PullTakeTooLongAndPullFast) { pullData.push_back(createSimpleEvent(1111L, 33)); pullSuccess = true; - // timeout is 0.5 - pullDelayNs = (long)(0.8 * NS_PER_SEC); + // timeout is 5ms + pullDelayNs = MillisToNano(6); vector> dataHolder; - EXPECT_FALSE(puller.Pull(&dataHolder)); + EXPECT_FALSE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(0, dataHolder.size()); pullData.clear(); pullData.push_back(createSimpleEvent(2222L, 44)); + pullDelayNs = 0; pullSuccess = true; dataHolder.clear(); - EXPECT_FALSE(puller.Pull(&dataHolder)); + EXPECT_FALSE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(0, dataHolder.size()); } @@ -169,7 +171,7 @@ TEST_F(StatsPullerTest, PullFail) { pullSuccess = false; vector> dataHolder; - EXPECT_FALSE(puller.Pull(&dataHolder)); + EXPECT_FALSE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(0, dataHolder.size()); } @@ -177,10 +179,10 @@ TEST_F(StatsPullerTest, PullTakeTooLong) { pullData.push_back(createSimpleEvent(1111L, 33)); pullSuccess = true; - pullDelayNs = NS_PER_SEC; + pullDelayNs = MillisToNano(6); vector> dataHolder; - EXPECT_FALSE(puller.Pull(&dataHolder)); + EXPECT_FALSE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(0, dataHolder.size()); } @@ -190,7 +192,7 @@ TEST_F(StatsPullerTest, PullTooFast) { pullSuccess = true; vector> dataHolder; - EXPECT_TRUE(puller.Pull(&dataHolder)); + EXPECT_TRUE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(1, dataHolder.size()); EXPECT_EQ(pullTagId, dataHolder[0]->GetTagId()); EXPECT_EQ(1111L, dataHolder[0]->GetElapsedTimestampNs()); @@ -203,7 +205,7 @@ TEST_F(StatsPullerTest, PullTooFast) { pullSuccess = true; dataHolder.clear(); - EXPECT_TRUE(puller.Pull(&dataHolder)); + EXPECT_TRUE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(1, dataHolder.size()); EXPECT_EQ(pullTagId, dataHolder[0]->GetTagId()); EXPECT_EQ(1111L, dataHolder[0]->GetElapsedTimestampNs()); @@ -217,7 +219,7 @@ TEST_F(StatsPullerTest, PullFailsAndTooFast) { pullSuccess = false; vector> dataHolder; - EXPECT_FALSE(puller.Pull(&dataHolder)); + EXPECT_FALSE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); ASSERT_EQ(0, dataHolder.size()); pullData.clear(); @@ -225,7 +227,84 @@ TEST_F(StatsPullerTest, PullFailsAndTooFast) { pullSuccess = true; - EXPECT_FALSE(puller.Pull(&dataHolder)); + EXPECT_FALSE(puller.Pull(getElapsedRealtimeNs(), &dataHolder)); + ASSERT_EQ(0, dataHolder.size()); +} + +TEST_F(StatsPullerTest, PullSameEventTime) { + pullData.push_back(createSimpleEvent(1111L, 33)); + + pullSuccess = true; + int64_t eventTimeNs = getElapsedRealtimeNs(); + + vector> dataHolder; + EXPECT_TRUE(puller.Pull(eventTimeNs, &dataHolder)); + ASSERT_EQ(1, dataHolder.size()); + EXPECT_EQ(pullTagId, dataHolder[0]->GetTagId()); + EXPECT_EQ(1111L, dataHolder[0]->GetElapsedTimestampNs()); + ASSERT_EQ(1, dataHolder[0]->size()); + EXPECT_EQ(33, dataHolder[0]->getValues()[0].mValue.int_value); + + pullData.clear(); + pullData.push_back(createSimpleEvent(2222L, 44)); + + // Sleep to ensure the cool down expires. + sleep_for(std::chrono::milliseconds(11)); + pullSuccess = true; + + dataHolder.clear(); + EXPECT_TRUE(puller.Pull(eventTimeNs, &dataHolder)); + ASSERT_EQ(1, dataHolder.size()); + EXPECT_EQ(pullTagId, dataHolder[0]->GetTagId()); + EXPECT_EQ(1111L, dataHolder[0]->GetElapsedTimestampNs()); + ASSERT_EQ(1, dataHolder[0]->size()); + EXPECT_EQ(33, dataHolder[0]->getValues()[0].mValue.int_value); +} + +// Test pull takes longer than timeout, 2nd pull happens at same event time +TEST_F(StatsPullerTest, PullTakeTooLongAndPullSameEventTime) { + pullData.push_back(createSimpleEvent(1111L, 33)); + pullSuccess = true; + int64_t eventTimeNs = getElapsedRealtimeNs(); + // timeout is 5ms + pullDelayNs = MillisToNano(6); + + vector> dataHolder; + EXPECT_FALSE(puller.Pull(eventTimeNs, &dataHolder)); + ASSERT_EQ(0, dataHolder.size()); + + // Sleep to ensure the cool down expires. 6ms is taken by the delay, so only 5 is needed here. + sleep_for(std::chrono::milliseconds(5)); + + pullData.clear(); + pullData.push_back(createSimpleEvent(2222L, 44)); + pullDelayNs = 0; + + pullSuccess = true; + dataHolder.clear(); + EXPECT_FALSE(puller.Pull(eventTimeNs, &dataHolder)); + ASSERT_EQ(0, dataHolder.size()); +} + +TEST_F(StatsPullerTest, PullFailsAndPullSameEventTime) { + pullData.push_back(createSimpleEvent(1111L, 33)); + + pullSuccess = false; + int64_t eventTimeNs = getElapsedRealtimeNs(); + + vector> dataHolder; + EXPECT_FALSE(puller.Pull(eventTimeNs, &dataHolder)); + ASSERT_EQ(0, dataHolder.size()); + + // Sleep to ensure the cool down expires. + sleep_for(std::chrono::milliseconds(11)); + + pullData.clear(); + pullData.push_back(createSimpleEvent(2222L, 44)); + + pullSuccess = true; + + EXPECT_FALSE(puller.Pull(eventTimeNs, &dataHolder)); ASSERT_EQ(0, dataHolder.size()); } diff --git a/cmds/statsd/tests/metrics/GaugeMetricProducer_test.cpp b/cmds/statsd/tests/metrics/GaugeMetricProducer_test.cpp index 12839e6d1fbe1..cc5f45922d452 100644 --- a/cmds/statsd/tests/metrics/GaugeMetricProducer_test.cpp +++ b/cmds/statsd/tests/metrics/GaugeMetricProducer_test.cpp @@ -138,11 +138,12 @@ TEST(GaugeMetricProducerTest, TestPulledEventsNoCondition) { sp pullerManager = new StrictMock(); EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs); data->clear(); - data->push_back(makeLogEvent(tagId, bucketStartTimeNs + 10, 3, "some value", 11)); + data->push_back(makeLogEvent(tagId, eventTimeNs + 10, 3, "some value", 11)); return true; })); @@ -311,15 +312,15 @@ TEST_P(GaugeMetricProducerTest_PartialBucket, TestPulled) { sp pullerManager = new StrictMock(); EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) .WillOnce(Return(false)) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back( - CreateRepeatedValueLogEvent(tagId, partialBucketSplitTimeNs, 2)); - return true; - })); + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, partialBucketSplitTimeNs); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, eventTimeNs, 2)); + return true; + })); GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId, @@ -389,7 +390,8 @@ TEST(GaugeMetricProducerTest, TestPulledWithAppUpgradeDisabled) { sp pullerManager = new StrictMock(); EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)).WillOnce(Return(false)); + 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, @@ -435,14 +437,16 @@ TEST(GaugeMetricProducerTest, TestPulledEventsWithCondition) { new EventMatcherWizard({new SimpleLogMatchingTracker( atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)}); + int64_t conditionChangeNs = bucketStartTimeNs + 8; + sp pullerManager = new StrictMock(); EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, conditionChangeNs, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 10, 100)); + data->push_back(CreateRepeatedValueLogEvent(tagId, eventTimeNs + 10, 100)); return true; })); @@ -451,7 +455,7 @@ TEST(GaugeMetricProducerTest, TestPulledEventsWithCondition) { bucketStartTimeNs, pullerManager); gaugeProducer.prepareFirstBucket(); - gaugeProducer.onConditionChanged(true, bucketStartTimeNs + 8); + gaugeProducer.onConditionChanged(true, conditionChangeNs); ASSERT_EQ(1UL, gaugeProducer.mCurrentSlicedBucket->size()); EXPECT_EQ(100, gaugeProducer.mCurrentSlicedBucket->begin() ->second.front() @@ -519,14 +523,16 @@ TEST(GaugeMetricProducerTest, TestPulledEventsWithSlicedCondition) { return ConditionState::kTrue; })); + int64_t sliceConditionChangeNs = bucketStartTimeNs + 8; + sp pullerManager = new StrictMock(); EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, sliceConditionChangeNs, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { data->clear(); - data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs + 10, 1000, 100)); + data->push_back(CreateTwoValueLogEvent(tagId, eventTimeNs + 10, 1000, 100)); return true; })); @@ -535,7 +541,7 @@ TEST(GaugeMetricProducerTest, TestPulledEventsWithSlicedCondition) { bucketStartTimeNs, pullerManager); gaugeProducer.prepareFirstBucket(); - gaugeProducer.onSlicedConditionMayChange(true, bucketStartTimeNs + 8); + gaugeProducer.onSlicedConditionMayChange(true, sliceConditionChangeNs); ASSERT_EQ(1UL, gaugeProducer.mCurrentSlicedBucket->size()); const auto& key = gaugeProducer.mCurrentSlicedBucket->begin()->first; @@ -560,7 +566,8 @@ TEST(GaugeMetricProducerTest, TestPulledEventsAnomalyDetection) { sp pullerManager = new StrictMock(); EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)).WillOnce(Return(false)); + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Return(false)); GaugeMetric metric; metric.set_id(metricId); @@ -658,17 +665,19 @@ TEST(GaugeMetricProducerTest, TestPullOnTrigger) { atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)}); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 10, 4)); + data->push_back(CreateRepeatedValueLogEvent(tagId, eventTimeNs, 4)); return true; })) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 20); data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 20, 5)); + data->push_back(CreateRepeatedValueLogEvent(tagId, eventTimeNs, 5)); return true; })) .WillOnce(Return(true)); @@ -727,23 +736,26 @@ TEST(GaugeMetricProducerTest, TestRemoveDimensionInOutput) { atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)}); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs + 3, 3, 4)); - return true; - })) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 3); data->clear(); - data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs + 10, 4, 5)); + data->push_back(CreateTwoValueLogEvent(tagId, eventTimeNs, 3, 4)); return true; })) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); data->clear(); - data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs + 20, 4, 6)); + data->push_back(CreateTwoValueLogEvent(tagId, eventTimeNs, 4, 5)); + return true; + })) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 20); + data->clear(); + data->push_back(CreateTwoValueLogEvent(tagId, eventTimeNs, 4, 6)); return true; })) .WillOnce(Return(true)); @@ -801,14 +813,14 @@ TEST(GaugeMetricProducerTest_BucketDrop, TestBucketDropWhenBucketTooSmall) { atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)}); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs + 3, _, _)) // Bucket start. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 10)); - return true; - })); + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, eventTimeNs, 10)); + return true; + })); int triggerId = 5; GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, diff --git a/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp b/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp index be1b9ebb557c8..b6e1075bcb727 100644 --- a/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp +++ b/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp @@ -278,13 +278,13 @@ TEST(ValueMetricProducerTest, TestFirstBucket) { TEST(ValueMetricProducerTest, TestPulledEventsNoCondition) { ValueMetric metric = ValueMetricProducerTestHelper::createMetric(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); - return true; - })); + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, + vector>* data, bool) { + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerNoConditions(pullerManager, metric); @@ -352,18 +352,20 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPartialBucketCreated) { ValueMetric metric = ValueMetricProducerTestHelper::createMetric(); sp pullerManager = new StrictMock(); int64_t partialBucketSplitTimeNs = bucket2StartTimeNs + 2; - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // Initialize bucket. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 1, 1)); return true; })) // Partial bucket. - .WillOnce(Invoke([partialBucketSplitTimeNs](int tagId, const ConfigKey&, - vector>* data, - bool) { + .WillOnce(Invoke([partialBucketSplitTimeNs]( + int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, partialBucketSplitTimeNs); data->clear(); data->push_back( CreateRepeatedValueLogEvent(tagId, partialBucketSplitTimeNs + 8, 5)); @@ -416,13 +418,13 @@ TEST(ValueMetricProducerTest, TestPulledEventsWithFiltering) { sp pullerManager = new StrictMock(); EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs, 3, 3)); - return true; - })); + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, + vector>* data, bool) { + data->clear(); + data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs, 3, 3)); + return true; + })); sp valueProducer = new ValueMetricProducer( kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, logEventMatcherIndex, @@ -487,7 +489,8 @@ TEST(ValueMetricProducerTest, TestPulledEventsTakeAbsoluteValueOnReset) { metric.set_use_absolute_value_on_reset(true); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)).WillOnce(Return(true)); + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Return(true)); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerNoConditions(pullerManager, metric); @@ -546,7 +549,8 @@ TEST(ValueMetricProducerTest, TestPulledEventsTakeAbsoluteValueOnReset) { TEST(ValueMetricProducerTest, TestPulledEventsTakeZeroOnReset) { ValueMetric metric = ValueMetricProducerTestHelper::createMetric(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)).WillOnce(Return(false)); + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Return(false)); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerNoConditions(pullerManager, metric); @@ -601,21 +605,24 @@ TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition) { sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 8); // First condition change. data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 100)); return true; })) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 1); // Second condition change. data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs + 1, 130)); return true; })) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket3StartTimeNs + 1); // Third condition change. data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucket3StartTimeNs + 1, 180)); return true; @@ -745,11 +752,12 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValue) { int64_t partialBucketSplitTimeNs = bucket2StartTimeNs + 150; EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) .WillOnce(Return(true)) - .WillOnce(Invoke([partialBucketSplitTimeNs](int tagId, const ConfigKey&, - vector>* data, - bool) { + .WillOnce(Invoke([partialBucketSplitTimeNs]( + int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, partialBucketSplitTimeNs); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, partialBucketSplitTimeNs, 120)); return true; @@ -803,7 +811,8 @@ TEST(ValueMetricProducerTest, TestPulledWithAppUpgradeDisabled) { sp pullerManager = new StrictMock(); EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)).WillOnce(Return(true)); + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Return(true)); ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager); @@ -825,15 +834,18 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValueWhileConditionFalse ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 1); // Condition change to true time. data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 1, 100)); return true; })) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, + bucket2StartTimeNs - 100); // Condition change to false time. data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs - 100, 120)); return true; @@ -1049,7 +1061,8 @@ TEST(ValueMetricProducerTest, TestAnomalyDetection) { TEST(ValueMetricProducerTest, TestBucketBoundaryNoCondition) { ValueMetric metric = ValueMetricProducerTestHelper::createMetric(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)).WillOnce(Return(true)); + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Return(true)); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerNoConditions(pullerManager, metric); @@ -1119,17 +1132,19 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // condition becomes true - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 8); // First condition change. data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 100)); return true; })) // condition becomes false - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 1); // Second condition change. data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs + 1, 120)); return true; @@ -1179,24 +1194,27 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition2) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // condition becomes true - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 8); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 100)); return true; })) // condition becomes false - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 1); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs + 1, 120)); return true; })) // condition becomes true again - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 25); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs + 25, 130)); return true; @@ -1625,13 +1643,13 @@ TEST(ValueMetricProducerTest, TestUseZeroDefaultBase) { metric.set_use_zero_default_base(true); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs, 1, 3)); - return true; - })); + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, + vector>* data, bool) { + data->clear(); + data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs, 1, 3)); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerNoConditions(pullerManager, metric); @@ -1701,13 +1719,13 @@ TEST(ValueMetricProducerTest, TestUseZeroDefaultBaseWithPullFailures) { metric.set_use_zero_default_base(true); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs, 1, 3)); - return true; - })); + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, + vector>* data, bool) { + data->clear(); + data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs, 1, 3)); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerNoConditions(pullerManager, metric); @@ -1806,13 +1824,13 @@ TEST(ValueMetricProducerTest, TestTrimUnusedDimensionKey) { metric.mutable_dimensions_in_what()->add_child()->set_field(1); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs, 1, 3)); - return true; - })); + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, + vector>* data, bool) { + data->clear(); + data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs, 1, 3)); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerNoConditions(pullerManager, metric); @@ -1909,8 +1927,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailAfterConditionChange_EndOfB sp pullerManager = new StrictMock(); // Used by onConditionChanged. - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs + 8, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, vector>* data, bool) { data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 100)); @@ -1942,9 +1960,10 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailAfterConditionChange) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 8); // Condition change to true. data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 100)); return true; @@ -1979,15 +1998,17 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailBeforeConditionChange) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 50)); - return false; - })) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 50)); + return false; + })) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 1); // Condition change to false. data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 100)); return true; @@ -2019,8 +2040,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullDelayExceeded) { metric.set_max_pull_delay_sec(0); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs + 1, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, vector>* data, bool) { data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 1, 120)); @@ -2067,8 +2088,8 @@ TEST(ValueMetricProducerTest, TestBaseSetOnConditionChange) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs + 1, _, _)) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, vector>* data, bool) { data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 1, 100)); @@ -2100,12 +2121,13 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenOneConditionFailed ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // First onConditionChanged .WillOnce(Return(false)) // Second onConditionChanged - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 3); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 130)); return true; @@ -2177,9 +2199,9 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenGuardRailHit) { metric.set_condition(StringToId("SCREEN_ON")); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs + 2, _, _)) // First onConditionChanged - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, vector>* data, bool) { for (int i = 0; i < 2000; i++) { data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 1, i)); @@ -2234,17 +2256,19 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenInitialPullFailed) ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // First onConditionChanged - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 2); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 120)); return true; })) // Second onConditionChanged - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 3); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 130)); return true; @@ -2312,17 +2336,19 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenLastPullFailed) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // First onConditionChanged - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 2); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 120)); return true; })) // Second onConditionChanged - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 3); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 8, 130)); return true; @@ -2384,14 +2410,14 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenLastPullFailed) { TEST(ValueMetricProducerTest, TestEmptyDataResetsBase_onDataPulled) { ValueMetric metric = ValueMetricProducerTestHelper::createMetric(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) // Start bucket. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); - return true; - })); + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, + vector>* data, bool) { + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerNoConditions(pullerManager, metric); @@ -2417,19 +2443,21 @@ TEST(ValueMetricProducerTest, TestEmptyDataResetsBase_onConditionChanged) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // First onConditionChanged - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); - return true; - })) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - return true; - })); + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); + return true; + })) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); + data->clear(); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); @@ -2457,26 +2485,29 @@ TEST(ValueMetricProducerTest, TestEmptyDataResetsBase_onBucketBoundary) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // First onConditionChanged - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); - return true; - })) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 2)); - return true; - })) - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 5)); - return true; - })); + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); + return true; + })) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 11); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 2)); + return true; + })) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 12); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 5)); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); @@ -2517,14 +2548,14 @@ TEST(ValueMetricProducerTest, TestPartialResetOnBucketBoundaries) { metric.set_condition(StringToId("SCREEN_ON")); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs + 10, _, _)) // First onConditionChanged - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); - return true; - })); + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, + vector>* data, bool) { + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); @@ -2559,18 +2590,20 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestFullBucketResetWhenLastBucketI sp pullerManager = new StrictMock(); int64_t partialBucketSplitTimeNs = bucketStartTimeNs + bucketSizeNs / 2; - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // Initialization. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); - return true; - })) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); + return true; + })) // notifyAppUpgrade. - .WillOnce(Invoke([partialBucketSplitTimeNs](int tagId, const ConfigKey&, - vector>* data, - bool) { + .WillOnce(Invoke([partialBucketSplitTimeNs]( + int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, partialBucketSplitTimeNs); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, partialBucketSplitTimeNs, 10)); return true; @@ -2609,17 +2642,19 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestFullBucketResetWhenLastBucketI TEST(ValueMetricProducerTest, TestBucketBoundariesOnConditionChange) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // Second onConditionChanged. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 10); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs + 10, 5)); return true; })) // Third onConditionChanged. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket3StartTimeNs + 10); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucket3StartTimeNs + 10, 7)); return true; @@ -2678,14 +2713,14 @@ TEST(ValueMetricProducerTest, TestLateOnDataPulledWithDiff) { ValueMetric metric = ValueMetricProducerTestHelper::createMetric(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) // Initialization. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); - return true; - })); + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, + vector>* data, bool) { + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerNoConditions(pullerManager, metric); @@ -2708,18 +2743,20 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestBucketBoundariesOnPartialBucke int64_t partialBucketSplitTimeNs = bucket2StartTimeNs + 2; sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // Initialization. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); - return true; - })) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); + return true; + })) // notifyAppUpgrade. - .WillOnce(Invoke([partialBucketSplitTimeNs](int tagId, const ConfigKey&, - vector>* data, - bool) { + .WillOnce(Invoke([partialBucketSplitTimeNs]( + int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, partialBucketSplitTimeNs); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, partialBucketSplitTimeNs, 10)); return true; @@ -2746,21 +2783,23 @@ TEST(ValueMetricProducerTest, TestDataIsNotUpdatedWhenNoConditionChanged) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // First on condition changed. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); - return true; - })) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 8); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); + return true; + })) // Second on condition changed. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); - return true; - })); + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); @@ -2788,28 +2827,31 @@ TEST(ValueMetricProducerTest, TestBucketInvalidIfGlobalBaseIsNotSet) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // First condition change. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); - return true; - })) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 10); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 1)); + return true; + })) // 2nd condition change. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs, 1)); - return true; - })) + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 8); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs, 1)); + return true; + })) // 3rd condition change. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs, 1)); - return true; - })); + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 10); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs, 1)); + return true; + })); sp valueProducer = ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric); @@ -2848,9 +2890,9 @@ TEST(ValueMetricProducerTest, TestPullNeededFastDump) { EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillRepeatedly(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) // Initial pull. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, vector>* data, bool) { data->clear(); data->push_back(CreateThreeValueLogEvent(tagId, bucketStartTimeNs, tagId, 1, 1)); @@ -2886,9 +2928,9 @@ TEST(ValueMetricProducerTest, TestFastDumpWithoutCurrentBucket) { EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillRepeatedly(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _)) // Initial pull. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, vector>* data, bool) { data->clear(); data->push_back(CreateThreeValueLogEvent(tagId, bucketStartTimeNs, tagId, 1, 1)); @@ -2930,16 +2972,18 @@ TEST(ValueMetricProducerTest, TestPullNeededNoTimeConstraints) { EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return()); EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillRepeatedly(Return()); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // Initial pull. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs); data->clear(); data->push_back(CreateThreeValueLogEvent(tagId, bucketStartTimeNs, tagId, 1, 1)); return true; })) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); data->clear(); data->push_back( CreateThreeValueLogEvent(tagId, bucketStartTimeNs + 10, tagId, 3, 3)); @@ -2984,17 +3028,19 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_withMultipleConditionChanges metric.set_use_diff(false); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // condition becomes true - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 8); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 30, 10)); return true; })) // condition becomes false - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 50); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 50, 20)); return true; @@ -3032,9 +3078,9 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_bucketBoundaryTrue) { metric.set_use_diff(false); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs + 8, _, _)) // condition becomes true - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, vector>* data, bool) { data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 30, 10)); @@ -3083,10 +3129,11 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_withFailure) { metric.set_use_diff(false); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // condition becomes true - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 8); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 30, 10)); return true; @@ -3122,9 +3169,9 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenDumpReportRequeste ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs + 20, _, _)) // Condition change to true. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, vector>* data, bool) { data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 20, 10)); @@ -3167,9 +3214,9 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenConditionEventWron ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs + 50, _, _)) // Condition change to true. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, vector>* data, bool) { data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 50, 10)); @@ -3220,17 +3267,19 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenAccumulateEventWro ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // Condition change to true. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 50); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 50, 10)); return true; })) // Dump report requested. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 100); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucket2StartTimeNs + 100, 15)); return true; @@ -3283,17 +3332,19 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenConditionUnknown) ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // Condition change to true. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 50); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 50, 10)); return true; })) // Dump report requested. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10000); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 100, 15)); return true; @@ -3337,10 +3388,11 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenPullFailed) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // Condition change to true. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 50); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 50, 10)); return true; @@ -3385,17 +3437,19 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenMultipleBucketsSki ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // Condition change to true. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 10, 10)); return true; })) // Dump report requested. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket4StartTimeNs + 10); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucket4StartTimeNs + 1000, 15)); return true; @@ -3441,17 +3495,19 @@ TEST(ValueMetricProducerTest_BucketDrop, TestBucketDropWhenBucketTooSmall) { metric.set_min_bucket_size_nanos(10000000000); // 10 seconds sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // Condition change to true. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 10, 10)); return true; })) // Dump report requested. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 9000000); data->clear(); data->push_back( CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 9000000, 15)); @@ -3494,9 +3550,9 @@ TEST(ValueMetricProducerTest_BucketDrop, TestMultipleBucketDropEvents) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs + 10, _, _)) // Condition change to true. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t, vector>* data, bool) { data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 10, 10)); @@ -3545,10 +3601,11 @@ TEST(ValueMetricProducerTest_BucketDrop, TestMaxBucketDropEvents) { ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithCondition(); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // First condition change event. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); for (int i = 0; i < 2000; i++) { data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 1, i)); } @@ -3563,8 +3620,9 @@ TEST(ValueMetricProducerTest_BucketDrop, TestMaxBucketDropEvents) { .WillOnce(Return(false)) .WillOnce(Return(false)) .WillOnce(Return(false)) - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 220); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 220, 10)); return true; @@ -3662,38 +3720,43 @@ TEST(ValueMetricProducerTest, TestSlicedState) { // Set up ValueMetricProducer. ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithState("SCREEN_STATE"); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // ValueMetricProducer initialized. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); - return true; - })) - // Screen state change to ON. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); + return true; + })) + // Screen state change to ON. + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 5); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 5, 5)); return true; })) // Screen state change to OFF. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 10, 9)); return true; })) // Screen state change to ON. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 15); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 15, 21)); return true; })) // Dump report requested. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 50); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 50, 30)); return true; @@ -3818,38 +3881,43 @@ TEST(ValueMetricProducerTest, TestSlicedStateWithMap) { // Set up ValueMetricProducer. ValueMetric metric = ValueMetricProducerTestHelper::createMetricWithState("SCREEN_STATE_ONOFF"); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // ValueMetricProducer initialized. - .WillOnce(Invoke( - [](int tagId, const ConfigKey&, vector>* data, bool) { - data->clear(); - data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); - return true; - })) - // Screen state change to ON. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs); + data->clear(); + data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs, 3)); + return true; + })) + // Screen state change to ON. + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, + vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 5); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 5, 5)); return true; })) // Screen state change to VR. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 10); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 10, 9)); return true; })) // Screen state change to OFF. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 15); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 15, 21)); return true; })) // Dump report requested. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 50); data->clear(); data->push_back(CreateRepeatedValueLogEvent(tagId, bucketStartTimeNs + 50, 30)); return true; @@ -3990,18 +4058,20 @@ TEST(ValueMetricProducerTest, TestSlicedStateWithPrimaryField_WithDimensions) { *fieldsInState = CreateDimensions(UID_PROCESS_STATE_ATOM_ID, {1 /* uid */}); sp pullerManager = new StrictMock(); - EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _)) + EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, _, _, _)) // ValueMetricProducer initialized. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs); data->clear(); data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs, 2 /*uid*/, 7)); data->push_back(CreateTwoValueLogEvent(tagId, bucketStartTimeNs, 1 /*uid*/, 3)); return true; })) // Uid 1 process state change from kStateUnknown -> Foreground - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 20); data->clear(); data->push_back( CreateTwoValueLogEvent(tagId, bucketStartTimeNs + 20, 1 /*uid*/, 6)); @@ -4012,8 +4082,9 @@ TEST(ValueMetricProducerTest, TestSlicedStateWithPrimaryField_WithDimensions) { return true; })) // Uid 2 process state change from kStateUnknown -> Background - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucketStartTimeNs + 40); data->clear(); data->push_back( CreateTwoValueLogEvent(tagId, bucketStartTimeNs + 40, 2 /*uid*/, 9)); @@ -4024,8 +4095,9 @@ TEST(ValueMetricProducerTest, TestSlicedStateWithPrimaryField_WithDimensions) { return true; })) // Uid 1 process state change from Foreground -> Background - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 20); data->clear(); data->push_back( CreateTwoValueLogEvent(tagId, bucket2StartTimeNs + 20, 1 /*uid*/, 13)); @@ -4036,8 +4108,9 @@ TEST(ValueMetricProducerTest, TestSlicedStateWithPrimaryField_WithDimensions) { return true; })) // Uid 1 process state change from Background -> Foreground - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 40); data->clear(); data->push_back( CreateTwoValueLogEvent(tagId, bucket2StartTimeNs + 40, 1 /*uid*/, 17)); @@ -4048,8 +4121,9 @@ TEST(ValueMetricProducerTest, TestSlicedStateWithPrimaryField_WithDimensions) { return true; })) // Dump report pull. - .WillOnce(Invoke([](int tagId, const ConfigKey&, + .WillOnce(Invoke([](int tagId, const ConfigKey&, const int64_t eventTimeNs, vector>* data, bool) { + EXPECT_EQ(eventTimeNs, bucket2StartTimeNs + 50); data->clear(); data->push_back( CreateTwoValueLogEvent(tagId, bucket2StartTimeNs + 50, 2 /*uid*/, 20)); diff --git a/cmds/statsd/tests/metrics/metrics_test_helper.h b/cmds/statsd/tests/metrics/metrics_test_helper.h index 46ef0f613bbea..eeb38a4644fd7 100644 --- a/cmds/statsd/tests/metrics/metrics_test_helper.h +++ b/cmds/statsd/tests/metrics/metrics_test_helper.h @@ -38,10 +38,11 @@ public: int64_t nextPulltimeNs, int64_t intervalNs)); MOCK_METHOD3(UnRegisterReceiver, void(int tagId, const ConfigKey& key, wp receiver)); - MOCK_METHOD4(Pull, bool(const int pullCode, const ConfigKey& key, - vector>* data, bool useUids)); - MOCK_METHOD4(Pull, bool(const int pullCode, const vector& uids, + MOCK_METHOD5(Pull, bool(const int pullCode, const ConfigKey& key, const int64_t eventTimeNs, vector>* data, bool useUids)); + MOCK_METHOD5(Pull, + bool(const int pullCode, const vector& uids, const int64_t eventTimeNs, + vector>* data, bool useUids)); MOCK_METHOD2(RegisterPullUidProvider, void(const ConfigKey& configKey, wp provider)); MOCK_METHOD2(UnregisterPullUidProvider, diff --git a/cmds/statsd/tests/shell/ShellSubscriber_test.cpp b/cmds/statsd/tests/shell/ShellSubscriber_test.cpp index 363fcb4bf1938..e384b6ac7c847 100644 --- a/cmds/statsd/tests/shell/ShellSubscriber_test.cpp +++ b/cmds/statsd/tests/shell/ShellSubscriber_test.cpp @@ -190,8 +190,8 @@ TEST(ShellSubscriberTest, testPulledSubscription) { sp pullerManager = new StrictMock(); const vector uids = {AID_SYSTEM}; - EXPECT_CALL(*pullerManager, Pull(10016, uids, _, _)) - .WillRepeatedly(Invoke([](int tagId, const vector&, + EXPECT_CALL(*pullerManager, Pull(10016, uids, _, _, _)) + .WillRepeatedly(Invoke([](int tagId, const vector&, const int64_t, vector>* data, bool) { data->clear(); data->push_back(makeCpuActiveTimeAtom(/*uid=*/kUid1, /*timeMillis=*/kCpuTime1));