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

Commit eb4c0774 authored by Salud Lemus's avatar Salud Lemus
Browse files

Refactor BaseInfo struct

Create another struct that contains the vector of BaseInfos,
currentState key, and hasCurrentState. Now there is a single
currentState key and hasCurrentState per HashableDimensionKey.

Bug: 165817484
Test: `m statsd`
Test: `m statsd_test`
Test: `m`
Test: `atest statsd_test`
Change-Id: I3a541b255829e44d16cfcbe3f2ad14648b759224
parent ae905ec5
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -411,7 +411,7 @@ void ValueMetricProducer::skipCurrentBucket(const int64_t dropTimeNs,

void ValueMetricProducer::resetBase() {
    for (auto& slice : mCurrentBaseInfo) {
        for (auto& baseInfo : slice.second) {
        for (auto& baseInfo : slice.second.baseInfos) {
            baseInfo.hasBase = false;
        }
    }
@@ -623,7 +623,7 @@ void ValueMetricProducer::accumulateEvents(const std::vector<std::shared_ptr<Log
                mMatchedMetricDimensionKeys.find(whatKey) != mMatchedMetricDimensionKeys.end();
        if (!presentInPulledData && whatKey.contains(mStateChangePrimaryKey.second)) {
            auto it = mCurrentBaseInfo.find(whatKey);
            for (auto& baseInfo : it->second) {
            for (auto& baseInfo : it->second.baseInfos) {
                baseInfo.hasBase = false;
            }
        }
@@ -788,22 +788,21 @@ void ValueMetricProducer::onMatchedLogEventInternalLocked(
        return;
    }

    vector<BaseInfo>& baseInfos = mCurrentBaseInfo[whatKey];
    DimensionsInWhatInfo& dimensionsInWhatInfo = mCurrentBaseInfo[whatKey];
    vector<BaseInfo>& baseInfos = dimensionsInWhatInfo.baseInfos;
    if (baseInfos.size() < mFieldMatchers.size()) {
        VLOG("Resizing number of intervals to %d", (int)mFieldMatchers.size());
        baseInfos.resize(mFieldMatchers.size());
    }

    for (BaseInfo& baseInfo : baseInfos) {
        if (!baseInfo.hasCurrentState) {
            baseInfo.currentState = getUnknownStateKey();
            baseInfo.hasCurrentState = true;
        }
    if (!dimensionsInWhatInfo.hasCurrentState) {
        dimensionsInWhatInfo.currentState = getUnknownStateKey();
        dimensionsInWhatInfo.hasCurrentState = true;
    }

    // We need to get the intervals stored with the previous state key so we can
    // close these value intervals.
    const auto oldStateKey = baseInfos[0].currentState;
    const auto oldStateKey = dimensionsInWhatInfo.currentState;
    vector<Interval>& intervals =
            mCurrentSlicedBucket[MetricDimensionKey(whatKey, oldStateKey)].intervals;
    if (intervals.size() < mFieldMatchers.size()) {
@@ -819,14 +818,14 @@ void ValueMetricProducer::onMatchedLogEventInternalLocked(
    // Discussion here: http://ag/6124370.
    bool useAnomalyDetection = true;

    dimensionsInWhatInfo.hasCurrentState = true;
    dimensionsInWhatInfo.currentState = stateKey;
    for (int i = 0; i < (int)mFieldMatchers.size(); i++) {
        const Matcher& matcher = mFieldMatchers[i];
        BaseInfo& baseInfo = baseInfos[i];
        Interval& interval = intervals[i];
        interval.valueIndex = i;
        Value value;
        baseInfo.hasCurrentState = true;
        baseInfo.currentState = stateKey;
        if (!getDoubleOrLong(event, matcher, value)) {
            VLOG("Failed to get value %d from event %s", i, event.ToString().c_str());
            StatsdStats::getInstance().noteBadValueType(mMetricId);
+9 −2
Original line number Diff line number Diff line
@@ -193,22 +193,29 @@ private:
        std::vector<Interval> intervals;
    } CurrentValueBucket;

    // Holds base information for diffing values from one value field.
    typedef struct {
        // Holds current base value of the dimension. Take diff and update if necessary.
        Value base;
        // Whether there is a base to diff to.
        bool hasBase;
    } BaseInfo;

    // State key and base information for a specific DimensionsInWhat key.
    typedef struct {
        std::vector<BaseInfo> baseInfos;
        // Last seen state value(s).
        HashableDimensionKey currentState;
        // Whether this dimensions in what key has a current state key.
        bool hasCurrentState;
    } BaseInfo;
    } DimensionsInWhatInfo;

    // Tracks the internal state in the ongoing aggregation bucket for each DimensionsInWhat
    // key and StateValuesKey pair.
    std::unordered_map<MetricDimensionKey, CurrentValueBucket> mCurrentSlicedBucket;

    std::unordered_map<HashableDimensionKey, std::vector<BaseInfo>> mCurrentBaseInfo;
    // Tracks current state key and base information for each DimensionsInWhat key.
    std::unordered_map<HashableDimensionKey, DimensionsInWhatInfo> mCurrentBaseInfo;

    std::unordered_map<MetricDimensionKey, int64_t> mCurrentFullBucket;

+216 −190

File changed.

Preview size limit exceeded, changes collapsed.