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 | |
| 43 | StatsdConfig buildGoodConfig() { |
| 44 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 45 | config.set_name("12345"); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 46 | |
| 47 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 48 | eventMatcher->set_name("SCREEN_IS_ON"); |
| 49 | |
| 50 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 51 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 52 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 53 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 54 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 55 | 2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/); |
| 56 | |
| 57 | eventMatcher = config.add_log_entry_matcher(); |
| 58 | eventMatcher->set_name("SCREEN_IS_OFF"); |
| 59 | |
| 60 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 61 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 62 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 63 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 64 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 65 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_OFF*/); |
| 66 | |
| 67 | eventMatcher = config.add_log_entry_matcher(); |
| 68 | eventMatcher->set_name("SCREEN_ON_OR_OFF"); |
| 69 | |
| 70 | LogEntryMatcher_Combination* combination = eventMatcher->mutable_combination(); |
| 71 | combination->set_operation(LogicalOperation::OR); |
| 72 | combination->add_matcher("SCREEN_IS_ON"); |
| 73 | combination->add_matcher("SCREEN_IS_OFF"); |
| 74 | |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 75 | CountMetric* metric = config.add_count_metric(); |
| 76 | metric->set_name("3"); |
| 77 | metric->set_what("SCREEN_IS_ON"); |
| 78 | metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 79 | KeyMatcher* keyMatcher = metric->add_dimension(); |
| 80 | keyMatcher->set_key(1); |
| 81 | |
| 82 | auto alert = config.add_alert(); |
| 83 | alert->set_name("3"); |
| 84 | alert->set_metric_name("3"); |
| 85 | alert->set_number_of_buckets(10); |
| 86 | alert->set_refractory_period_secs(100); |
| 87 | alert->set_trigger_if_sum_gt(100); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 88 | return config; |
| 89 | } |
| 90 | |
| 91 | StatsdConfig buildCircleMatchers() { |
| 92 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 93 | config.set_name("12345"); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 94 | |
| 95 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 96 | eventMatcher->set_name("SCREEN_IS_ON"); |
| 97 | |
| 98 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 99 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 100 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 101 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 102 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 103 | 2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/); |
| 104 | |
| 105 | eventMatcher = config.add_log_entry_matcher(); |
| 106 | eventMatcher->set_name("SCREEN_ON_OR_OFF"); |
| 107 | |
| 108 | LogEntryMatcher_Combination* combination = eventMatcher->mutable_combination(); |
| 109 | combination->set_operation(LogicalOperation::OR); |
| 110 | combination->add_matcher("SCREEN_IS_ON"); |
| 111 | // Circle dependency |
| 112 | combination->add_matcher("SCREEN_ON_OR_OFF"); |
| 113 | |
| 114 | return config; |
| 115 | } |
| 116 | |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 117 | StatsdConfig buildAlertWithUnknownMetric() { |
| 118 | StatsdConfig config; |
| 119 | config.set_name("12345"); |
| 120 | |
| 121 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 122 | eventMatcher->set_name("SCREEN_IS_ON"); |
| 123 | |
| 124 | CountMetric* metric = config.add_count_metric(); |
| 125 | metric->set_name("3"); |
| 126 | metric->set_what("SCREEN_IS_ON"); |
| 127 | metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 128 | KeyMatcher* keyMatcher = metric->add_dimension(); |
| 129 | keyMatcher->set_key(1); |
| 130 | |
| 131 | auto alert = config.add_alert(); |
| 132 | alert->set_name("3"); |
| 133 | alert->set_metric_name("2"); |
| 134 | alert->set_number_of_buckets(10); |
| 135 | alert->set_refractory_period_secs(100); |
| 136 | alert->set_trigger_if_sum_gt(100); |
| 137 | return config; |
| 138 | } |
| 139 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 140 | StatsdConfig buildMissingMatchers() { |
| 141 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 142 | config.set_name("12345"); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 143 | |
| 144 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 145 | eventMatcher->set_name("SCREEN_IS_ON"); |
| 146 | |
| 147 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 148 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 149 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 150 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 151 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 152 | 2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/); |
| 153 | |
| 154 | eventMatcher = config.add_log_entry_matcher(); |
| 155 | eventMatcher->set_name("SCREEN_ON_OR_OFF"); |
| 156 | |
| 157 | LogEntryMatcher_Combination* combination = eventMatcher->mutable_combination(); |
| 158 | combination->set_operation(LogicalOperation::OR); |
| 159 | combination->add_matcher("SCREEN_IS_ON"); |
| 160 | // undefined matcher |
| 161 | combination->add_matcher("ABC"); |
| 162 | |
| 163 | return config; |
| 164 | } |
| 165 | |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 166 | StatsdConfig buildDimensionMetricsWithMultiTags() { |
| 167 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 168 | config.set_name("12345"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 169 | |
| 170 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 171 | eventMatcher->set_name("BATTERY_VERY_LOW"); |
| 172 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
| 173 | simpleLogEntryMatcher->set_tag(2); |
| 174 | |
| 175 | eventMatcher = config.add_log_entry_matcher(); |
| 176 | eventMatcher->set_name("BATTERY_VERY_VERY_LOW"); |
| 177 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
| 178 | simpleLogEntryMatcher->set_tag(3); |
| 179 | |
| 180 | eventMatcher = config.add_log_entry_matcher(); |
| 181 | eventMatcher->set_name("BATTERY_LOW"); |
| 182 | |
| 183 | LogEntryMatcher_Combination* combination = eventMatcher->mutable_combination(); |
| 184 | combination->set_operation(LogicalOperation::OR); |
| 185 | combination->add_matcher("BATTERY_VERY_LOW"); |
| 186 | combination->add_matcher("BATTERY_VERY_VERY_LOW"); |
| 187 | |
| 188 | // Count process state changes, slice by uid, while SCREEN_IS_OFF |
| 189 | CountMetric* metric = config.add_count_metric(); |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 190 | metric->set_name("3"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 191 | metric->set_what("BATTERY_LOW"); |
| 192 | metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L); |
| 193 | KeyMatcher* keyMatcher = metric->add_dimension(); |
| 194 | keyMatcher->set_key(1); |
| 195 | |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 196 | auto alert = config.add_alert(); |
| 197 | alert->set_name("3"); |
| 198 | alert->set_metric_name("3"); |
| 199 | alert->set_number_of_buckets(10); |
| 200 | alert->set_refractory_period_secs(100); |
| 201 | alert->set_trigger_if_sum_gt(100); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 202 | return config; |
| 203 | } |
| 204 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 205 | StatsdConfig buildCircleConditions() { |
| 206 | StatsdConfig config; |
Yangster-mac | d1815dc | 2017-11-13 21:43:15 -0800 | [diff] [blame] | 207 | config.set_name("12345"); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 208 | |
| 209 | LogEntryMatcher* eventMatcher = config.add_log_entry_matcher(); |
| 210 | eventMatcher->set_name("SCREEN_IS_ON"); |
| 211 | |
| 212 | SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 213 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 214 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 215 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 216 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 217 | 2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/); |
| 218 | |
| 219 | eventMatcher = config.add_log_entry_matcher(); |
| 220 | eventMatcher->set_name("SCREEN_IS_OFF"); |
| 221 | |
| 222 | simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 223 | simpleLogEntryMatcher->set_tag(2 /*SCREEN_STATE_CHANGE*/); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 224 | simpleLogEntryMatcher->add_key_value_matcher()->mutable_key_matcher()->set_key( |
| 225 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE*/); |
| 226 | simpleLogEntryMatcher->mutable_key_value_matcher(0)->set_eq_int( |
| 227 | 1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_OFF*/); |
| 228 | |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 229 | auto condition = config.add_condition(); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 230 | condition->set_name("SCREEN_IS_ON"); |
| 231 | SimpleCondition* simpleCondition = condition->mutable_simple_condition(); |
| 232 | simpleCondition->set_start("SCREEN_IS_ON"); |
| 233 | simpleCondition->set_stop("SCREEN_IS_OFF"); |
| 234 | |
| 235 | condition = config.add_condition(); |
| 236 | condition->set_name("SCREEN_IS_EITHER_ON_OFF"); |
| 237 | |
| 238 | Condition_Combination* combination = condition->mutable_combination(); |
| 239 | combination->set_operation(LogicalOperation::OR); |
| 240 | combination->add_condition("SCREEN_IS_ON"); |
| 241 | combination->add_condition("SCREEN_IS_EITHER_ON_OFF"); |
| 242 | |
| 243 | return config; |
| 244 | } |
| 245 | |
| 246 | TEST(MetricsManagerTest, TestGoodConfig) { |
| 247 | StatsdConfig config = buildGoodConfig(); |
| 248 | set<int> allTagIds; |
| 249 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 250 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 251 | vector<sp<MetricProducer>> allMetricProducers; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 252 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 253 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 254 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 255 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
| 256 | |
| 257 | EXPECT_TRUE(initStatsdConfig(config, allTagIds, allLogEntryMatchers, allConditionTrackers, |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 258 | allMetricProducers, allAnomalyTrackers, conditionToMetricMap, |
| 259 | trackerToMetricMap, trackerToConditionMap)); |
| 260 | EXPECT_EQ(1u, allMetricProducers.size()); |
| 261 | EXPECT_EQ(1u, allAnomalyTrackers.size()); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 264 | TEST(MetricsManagerTest, TestDimensionMetricsWithMultiTags) { |
| 265 | StatsdConfig config = buildDimensionMetricsWithMultiTags(); |
| 266 | set<int> allTagIds; |
| 267 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 268 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 269 | vector<sp<MetricProducer>> allMetricProducers; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 270 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 271 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 272 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 273 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
| 274 | |
| 275 | EXPECT_FALSE(initStatsdConfig(config, allTagIds, allLogEntryMatchers, allConditionTrackers, |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 276 | allMetricProducers, allAnomalyTrackers, conditionToMetricMap, |
| 277 | trackerToMetricMap, trackerToConditionMap)); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 280 | TEST(MetricsManagerTest, TestCircleLogMatcherDependency) { |
| 281 | StatsdConfig config = buildCircleMatchers(); |
| 282 | set<int> allTagIds; |
| 283 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 284 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 285 | vector<sp<MetricProducer>> allMetricProducers; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 286 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 287 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 288 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 289 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
| 290 | |
| 291 | EXPECT_FALSE(initStatsdConfig(config, allTagIds, allLogEntryMatchers, allConditionTrackers, |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 292 | allMetricProducers, allAnomalyTrackers, conditionToMetricMap, |
| 293 | trackerToMetricMap, trackerToConditionMap)); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | TEST(MetricsManagerTest, TestMissingMatchers) { |
| 297 | StatsdConfig config = buildMissingMatchers(); |
| 298 | set<int> allTagIds; |
| 299 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 300 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 301 | vector<sp<MetricProducer>> allMetricProducers; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 302 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 303 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 304 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 305 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 306 | EXPECT_FALSE(initStatsdConfig(config, allTagIds, allLogEntryMatchers, allConditionTrackers, |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 307 | allMetricProducers, allAnomalyTrackers, conditionToMetricMap, |
| 308 | trackerToMetricMap, trackerToConditionMap)); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | TEST(MetricsManagerTest, TestCircleConditionDependency) { |
| 312 | StatsdConfig config = buildCircleConditions(); |
| 313 | set<int> allTagIds; |
| 314 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 315 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 316 | vector<sp<MetricProducer>> allMetricProducers; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 317 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 318 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 319 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 320 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
| 321 | |
| 322 | EXPECT_FALSE(initStatsdConfig(config, allTagIds, allLogEntryMatchers, allConditionTrackers, |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame^] | 323 | allMetricProducers, allAnomalyTrackers, conditionToMetricMap, |
| 324 | trackerToMetricMap, trackerToConditionMap)); |
| 325 | } |
| 326 | |
| 327 | TEST(MetricsManagerTest, testAlertWithUnknownMetric) { |
| 328 | StatsdConfig config = buildAlertWithUnknownMetric(); |
| 329 | set<int> allTagIds; |
| 330 | vector<sp<LogMatchingTracker>> allLogEntryMatchers; |
| 331 | vector<sp<ConditionTracker>> allConditionTrackers; |
| 332 | vector<sp<MetricProducer>> allMetricProducers; |
| 333 | std::vector<sp<AnomalyTracker>> allAnomalyTrackers; |
| 334 | unordered_map<int, std::vector<int>> conditionToMetricMap; |
| 335 | unordered_map<int, std::vector<int>> trackerToMetricMap; |
| 336 | unordered_map<int, std::vector<int>> trackerToConditionMap; |
| 337 | |
| 338 | EXPECT_FALSE(initStatsdConfig(config, allTagIds, allLogEntryMatchers, allConditionTrackers, |
| 339 | allMetricProducers, allAnomalyTrackers, conditionToMetricMap, |
| 340 | trackerToMetricMap, trackerToConditionMap)); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | #else |
| 344 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 345 | #endif |