Merge "Support a ONE_WEEK bucket size"

This commit is contained in:
Ruchir Rastogi
2019-10-14 16:34:20 +00:00
committed by Android (Google) Code Review
4 changed files with 24 additions and 0 deletions

View File

@@ -106,6 +106,7 @@ private:
FRIEND_TEST(CountMetricProducerTest, TestEventWithAppUpgrade);
FRIEND_TEST(CountMetricProducerTest, TestEventWithAppUpgradeInNextBucket);
FRIEND_TEST(CountMetricProducerTest, TestFirstBucket);
FRIEND_TEST(CountMetricProducerTest, TestOneWeekTimeUnit);
};
} // namespace statsd

View File

@@ -445,6 +445,8 @@ int64_t TimeUnitToBucketSizeInMillis(TimeUnit unit) {
return 12 * 60 * 60 * 1000LL;
case ONE_DAY:
return 24 * 60 * 60 * 1000LL;
case ONE_WEEK:
return 7 * 24 * 60 * 60 * 1000LL;
case CTS:
return 1000;
case TIME_UNIT_UNSPECIFIED:

View File

@@ -44,6 +44,7 @@ enum TimeUnit {
SIX_HOURS = 7;
TWELVE_HOURS = 8;
ONE_DAY = 9;
ONE_WEEK = 10;
CTS = 1000;
}

View File

@@ -396,6 +396,26 @@ TEST(CountMetricProducerTest, TestAnomalyDetectionUnSliced) {
std::ceil(1.0 * event7.GetElapsedTimestampNs() / NS_PER_SEC + refPeriodSec));
}
TEST(CountMetricProducerTest, TestOneWeekTimeUnit) {
CountMetric metric;
metric.set_id(1);
metric.set_bucket(ONE_WEEK);
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
int64_t oneDayNs = 24 * 60 * 60 * 1e9;
int64_t fiveWeeksNs = 5 * 7 * oneDayNs;
CountMetricProducer countProducer(
kConfigKey, metric, -1 /* meaning no condition */, wizard, oneDayNs, fiveWeeksNs);
int64_t fiveWeeksOneDayNs = fiveWeeksNs + oneDayNs;
EXPECT_EQ(fiveWeeksNs, countProducer.mCurrentBucketStartTimeNs);
EXPECT_EQ(4, countProducer.mCurrentBucketNum);
EXPECT_EQ(fiveWeeksOneDayNs, countProducer.getCurrentBucketEndTimeNs());
}
} // namespace statsd
} // namespace os
} // namespace android