summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2017-11-28 01:59:57 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-11-28 01:59:57 +0000
commit593f56cc811a8a0577044f73d4553cd122de9b43 (patch)
tree17a72bf29fdb4acd0551eaa4908b4fd8ea5dac1e
parent5b8f69b08eca8f497ffe56ca61c4e6b96d99929a (diff)
parentd1fd2425f744ab46a87dec4ed4d3f0680e819dbc (diff)
Merge "statsd informs incidentd of anomalies"
-rw-r--r--cmds/statsd/src/anomaly/AnomalyTracker.cpp28
-rw-r--r--cmds/statsd/src/anomaly/AnomalyTracker.h3
-rw-r--r--cmds/statsd/src/config/ConfigManager.cpp6
3 files changed, 36 insertions, 1 deletions
diff --git a/cmds/statsd/src/anomaly/AnomalyTracker.cpp b/cmds/statsd/src/anomaly/AnomalyTracker.cpp
index c2bf233c103b..7bacb441ee48 100644
--- a/cmds/statsd/src/anomaly/AnomalyTracker.cpp
+++ b/cmds/statsd/src/anomaly/AnomalyTracker.cpp
@@ -19,6 +19,9 @@
#include "AnomalyTracker.h"
+#include <android/os/IIncidentManager.h>
+#include <android/os/IncidentReportArgs.h>
+#include <binder/IServiceManager.h>
#include <time.h>
namespace android {
@@ -213,7 +216,7 @@ void AnomalyTracker::declareAnomaly(const uint64_t& timestampNs) {
// TODO: Can construct a name based on the criteria (and/or relay the criteria).
ALOGW("An anomaly (nameless) has occurred! Informing incidentd.");
}
- // TODO: informIncidentd();
+ informIncidentd();
} else {
ALOGW("An anomaly has occurred! (But informing incidentd not requested.)");
}
@@ -314,6 +317,29 @@ void AnomalyTracker::informAlarmsFired(const uint64_t& timestampNs,
}
}
+void AnomalyTracker::informIncidentd() {
+ VLOG("informIncidentd called.");
+ if (!mAlert.has_incidentd_details()) {
+ ALOGE("Attempted to call incidentd without any incidentd_details.");
+ return;
+ }
+ sp<IIncidentManager> service = interface_cast<IIncidentManager>(
+ defaultServiceManager()->getService(android::String16("incident")));
+ if (service == NULL) {
+ ALOGW("Couldn't get the incident service.");
+ return;
+ }
+
+ IncidentReportArgs incidentReport;
+ const Alert::IncidentdDetails& details = mAlert.incidentd_details();
+ for (int i = 0; i < details.section_size(); i++) {
+ incidentReport.addSection(details.section(i));
+ }
+ // TODO: Pass in mAlert.name() into the addHeader?
+
+ service->reportIncident(incidentReport);
+}
+
} // namespace statsd
} // namespace os
} // namespace android
diff --git a/cmds/statsd/src/anomaly/AnomalyTracker.h b/cmds/statsd/src/anomaly/AnomalyTracker.h
index afa6fee99c6b..49e83235f73b 100644
--- a/cmds/statsd/src/anomaly/AnomalyTracker.h
+++ b/cmds/statsd/src/anomaly/AnomalyTracker.h
@@ -148,6 +148,9 @@ protected:
// Resets all bucket data. For use when all the data gets stale.
void resetStorage();
+ // Informs the incident service that an anomaly has occurred.
+ void informIncidentd();
+
FRIEND_TEST(AnomalyTrackerTest, TestConsecutiveBuckets);
FRIEND_TEST(AnomalyTrackerTest, TestSparseBuckets);
FRIEND_TEST(GaugeMetricProducerTest, TestAnomalyDetection);
diff --git a/cmds/statsd/src/config/ConfigManager.cpp b/cmds/statsd/src/config/ConfigManager.cpp
index ac2192cdb3c5..445ee59947e9 100644
--- a/cmds/statsd/src/config/ConfigManager.cpp
+++ b/cmds/statsd/src/config/ConfigManager.cpp
@@ -210,6 +210,9 @@ StatsdConfig build_fake_config() {
alert->set_number_of_buckets(6);
alert->set_trigger_if_sum_gt(10);
alert->set_refractory_period_secs(30);
+ Alert::IncidentdDetails* details = alert->mutable_incidentd_details();
+ details->add_section(12);
+ details->add_section(13);
// Count process state changes, slice by uid.
metric = config.add_count_metric();
@@ -226,6 +229,9 @@ StatsdConfig build_fake_config() {
alert->set_number_of_buckets(4);
alert->set_trigger_if_sum_gt(30);
alert->set_refractory_period_secs(20);
+ details = alert->mutable_incidentd_details();
+ details->add_section(14);
+ details->add_section(15);
// Count process state changes, slice by uid, while SCREEN_IS_OFF
metric = config.add_count_metric();