Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 1 | // Copyright (C) 2017 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 15 | #include <gtest/gtest.h> |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 16 | |
| 17 | #include "src/condition/ConditionTracker.h" |
| 18 | #include "src/matchers/LogMatchingTracker.h" |
| 19 | #include "src/metrics/CountMetricProducer.h" |
Yangster | 1d4d686 | 2017-10-31 12:58:51 -0700 | [diff] [blame] | 20 | #include "src/metrics/GaugeMetricProducer.h" |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 21 | #include "src/metrics/MetricProducer.h" |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 22 | #include "src/metrics/ValueMetricProducer.h" |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 23 | #include "src/metrics/metrics_manager_util.h" |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 24 | |
| 25 | #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <set> |
| 29 | #include <unordered_map> |
| 30 | #include <vector> |
| 31 | |
| 32 | using namespace android::os::statsd; |
| 33 | using android::sp; |
| 34 | using std::set; |
| 35 | using std::unordered_map; |
| 36 | using std::vector; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 37 | using android::os::statsd::Condition; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 38 | |
| 39 | #ifdef __ANDROID__ |
| 40 | |
| 41 | // TODO: ADD MORE TEST CASES. |
| 42 | |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame^] | 43 | const ConfigKey kConfigKey(0, "test"); |
| 44 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 45 | StatsdConfig buildGoodConfig() { |
| 46 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 47 | config.set_name("12345"); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 48 | |
| 49 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 50 | eventMatcher->set_name("SCREEN_IS_ON"); |
| 51 | |
| 52 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 53 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 54 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 55 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 56 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 57 | 2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/); |
| 58 | |
| 59 | eventMatcher = config.add_log_entry_matcher(); |
| 60 | eventMatcher->set_name("SCREEN_IS_OFF"); |
| 61 | |
| 62 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 63 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 64 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 65 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 66 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 67 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_OFF*/); |
| 68 | |
| 69 | eventMatcher = config.add_log_entry_matcher(); |
| 70 | eventMatcher->set_name("SCREEN_ON_OR_OFF"); |
| 71 | |
| 72 | LogEntryMatcher_Combination* combination = eventMatcher->mutable_combination(); |
| 73 | combination->set_operation(LogicalOperation::OR); |
| 74 | combination->add_matcher("SCREEN_IS_ON"); |
| 75 | combination->add_matcher("SCREEN_IS_OFF"); |
| 76 | |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 77 | CountMetric* metric = config.add_count_metric(); |
| 78 | metric->set_name("3"); |
| 79 | metric->set_what("SCREEN_IS_ON"); |
| 80 | metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 81 | KeyMatcher* keyMatcher = metric->add_dimension(); |
| 82 | keyMatcher->set_key(1); |
| 83 | |
| 84 | auto alert = config.add_alert(); |
| 85 | alert->set_name("3"); |
| 86 | alert->set_metric_name("3"); |
| 87 | alert->set_number_of_buckets(10); |
| 88 | alert->set_refractory_period_secs(100); |
| 89 | alert->set_trigger_if_sum_gt(100); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 90 | return config; |
| 91 | } |
| 92 | |
| 93 | StatsdConfig buildCircleMatchers() { |
| 94 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 95 | config.set_name("12345"); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 96 | |
| 97 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 98 | eventMatcher->set_name("SCREEN_IS_ON"); |
| 99 | |
| 100 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 101 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 102 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 103 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 104 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 105 | 2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/); |
| 106 | |
| 107 | eventMatcher = config.add_log_entry_matcher(); |
| 108 | eventMatcher->set_name("SCREEN_ON_OR_OFF"); |
| 109 | |
| 110 | LogEntryMatcher_Combination* combination = eventMatcher->mutable_combination(); |
| 111 | combination->set_operation(LogicalOperation::OR); |
| 112 | combination->add_matcher("SCREEN_IS_ON"); |
| 113 | // Circle dependency |
| 114 | combination->add_matcher("SCREEN_ON_OR_OFF"); |
| 115 | |
| 116 | return config; |
| 117 | } |
| 118 | |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 119 | StatsdConfig buildAlertWithUnknownMetric() { |
| 120 | StatsdConfig config; |
| 121 | config.set_name("12345"); |
| 122 | |
| 123 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 124 | eventMatcher->set_name("SCREEN_IS_ON"); |
| 125 | |
| 126 | CountMetric* metric = config.add_count_metric(); |
| 127 | metric->set_name("3"); |
| 128 | metric->set_what("SCREEN_IS_ON"); |
| 129 | metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 130 | KeyMatcher* keyMatcher = metric->add_dimension(); |
| 131 | keyMatcher->set_key(1); |
| 132 | |
| 133 | auto alert = config.add_alert(); |
| 134 | alert->set_name("3"); |
| 135 | alert->set_metric_name("2"); |
| 136 | alert->set_number_of_buckets(10); |
| 137 | alert->set_refractory_period_secs(100); |
| 138 | alert->set_trigger_if_sum_gt(100); |
| 139 | return config; |
| 140 | } |
| 141 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 142 | StatsdConfig buildMissingMatchers() { |
| 143 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 144 | config.set_name("12345"); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 145 | |
| 146 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 147 | eventMatcher->set_name("SCREEN_IS_ON"); |
| 148 | |
| 149 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 150 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 151 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 152 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 153 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 154 | 2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/); |
| 155 | |
| 156 | eventMatcher = config.add_log_entry_matcher(); |
| 157 | eventMatcher->set_name("SCREEN_ON_OR_OFF"); |
| 158 | |
| 159 | LogEntryMatcher_Combination* combination = eventMatcher->mutable_combination(); |
| 160 | combination->set_operation(LogicalOperation::OR); |
| 161 | combination->add_matcher("SCREEN_IS_ON"); |
| 162 | // undefined matcher |
| 163 | combination->add_matcher("ABC"); |
| 164 | |
| 165 | return config; |
| 166 | } |
| 167 | |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 168 | StatsdConfig buildDimensionMetricsWithMultiTags() { |
| 169 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 170 | config.set_name("12345"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 171 | |
| 172 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 173 | eventMatcher->set_name("BATTERY_VERY_LOW"); |
| 174 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
| 175 | simpleLogEntryMatcher->set_tag(2); |
| 176 | |
| 177 | eventMatcher = config.add_log_entry_matcher(); |
| 178 | eventMatcher->set_name("BATTERY_VERY_VERY_LOW"); |
| 179 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
| 180 | simpleLogEntryMatcher->set_tag(3); |
| 181 | |
| 182 | eventMatcher = config.add_log_entry_matcher(); |
| 183 | eventMatcher->set_name("BATTERY_LOW"); |
| 184 | |
| 185 | LogEntryMatcher_Combination* combination = eventMatcher->mutable_combination(); |
| 186 | combination->set_operation(LogicalOperation::OR); |
| 187 | combination->add_matcher("BATTERY_VERY_LOW"); |
| 188 | combination->add_matcher("BATTERY_VERY_VERY_LOW"); |
| 189 | |
| 190 | // Count process state changes, slice by uid, while SCREEN_IS_OFF |
| 191 | CountMetric* metric = config.add_count_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 192 | metric->set_name("3"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 193 | metric->set_what("BATTERY_LOW"); |
| 194 | metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 195 | KeyMatcher* keyMatcher = metric->add_dimension(); |
| 196 | keyMatcher->set_key(1); |
| 197 | |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 198 | auto alert = config.add_alert(); |
| 199 | alert->set_name("3"); |
| 200 | alert->set_metric_name("3"); |
| 201 | alert->set_number_of_buckets(10); |
| 202 | alert->set_refractory_period_secs(100); |
| 203 | alert->set_trigger_if_sum_gt(100); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 204 | return config; |
| 205 | } |
| 206 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 207 | StatsdConfig buildCircleConditions() { |
| 208 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 209 | config.set_name("12345"); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 210 | |
| 211 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 212 | eventMatcher->set_name("SCREEN_IS_ON"); |
| 213 | |
| 214 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 215 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 216 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 217 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 218 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 219 | 2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/); |
| 220 | |
| 221 | eventMatcher = config.add_log_entry_matcher(); |
| 222 | eventMatcher->set_name("SCREEN_IS_OFF"); |
| 223 | |
| 224 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 225 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 226 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 227 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 228 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 229 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_OFF*/); |
| 230 | |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 231 | auto condition = config.add_condition(); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 232 | condition->set_name("SCREEN_IS_ON"); |
| 233 | SimpleCondition* simpleCondition = condition->mutable_simple_condition(); |
| 234 | simpleCondition->set_start("SCREEN_IS_ON"); |
| 235 | simpleCondition->set_stop("SCREEN_IS_OFF"); |
| 236 | |
| 237 | condition = config.add_condition(); |
| 238 | condition->set_name("SCREEN_IS_EITHER_ON_OFF"); |
| 239 | |
| 240 | Condition_Combination* combination = condition->mutable_combination(); |
| 241 | combination->set_operation(LogicalOperation::OR); |
| 242 | combination->add_condition("SCREEN_IS_ON"); |
| 243 | combination->add_condition("SCREEN_IS_EITHER_ON_OFF"); |
| 244 | |
| 245 | return config; |
| 246 | } |
| 247 | |
| 248 | TEST(MetricsManagerTest, TestGoodConfig) { |
| 249 | StatsdConfig config = buildGoodConfig(); |
| 250 | set<int> allTagIds; |
| 251 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 252 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 253 | vector<sp<MetricProducer>> allMetricProducers; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 254 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 255 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 256 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 257 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
| 258 | |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame^] | 259 | EXPECT_TRUE(initStatsdConfig(kConfigKey, config, allTagIds, allLogEntryMatchers, |
| 260 | allConditionTrackers, allMetricProducers, allAnomalyTrackers, |
| 261 | conditionToMetricMap, trackerToMetricMap, trackerToConditionMap)); |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 262 | EXPECT_EQ(1u, allMetricProducers.size()); |
| 263 | EXPECT_EQ(1u, allAnomalyTrackers.size()); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 266 | TEST(MetricsManagerTest, TestDimensionMetricsWithMultiTags) { |
| 267 | StatsdConfig config = buildDimensionMetricsWithMultiTags(); |
| 268 | set<int> allTagIds; |
| 269 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 270 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 271 | vector<sp<MetricProducer>> allMetricProducers; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 272 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 273 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 274 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 275 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
| 276 | |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame^] | 277 | EXPECT_FALSE(initStatsdConfig(kConfigKey, config, allTagIds, allLogEntryMatchers, |
| 278 | allConditionTrackers, allMetricProducers, allAnomalyTrackers, |
| 279 | conditionToMetricMap, trackerToMetricMap, trackerToConditionMap)); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 282 | TEST(MetricsManagerTest, TestCircleLogMatcherDependency) { |
| 283 | StatsdConfig config = buildCircleMatchers(); |
| 284 | set<int> allTagIds; |
| 285 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 286 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 287 | vector<sp<MetricProducer>> allMetricProducers; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 288 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 289 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 290 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 291 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
| 292 | |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame^] | 293 | EXPECT_FALSE(initStatsdConfig(kConfigKey, config, allTagIds, allLogEntryMatchers, |
| 294 | allConditionTrackers, allMetricProducers, allAnomalyTrackers, |
| 295 | conditionToMetricMap, trackerToMetricMap, trackerToConditionMap)); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | TEST(MetricsManagerTest, TestMissingMatchers) { |
| 299 | StatsdConfig config = buildMissingMatchers(); |
| 300 | set<int> allTagIds; |
| 301 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 302 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 303 | vector<sp<MetricProducer>> allMetricProducers; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 304 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 305 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 306 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 307 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame^] | 308 | EXPECT_FALSE(initStatsdConfig(kConfigKey, config, allTagIds, allLogEntryMatchers, |
| 309 | allConditionTrackers, allMetricProducers, allAnomalyTrackers, |
| 310 | conditionToMetricMap, trackerToMetricMap, trackerToConditionMap)); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | TEST(MetricsManagerTest, TestCircleConditionDependency) { |
| 314 | StatsdConfig config = buildCircleConditions(); |
| 315 | set<int> allTagIds; |
| 316 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 317 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 318 | vector<sp<MetricProducer>> allMetricProducers; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 319 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 320 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 321 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 322 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
| 323 | |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame^] | 324 | EXPECT_FALSE(initStatsdConfig(kConfigKey, config, allTagIds, allLogEntryMatchers, |
| 325 | allConditionTrackers, allMetricProducers, allAnomalyTrackers, |
| 326 | conditionToMetricMap, trackerToMetricMap, trackerToConditionMap)); |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | TEST(MetricsManagerTest, testAlertWithUnknownMetric) { |
| 330 | StatsdConfig config = buildAlertWithUnknownMetric(); |
| 331 | set<int> allTagIds; |
| 332 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 333 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 334 | vector<sp<MetricProducer>> allMetricProducers; |
| 335 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
| 336 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 337 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 338 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
| 339 | |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame^] | 340 | EXPECT_FALSE(initStatsdConfig(kConfigKey, config, allTagIds, allLogEntryMatchers, |
| 341 | allConditionTrackers, allMetricProducers, allAnomalyTrackers, |
| 342 | conditionToMetricMap, trackerToMetricMap, trackerToConditionMap)); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | #else |
| 346 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 347 | #endif |