Merge "statsd informs incidentd of anomalies"

This commit is contained in:
TreeHugger Robot
2017-11-28 01:59:57 +00:00
committed by Android (Google) Code Review
3 changed files with 36 additions and 1 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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();