Statsd AnomalyDetection stopAlarm also checks old
Every time stopAlarm() is called, it should also,
right then, check to see if the alarm should actually
have already fired (but didn't due to AlarmManager lag).
Right now, the client needs to do this check separately,
but they always go together. Indeed, MaxDurationTracker
forgot to do the check, which is a bug. It would make
much more sense if the stopAlarm takes care of it for
them, to prevent such mistakes.
Bug: 75273733
Test: make statsd_test && adb sync data && adb shell data/nativetest64/statsd_test/statsd_test
Test: cts-tradefed run cts-dev -m CtsStatsdHostTestCases -t android.cts.statsd.alert
Change-Id: I689df13690df822090ac34b1171e948be1ad0d9f
diff --git a/cmds/statsd/src/anomaly/DurationAnomalyTracker.h b/cmds/statsd/src/anomaly/DurationAnomalyTracker.h
index ef9d0d8..7c6d3e2 100644
--- a/cmds/statsd/src/anomaly/DurationAnomalyTracker.h
+++ b/cmds/statsd/src/anomaly/DurationAnomalyTracker.h
@@ -37,14 +37,12 @@
void startAlarm(const MetricDimensionKey& dimensionKey, const uint64_t& eventTime);
// Stops the alarm.
- void stopAlarm(const MetricDimensionKey& dimensionKey);
+ // If it should have already fired, but hasn't yet (e.g. because the AlarmManager is delayed),
+ // declare the anomaly now.
+ void stopAlarm(const MetricDimensionKey& dimensionKey, const uint64_t& timestampNs);
- // Stop all the alarms owned by this tracker.
- void stopAllAlarms();
-
- // Declares the anomaly when the alarm expired given the current timestamp.
- void declareAnomalyIfAlarmExpired(const MetricDimensionKey& dimensionKey,
- const uint64_t& timestampNs);
+ // Stop all the alarms owned by this tracker. Does not declare any anomalies.
+ void cancelAllAlarms();
// Declares an anomaly for each alarm in firedAlarms that belongs to this DurationAnomalyTracker
// and removes it from firedAlarms. The AlarmMonitor is not informed.