Determine update status for gauge metrics
Test: statsd_test Bug: 162323123 Change-Id: I75e2858853719078542d4c80996c766bf5e65e67
This commit is contained in:
@@ -531,7 +531,28 @@ bool determineAllMetricUpdateStatuses(const StatsdConfig& config,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// TODO: determine update status for count, gauge, value, duration metrics.
|
||||
|
||||
for (int i = 0; i < config.gauge_metric_size(); i++, metricIndex++) {
|
||||
const GaugeMetric& metric = config.gauge_metric(i);
|
||||
set<int64_t> conditionDependencies;
|
||||
if (metric.has_condition()) {
|
||||
conditionDependencies.insert(metric.condition());
|
||||
}
|
||||
set<int64_t> matcherDependencies;
|
||||
matcherDependencies.insert(metric.what());
|
||||
if (metric.has_trigger_event()) {
|
||||
matcherDependencies.insert(metric.trigger_event());
|
||||
}
|
||||
if (!determineMetricUpdateStatus(
|
||||
config, metric, metric.id(), METRIC_TYPE_GAUGE, matcherDependencies,
|
||||
conditionDependencies, ::google::protobuf::RepeatedField<int64_t>(),
|
||||
metric.links(), oldMetricProducerMap, oldMetricProducers, metricToActivationMap,
|
||||
replacedMatchers, replacedConditions, replacedStates,
|
||||
metricsToUpdate[metricIndex])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// TODO: determine update status for value, duration metrics.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1266,6 +1266,135 @@ TEST_F(ConfigUpdateTest, TestCountMetricStateChanged) {
|
||||
EXPECT_EQ(metricsToUpdate[0], UPDATE_REPLACE);
|
||||
}
|
||||
|
||||
TEST_F(ConfigUpdateTest, TestGaugeMetricPreserve) {
|
||||
StatsdConfig config;
|
||||
AtomMatcher startMatcher = CreateScreenTurnedOnAtomMatcher();
|
||||
*config.add_atom_matcher() = startMatcher;
|
||||
AtomMatcher stopMatcher = CreateScreenTurnedOffAtomMatcher();
|
||||
*config.add_atom_matcher() = stopMatcher;
|
||||
AtomMatcher whatMatcher = CreateScreenBrightnessChangedAtomMatcher();
|
||||
*config.add_atom_matcher() = whatMatcher;
|
||||
|
||||
Predicate predicate = CreateScreenIsOnPredicate();
|
||||
*config.add_predicate() = predicate;
|
||||
|
||||
GaugeMetric* metric = config.add_gauge_metric();
|
||||
metric->set_id(12345);
|
||||
metric->set_what(whatMatcher.id());
|
||||
metric->set_condition(predicate.id());
|
||||
metric->mutable_gauge_fields_filter()->set_include_all(true);
|
||||
|
||||
EXPECT_TRUE(initConfig(config));
|
||||
|
||||
unordered_map<int64_t, int> metricToActivationMap;
|
||||
vector<UpdateStatus> metricsToUpdate(1, UPDATE_UNKNOWN);
|
||||
EXPECT_TRUE(determineAllMetricUpdateStatuses(config, oldMetricProducerMap, oldMetricProducers,
|
||||
metricToActivationMap,
|
||||
/*replacedMatchers*/ {}, /*replacedConditions=*/{},
|
||||
/*replacedStates=*/{}, metricsToUpdate));
|
||||
EXPECT_EQ(metricsToUpdate[0], UPDATE_PRESERVE);
|
||||
}
|
||||
|
||||
TEST_F(ConfigUpdateTest, TestGaugeMetricDefinitionChange) {
|
||||
StatsdConfig config;
|
||||
AtomMatcher whatMatcher = CreateScreenBrightnessChangedAtomMatcher();
|
||||
*config.add_atom_matcher() = whatMatcher;
|
||||
|
||||
GaugeMetric* metric = config.add_gauge_metric();
|
||||
metric->set_id(12345);
|
||||
metric->set_what(whatMatcher.id());
|
||||
metric->mutable_gauge_fields_filter()->set_include_all(true);
|
||||
|
||||
EXPECT_TRUE(initConfig(config));
|
||||
|
||||
// Change split bucket on app upgrade, which should change the proto, causing replacement.
|
||||
metric->set_split_bucket_for_app_upgrade(false);
|
||||
|
||||
unordered_map<int64_t, int> metricToActivationMap;
|
||||
vector<UpdateStatus> metricsToUpdate(1, UPDATE_UNKNOWN);
|
||||
EXPECT_TRUE(determineAllMetricUpdateStatuses(config, oldMetricProducerMap, oldMetricProducers,
|
||||
metricToActivationMap,
|
||||
/*replacedMatchers*/ {}, /*replacedConditions=*/{},
|
||||
/*replacedStates=*/{}, metricsToUpdate));
|
||||
EXPECT_EQ(metricsToUpdate[0], UPDATE_REPLACE);
|
||||
}
|
||||
|
||||
TEST_F(ConfigUpdateTest, TestGaugeMetricWhatChanged) {
|
||||
StatsdConfig config;
|
||||
AtomMatcher whatMatcher = CreateScreenBrightnessChangedAtomMatcher();
|
||||
*config.add_atom_matcher() = whatMatcher;
|
||||
|
||||
GaugeMetric* metric = config.add_gauge_metric();
|
||||
metric->set_id(12345);
|
||||
metric->set_what(whatMatcher.id());
|
||||
metric->mutable_gauge_fields_filter()->set_include_all(true);
|
||||
|
||||
EXPECT_TRUE(initConfig(config));
|
||||
|
||||
unordered_map<int64_t, int> metricToActivationMap;
|
||||
vector<UpdateStatus> metricsToUpdate(1, UPDATE_UNKNOWN);
|
||||
EXPECT_TRUE(determineAllMetricUpdateStatuses(
|
||||
config, oldMetricProducerMap, oldMetricProducers, metricToActivationMap,
|
||||
/*replacedMatchers*/ {whatMatcher.id()}, /*replacedConditions=*/{},
|
||||
/*replacedStates=*/{}, metricsToUpdate));
|
||||
EXPECT_EQ(metricsToUpdate[0], UPDATE_REPLACE);
|
||||
}
|
||||
|
||||
TEST_F(ConfigUpdateTest, TestGaugeMetricConditionChanged) {
|
||||
StatsdConfig config;
|
||||
AtomMatcher startMatcher = CreateScreenTurnedOnAtomMatcher();
|
||||
*config.add_atom_matcher() = startMatcher;
|
||||
AtomMatcher stopMatcher = CreateScreenTurnedOffAtomMatcher();
|
||||
*config.add_atom_matcher() = stopMatcher;
|
||||
AtomMatcher whatMatcher = CreateScreenBrightnessChangedAtomMatcher();
|
||||
*config.add_atom_matcher() = whatMatcher;
|
||||
|
||||
Predicate predicate = CreateScreenIsOnPredicate();
|
||||
*config.add_predicate() = predicate;
|
||||
|
||||
GaugeMetric* metric = config.add_gauge_metric();
|
||||
metric->set_id(12345);
|
||||
metric->set_what(whatMatcher.id());
|
||||
metric->set_condition(predicate.id());
|
||||
metric->mutable_gauge_fields_filter()->set_include_all(true);
|
||||
|
||||
EXPECT_TRUE(initConfig(config));
|
||||
|
||||
unordered_map<int64_t, int> metricToActivationMap;
|
||||
vector<UpdateStatus> metricsToUpdate(1, UPDATE_UNKNOWN);
|
||||
EXPECT_TRUE(determineAllMetricUpdateStatuses(
|
||||
config, oldMetricProducerMap, oldMetricProducers, metricToActivationMap,
|
||||
/*replacedMatchers*/ {}, /*replacedConditions=*/{predicate.id()},
|
||||
/*replacedStates=*/{}, metricsToUpdate));
|
||||
EXPECT_EQ(metricsToUpdate[0], UPDATE_REPLACE);
|
||||
}
|
||||
|
||||
TEST_F(ConfigUpdateTest, TestGaugeMetricTriggerEventChanged) {
|
||||
StatsdConfig config;
|
||||
AtomMatcher triggerEvent = CreateScreenTurnedOnAtomMatcher();
|
||||
*config.add_atom_matcher() = triggerEvent;
|
||||
AtomMatcher whatMatcher = CreateTemperatureAtomMatcher();
|
||||
*config.add_atom_matcher() = whatMatcher;
|
||||
|
||||
GaugeMetric* metric = config.add_gauge_metric();
|
||||
metric->set_id(12345);
|
||||
metric->set_what(whatMatcher.id());
|
||||
metric->set_trigger_event(triggerEvent.id());
|
||||
metric->mutable_gauge_fields_filter()->set_include_all(true);
|
||||
metric->set_sampling_type(GaugeMetric::FIRST_N_SAMPLES);
|
||||
|
||||
// Create an initial config.
|
||||
EXPECT_TRUE(initConfig(config));
|
||||
|
||||
unordered_map<int64_t, int> metricToActivationMap;
|
||||
vector<UpdateStatus> metricsToUpdate(1, UPDATE_UNKNOWN);
|
||||
EXPECT_TRUE(determineAllMetricUpdateStatuses(
|
||||
config, oldMetricProducerMap, oldMetricProducers, metricToActivationMap,
|
||||
/*replacedMatchers*/ {triggerEvent.id()}, /*replacedConditions=*/{},
|
||||
/*replacedStates=*/{}, metricsToUpdate));
|
||||
EXPECT_EQ(metricsToUpdate[0], UPDATE_REPLACE);
|
||||
}
|
||||
|
||||
TEST_F(ConfigUpdateTest, TestUpdateEventMetrics) {
|
||||
StatsdConfig config;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user