Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12c1270f authored by Bookatz's avatar Bookatz
Browse files

Statsd alerts can inform subscribers probabilistically

The config can specify that when an alarm fires the relevant
subscriber is only informed with some probability. This allows
only a fraction of firings to trigger the subscriber's action.

Bug: 73287237
Test: none yet

Change-Id: I365faad8ffd1b40b01782c1d761b1c0e09c7c299
parent 385ccb10
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -229,11 +229,19 @@ bool AnomalyTracker::isInRefractoryPeriod(const uint64_t& timestampNs,
void AnomalyTracker::informSubscribers(const MetricDimensionKey& key) {
    VLOG("informSubscribers called.");
    if (mSubscriptions.empty()) {
        ALOGE("Attempt to call with no subscribers.");
        // The config just wanted to log the anomaly. That's fine.
        VLOG("No Subscriptions were associated with the alert.");
        return;
    }

    for (const Subscription& subscription : mSubscriptions) {
        if (subscription.probability_of_informing() < 1
                && ((float)rand() / RAND_MAX) >= subscription.probability_of_informing()) {
            // Note that due to float imprecision, 0.0 and 1.0 might not truly mean never/always.
            // The config writer was advised to use -0.1 and 1.1 for never/always.
            ALOGI("Fate decided that a subscriber would not be informed.");
            continue;
        }
        switch (subscription.subscriber_information_case()) {
            case Subscription::SubscriberInformationCase::kIncidentdDetails:
                if (!GenerateIncidentReport(subscription.incidentd_details(), mAlert, mConfigKey)) {
+2 −0
Original line number Diff line number Diff line
@@ -308,6 +308,8 @@ message Subscription {
    PerfettoDetails perfetto_details = 5;
    BroadcastSubscriberDetails broadcast_subscriber_details = 6;
  }

  optional float probability_of_informing = 7 [default = 1.1];
}

message StatsdConfig {