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

Commit a7de0002 authored by Muhammad Qureshi's avatar Muhammad Qureshi
Browse files

Remove kTruncatingTimestampAtomBlackList

Use shouldTruncateTimestamp flag in LogEvent instead of the blacklist
to determine whether timestamp should be truncated.

Bug: 150414373
Test: bit statsd_test:*
Change-Id: I4e21ae4909484dd898b9fcd3ce7a018f5e9d982f
parent bba1891e
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -145,7 +145,7 @@ public:
    }
    }


    // Default value = false
    // Default value = false
    inline bool shouldTruncateTimestamp() {
    inline bool shouldTruncateTimestamp() const {
        return mTruncateTimestamp;
        return mTruncateTimestamp;
    }
    }


+1 −2
Original line number Original line Diff line number Diff line
@@ -151,8 +151,7 @@ void EventMetricProducer::onMatchedLogEventInternalLocked(


    uint64_t wrapperToken =
    uint64_t wrapperToken =
            mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA);
            mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA);
    const int64_t elapsedTimeNs = truncateTimestampIfNecessary(
    const int64_t elapsedTimeNs = truncateTimestampIfNecessary(event);
            event.GetTagId(), event.GetElapsedTimestampNs());
    mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long) elapsedTimeNs);
    mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long) elapsedTimeNs);


    uint64_t eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS);
    uint64_t eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS);
+6 −6
Original line number Original line Diff line number Diff line
@@ -270,11 +270,9 @@ void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
                    protoOutput->end(atomsToken);
                    protoOutput->end(atomsToken);
                }
                }
                for (const auto& atom : bucket.mGaugeAtoms) {
                for (const auto& atom : bucket.mGaugeAtoms) {
                    const int64_t elapsedTimestampNs =
                    protoOutput->write(FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED |
                            truncateTimestampIfNecessary(mAtomId, atom.mElapsedTimestamps);
                                               FIELD_ID_ELAPSED_ATOM_TIMESTAMP,
                    protoOutput->write(
                                       (long long)atom.mElapsedTimestampNs);
                        FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_ELAPSED_ATOM_TIMESTAMP,
                        (long long)elapsedTimestampNs);
                }
                }
            }
            }
            protoOutput->end(bucketInfoToken);
            protoOutput->end(bucketInfoToken);
@@ -477,7 +475,9 @@ void GaugeMetricProducer::onMatchedLogEventInternalLocked(
    if ((*mCurrentSlicedBucket)[eventKey].size() >= mGaugeAtomsPerDimensionLimit) {
    if ((*mCurrentSlicedBucket)[eventKey].size() >= mGaugeAtomsPerDimensionLimit) {
        return;
        return;
    }
    }
    GaugeAtom gaugeAtom(getGaugeFields(event), eventTimeNs);

    const int64_t truncatedElapsedTimestampNs = truncateTimestampIfNecessary(event);
    GaugeAtom gaugeAtom(getGaugeFields(event), truncatedElapsedTimestampNs);
    (*mCurrentSlicedBucket)[eventKey].push_back(gaugeAtom);
    (*mCurrentSlicedBucket)[eventKey].push_back(gaugeAtom);
    // Anomaly detection on gauge metric only works when there is one numeric
    // Anomaly detection on gauge metric only works when there is one numeric
    // field specified.
    // field specified.
+2 −2
Original line number Original line Diff line number Diff line
@@ -35,10 +35,10 @@ namespace statsd {


struct GaugeAtom {
struct GaugeAtom {
    GaugeAtom(std::shared_ptr<vector<FieldValue>> fields, int64_t elapsedTimeNs)
    GaugeAtom(std::shared_ptr<vector<FieldValue>> fields, int64_t elapsedTimeNs)
        : mFields(fields), mElapsedTimestamps(elapsedTimeNs) {
        : mFields(fields), mElapsedTimestampNs(elapsedTimeNs) {
    }
    }
    std::shared_ptr<vector<FieldValue>> mFields;
    std::shared_ptr<vector<FieldValue>> mFields;
    int64_t mElapsedTimestamps;
    int64_t mElapsedTimestampNs;
};
};


struct GaugeBucket {
struct GaugeBucket {
+6 −7
Original line number Original line Diff line number Diff line
@@ -549,14 +549,13 @@ int64_t getWallClockMillis() {
    return time(nullptr) * MS_PER_SEC;
    return time(nullptr) * MS_PER_SEC;
}
}


int64_t truncateTimestampIfNecessary(int atomId, int64_t timestampNs) {
int64_t truncateTimestampIfNecessary(const LogEvent& event) {
    if (AtomsInfo::kTruncatingTimestampAtomBlackList.find(atomId) !=
    if (event.shouldTruncateTimestamp() ||
            AtomsInfo::kTruncatingTimestampAtomBlackList.end() ||
        (event.GetTagId() >= StatsdStats::kTimestampTruncationStartTag &&
        (atomId >= StatsdStats::kTimestampTruncationStartTag &&
         event.GetTagId() <= StatsdStats::kTimestampTruncationEndTag)) {
         atomId <= StatsdStats::kTimestampTruncationEndTag)) {
        return event.GetElapsedTimestampNs() / NS_PER_SEC / (5 * 60) * NS_PER_SEC * (5 * 60);
        return timestampNs / NS_PER_SEC / (5 * 60) * NS_PER_SEC * (5 * 60);
    } else {
    } else {
        return timestampNs;
        return event.GetElapsedTimestampNs();
    }
    }
}
}


Loading