Loading cmds/statsd/src/metrics/GaugeMetricProducer.cpp +5 −5 Original line number Original line Diff line number Diff line Loading @@ -320,11 +320,11 @@ void GaugeMetricProducer::pullAndMatchEventsLocked(const int64_t timestampNs) { triggerPuller = mCondition && mCurrentSlicedBucket->empty(); triggerPuller = mCondition && mCurrentSlicedBucket->empty(); break; break; } } case GaugeMetric::ALL_CONDITION_CHANGES: { case GaugeMetric::CONDITION_CHANGE_TO_TRUE: { triggerPuller = true; triggerPuller = mCondition; break; break; } } case GaugeMetric::CONDITION_CHANGE_TO_TRUE: { case GaugeMetric::FIRST_N_SAMPLES: { triggerPuller = mCondition; triggerPuller = mCondition; break; break; } } Loading Loading @@ -352,7 +352,7 @@ void GaugeMetricProducer::onConditionChangedLocked(const bool conditionMet, VLOG("GaugeMetric %lld onConditionChanged", (long long)mMetricId); VLOG("GaugeMetric %lld onConditionChanged", (long long)mMetricId); flushIfNeededLocked(eventTimeNs); flushIfNeededLocked(eventTimeNs); mCondition = conditionMet; mCondition = conditionMet; if (mIsPulled) { if (mIsPulled && mTriggerAtomId == -1) { pullAndMatchEventsLocked(eventTimeNs); pullAndMatchEventsLocked(eventTimeNs); } // else: Push mode. No need to proactively pull the gauge data. } // else: Push mode. No need to proactively pull the gauge data. } } Loading @@ -365,7 +365,7 @@ void GaugeMetricProducer::onSlicedConditionMayChangeLocked(bool overallCondition // If the condition is sliced, mCondition is true if any of the dimensions is true. And we will // If the condition is sliced, mCondition is true if any of the dimensions is true. And we will // pull for every dimension. // pull for every dimension. mCondition = overallCondition; mCondition = overallCondition; if (mIsPulled) { if (mIsPulled && mTriggerAtomId == -1) { pullAndMatchEventsLocked(eventTimeNs); pullAndMatchEventsLocked(eventTimeNs); } // else: Push mode. No need to proactively pull the gauge data. } // else: Push mode. No need to proactively pull the gauge data. } } Loading cmds/statsd/src/metrics/metrics_manager_util.cpp +13 −3 Original line number Original line Diff line number Diff line Loading @@ -535,9 +535,13 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t int triggerTrackerIndex; int triggerTrackerIndex; int triggerAtomId = -1; int triggerAtomId = -1; if (pullTagId != -1 && metric.has_trigger_event()) { if (metric.has_trigger_event()) { // event_trigger should be used with ALL_CONDITION_CHANGES if (pullTagId == -1) { if (metric.sampling_type() != GaugeMetric::ALL_CONDITION_CHANGES) { ALOGW("Pull atom not specified for trigger"); return false; } // event_trigger should be used with FIRST_N_SAMPLES if (metric.sampling_type() != GaugeMetric::FIRST_N_SAMPLES) { return false; return false; } } if (!handlePullMetricTriggerWithLogTrackers(metric.trigger_event(), metricIndex, if (!handlePullMetricTriggerWithLogTrackers(metric.trigger_event(), metricIndex, Loading @@ -549,6 +553,12 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t triggerAtomId = *(triggerAtomMatcher->getAtomIds().begin()); triggerAtomId = *(triggerAtomMatcher->getAtomIds().begin()); } } if (!metric.has_trigger_event() && pullTagId != -1 && metric.sampling_type() == GaugeMetric::FIRST_N_SAMPLES) { ALOGW("FIRST_N_SAMPLES is only for pushed event or pull_on_trigger"); return false; } int conditionIndex = -1; int conditionIndex = -1; if (metric.has_condition()) { if (metric.has_condition()) { bool good = handleMetricWithConditions( bool good = handleMetricWithConditions( Loading cmds/statsd/src/statsd_config.proto +2 −1 Original line number Original line Diff line number Diff line Loading @@ -233,8 +233,9 @@ message GaugeMetric { enum SamplingType { enum SamplingType { RANDOM_ONE_SAMPLE = 1; RANDOM_ONE_SAMPLE = 1; ALL_CONDITION_CHANGES = 2; ALL_CONDITION_CHANGES = 2 [deprecated = true]; CONDITION_CHANGE_TO_TRUE = 3; CONDITION_CHANGE_TO_TRUE = 3; FIRST_N_SAMPLES = 4; } } optional SamplingType sampling_type = 9 [default = RANDOM_ONE_SAMPLE] ; optional SamplingType sampling_type = 9 [default = RANDOM_ONE_SAMPLE] ; Loading cmds/statsd/tests/e2e/GaugeMetric_e2e_push_test.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -89,7 +89,7 @@ std::unique_ptr<LogEvent> CreateAppStartOccurredEvent( TEST(GaugeMetricE2eTest, TestMultipleFieldsForPushedEvent) { TEST(GaugeMetricE2eTest, TestMultipleFieldsForPushedEvent) { for (const auto& sampling_type : for (const auto& sampling_type : { GaugeMetric::ALL_CONDITION_CHANGES, GaugeMetric:: RANDOM_ONE_SAMPLE }) { { GaugeMetric::FIRST_N_SAMPLES, GaugeMetric:: RANDOM_ONE_SAMPLE }) { auto config = CreateStatsdConfigForPushedEvent(sampling_type); auto config = CreateStatsdConfigForPushedEvent(sampling_type); int64_t bucketStartTimeNs = 10000000000; int64_t bucketStartTimeNs = 10000000000; int64_t bucketSizeNs = int64_t bucketSizeNs = Loading Loading @@ -170,7 +170,7 @@ TEST(GaugeMetricE2eTest, TestMultipleFieldsForPushedEvent) { data.dimensions_in_what().value_tuple().dimensions_value(0).field()); data.dimensions_in_what().value_tuple().dimensions_value(0).field()); EXPECT_EQ(appUid1, data.dimensions_in_what().value_tuple().dimensions_value(0).value_int()); EXPECT_EQ(appUid1, data.dimensions_in_what().value_tuple().dimensions_value(0).value_int()); EXPECT_EQ(3, data.bucket_info_size()); EXPECT_EQ(3, data.bucket_info_size()); if (sampling_type == GaugeMetric::ALL_CONDITION_CHANGES) { if (sampling_type == GaugeMetric::FIRST_N_SAMPLES) { EXPECT_EQ(2, data.bucket_info(0).atom_size()); EXPECT_EQ(2, data.bucket_info(0).atom_size()); EXPECT_EQ(2, data.bucket_info(0).elapsed_timestamp_nanos_size()); EXPECT_EQ(2, data.bucket_info(0).elapsed_timestamp_nanos_size()); EXPECT_EQ(0, data.bucket_info(0).wall_clock_timestamp_nanos_size()); EXPECT_EQ(0, data.bucket_info(0).wall_clock_timestamp_nanos_size()); Loading cmds/statsd/tests/metrics/GaugeMetricProducer_test.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -589,7 +589,7 @@ TEST(GaugeMetricProducerTest, TestPullOnTrigger) { GaugeMetric metric; GaugeMetric metric; metric.set_id(metricId); metric.set_id(metricId); metric.set_bucket(ONE_MINUTE); metric.set_bucket(ONE_MINUTE); metric.set_sampling_type(GaugeMetric::ALL_CONDITION_CHANGES); metric.set_sampling_type(GaugeMetric::FIRST_N_SAMPLES); metric.mutable_gauge_fields_filter()->set_include_all(false); metric.mutable_gauge_fields_filter()->set_include_all(false); auto gaugeFieldMatcher = metric.mutable_gauge_fields_filter()->mutable_fields(); auto gaugeFieldMatcher = metric.mutable_gauge_fields_filter()->mutable_fields(); gaugeFieldMatcher->set_field(tagId); gaugeFieldMatcher->set_field(tagId); Loading Loading @@ -662,7 +662,7 @@ TEST(GaugeMetricProducerTest, TestRemoveDimensionInOutput) { GaugeMetric metric; GaugeMetric metric; metric.set_id(metricId); metric.set_id(metricId); metric.set_bucket(ONE_MINUTE); metric.set_bucket(ONE_MINUTE); metric.set_sampling_type(GaugeMetric::ALL_CONDITION_CHANGES); metric.set_sampling_type(GaugeMetric::FIRST_N_SAMPLES); metric.mutable_gauge_fields_filter()->set_include_all(true); metric.mutable_gauge_fields_filter()->set_include_all(true); auto dimensionMatcher = metric.mutable_dimensions_in_what(); auto dimensionMatcher = metric.mutable_dimensions_in_what(); // use field 1 as dimension. // use field 1 as dimension. Loading Loading
cmds/statsd/src/metrics/GaugeMetricProducer.cpp +5 −5 Original line number Original line Diff line number Diff line Loading @@ -320,11 +320,11 @@ void GaugeMetricProducer::pullAndMatchEventsLocked(const int64_t timestampNs) { triggerPuller = mCondition && mCurrentSlicedBucket->empty(); triggerPuller = mCondition && mCurrentSlicedBucket->empty(); break; break; } } case GaugeMetric::ALL_CONDITION_CHANGES: { case GaugeMetric::CONDITION_CHANGE_TO_TRUE: { triggerPuller = true; triggerPuller = mCondition; break; break; } } case GaugeMetric::CONDITION_CHANGE_TO_TRUE: { case GaugeMetric::FIRST_N_SAMPLES: { triggerPuller = mCondition; triggerPuller = mCondition; break; break; } } Loading Loading @@ -352,7 +352,7 @@ void GaugeMetricProducer::onConditionChangedLocked(const bool conditionMet, VLOG("GaugeMetric %lld onConditionChanged", (long long)mMetricId); VLOG("GaugeMetric %lld onConditionChanged", (long long)mMetricId); flushIfNeededLocked(eventTimeNs); flushIfNeededLocked(eventTimeNs); mCondition = conditionMet; mCondition = conditionMet; if (mIsPulled) { if (mIsPulled && mTriggerAtomId == -1) { pullAndMatchEventsLocked(eventTimeNs); pullAndMatchEventsLocked(eventTimeNs); } // else: Push mode. No need to proactively pull the gauge data. } // else: Push mode. No need to proactively pull the gauge data. } } Loading @@ -365,7 +365,7 @@ void GaugeMetricProducer::onSlicedConditionMayChangeLocked(bool overallCondition // If the condition is sliced, mCondition is true if any of the dimensions is true. And we will // If the condition is sliced, mCondition is true if any of the dimensions is true. And we will // pull for every dimension. // pull for every dimension. mCondition = overallCondition; mCondition = overallCondition; if (mIsPulled) { if (mIsPulled && mTriggerAtomId == -1) { pullAndMatchEventsLocked(eventTimeNs); pullAndMatchEventsLocked(eventTimeNs); } // else: Push mode. No need to proactively pull the gauge data. } // else: Push mode. No need to proactively pull the gauge data. } } Loading
cmds/statsd/src/metrics/metrics_manager_util.cpp +13 −3 Original line number Original line Diff line number Diff line Loading @@ -535,9 +535,13 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t int triggerTrackerIndex; int triggerTrackerIndex; int triggerAtomId = -1; int triggerAtomId = -1; if (pullTagId != -1 && metric.has_trigger_event()) { if (metric.has_trigger_event()) { // event_trigger should be used with ALL_CONDITION_CHANGES if (pullTagId == -1) { if (metric.sampling_type() != GaugeMetric::ALL_CONDITION_CHANGES) { ALOGW("Pull atom not specified for trigger"); return false; } // event_trigger should be used with FIRST_N_SAMPLES if (metric.sampling_type() != GaugeMetric::FIRST_N_SAMPLES) { return false; return false; } } if (!handlePullMetricTriggerWithLogTrackers(metric.trigger_event(), metricIndex, if (!handlePullMetricTriggerWithLogTrackers(metric.trigger_event(), metricIndex, Loading @@ -549,6 +553,12 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t triggerAtomId = *(triggerAtomMatcher->getAtomIds().begin()); triggerAtomId = *(triggerAtomMatcher->getAtomIds().begin()); } } if (!metric.has_trigger_event() && pullTagId != -1 && metric.sampling_type() == GaugeMetric::FIRST_N_SAMPLES) { ALOGW("FIRST_N_SAMPLES is only for pushed event or pull_on_trigger"); return false; } int conditionIndex = -1; int conditionIndex = -1; if (metric.has_condition()) { if (metric.has_condition()) { bool good = handleMetricWithConditions( bool good = handleMetricWithConditions( Loading
cmds/statsd/src/statsd_config.proto +2 −1 Original line number Original line Diff line number Diff line Loading @@ -233,8 +233,9 @@ message GaugeMetric { enum SamplingType { enum SamplingType { RANDOM_ONE_SAMPLE = 1; RANDOM_ONE_SAMPLE = 1; ALL_CONDITION_CHANGES = 2; ALL_CONDITION_CHANGES = 2 [deprecated = true]; CONDITION_CHANGE_TO_TRUE = 3; CONDITION_CHANGE_TO_TRUE = 3; FIRST_N_SAMPLES = 4; } } optional SamplingType sampling_type = 9 [default = RANDOM_ONE_SAMPLE] ; optional SamplingType sampling_type = 9 [default = RANDOM_ONE_SAMPLE] ; Loading
cmds/statsd/tests/e2e/GaugeMetric_e2e_push_test.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -89,7 +89,7 @@ std::unique_ptr<LogEvent> CreateAppStartOccurredEvent( TEST(GaugeMetricE2eTest, TestMultipleFieldsForPushedEvent) { TEST(GaugeMetricE2eTest, TestMultipleFieldsForPushedEvent) { for (const auto& sampling_type : for (const auto& sampling_type : { GaugeMetric::ALL_CONDITION_CHANGES, GaugeMetric:: RANDOM_ONE_SAMPLE }) { { GaugeMetric::FIRST_N_SAMPLES, GaugeMetric:: RANDOM_ONE_SAMPLE }) { auto config = CreateStatsdConfigForPushedEvent(sampling_type); auto config = CreateStatsdConfigForPushedEvent(sampling_type); int64_t bucketStartTimeNs = 10000000000; int64_t bucketStartTimeNs = 10000000000; int64_t bucketSizeNs = int64_t bucketSizeNs = Loading Loading @@ -170,7 +170,7 @@ TEST(GaugeMetricE2eTest, TestMultipleFieldsForPushedEvent) { data.dimensions_in_what().value_tuple().dimensions_value(0).field()); data.dimensions_in_what().value_tuple().dimensions_value(0).field()); EXPECT_EQ(appUid1, data.dimensions_in_what().value_tuple().dimensions_value(0).value_int()); EXPECT_EQ(appUid1, data.dimensions_in_what().value_tuple().dimensions_value(0).value_int()); EXPECT_EQ(3, data.bucket_info_size()); EXPECT_EQ(3, data.bucket_info_size()); if (sampling_type == GaugeMetric::ALL_CONDITION_CHANGES) { if (sampling_type == GaugeMetric::FIRST_N_SAMPLES) { EXPECT_EQ(2, data.bucket_info(0).atom_size()); EXPECT_EQ(2, data.bucket_info(0).atom_size()); EXPECT_EQ(2, data.bucket_info(0).elapsed_timestamp_nanos_size()); EXPECT_EQ(2, data.bucket_info(0).elapsed_timestamp_nanos_size()); EXPECT_EQ(0, data.bucket_info(0).wall_clock_timestamp_nanos_size()); EXPECT_EQ(0, data.bucket_info(0).wall_clock_timestamp_nanos_size()); Loading
cmds/statsd/tests/metrics/GaugeMetricProducer_test.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -589,7 +589,7 @@ TEST(GaugeMetricProducerTest, TestPullOnTrigger) { GaugeMetric metric; GaugeMetric metric; metric.set_id(metricId); metric.set_id(metricId); metric.set_bucket(ONE_MINUTE); metric.set_bucket(ONE_MINUTE); metric.set_sampling_type(GaugeMetric::ALL_CONDITION_CHANGES); metric.set_sampling_type(GaugeMetric::FIRST_N_SAMPLES); metric.mutable_gauge_fields_filter()->set_include_all(false); metric.mutable_gauge_fields_filter()->set_include_all(false); auto gaugeFieldMatcher = metric.mutable_gauge_fields_filter()->mutable_fields(); auto gaugeFieldMatcher = metric.mutable_gauge_fields_filter()->mutable_fields(); gaugeFieldMatcher->set_field(tagId); gaugeFieldMatcher->set_field(tagId); Loading Loading @@ -662,7 +662,7 @@ TEST(GaugeMetricProducerTest, TestRemoveDimensionInOutput) { GaugeMetric metric; GaugeMetric metric; metric.set_id(metricId); metric.set_id(metricId); metric.set_bucket(ONE_MINUTE); metric.set_bucket(ONE_MINUTE); metric.set_sampling_type(GaugeMetric::ALL_CONDITION_CHANGES); metric.set_sampling_type(GaugeMetric::FIRST_N_SAMPLES); metric.mutable_gauge_fields_filter()->set_include_all(true); metric.mutable_gauge_fields_filter()->set_include_all(true); auto dimensionMatcher = metric.mutable_dimensions_in_what(); auto dimensionMatcher = metric.mutable_dimensions_in_what(); // use field 1 as dimension. // use field 1 as dimension. Loading