diff --git a/cmds/statsd/src/guardrail/StatsdStats.cpp b/cmds/statsd/src/guardrail/StatsdStats.cpp index c774719a32dd2..c4034ffeee22a 100644 --- a/cmds/statsd/src/guardrail/StatsdStats.cpp +++ b/cmds/statsd/src/guardrail/StatsdStats.cpp @@ -458,6 +458,15 @@ void StatsdStats::noteInvalidatedBucket(int64_t metricId) { getAtomMetricStats(metricId).invalidatedBucket++; } +void StatsdStats::noteBucketBoundaryDelayNs(int64_t metricId, int64_t timeDelayNs) { + lock_guard lock(mLock); + AtomMetricStats& pullStats = getAtomMetricStats(metricId); + pullStats.maxBucketBoundaryDelayNs = + std::max(pullStats.maxBucketBoundaryDelayNs, timeDelayNs); + pullStats.minBucketBoundaryDelayNs = + std::min(pullStats.minBucketBoundaryDelayNs, timeDelayNs); +} + StatsdStats::AtomMetricStats& StatsdStats::getAtomMetricStats(int metricId) { auto atomMetricStatsIter = mAtomMetricStats.find(metricId); if (atomMetricStatsIter != mAtomMetricStats.end()) { diff --git a/cmds/statsd/src/guardrail/StatsdStats.h b/cmds/statsd/src/guardrail/StatsdStats.h index ed42b1f0c1cd4..2999b649a509c 100644 --- a/cmds/statsd/src/guardrail/StatsdStats.h +++ b/cmds/statsd/src/guardrail/StatsdStats.h @@ -374,6 +374,12 @@ public: */ void noteInvalidatedBucket(int64_t metricId); + /** + * For pulls at bucket boundaries, it represents the misalignment between the real timestamp and + * the end of the bucket. + */ + void noteBucketBoundaryDelayNs(int64_t metricId, int64_t timeDelayNs); + /** * Reset the historical stats. Including all stats in icebox, and the tracked stats about * metrics, matchers, and atoms. The active configs will be kept and StatsdStats will continue @@ -420,6 +426,8 @@ public: long conditionChangeInNextBucket = 0; long invalidatedBucket = 0; long bucketDropped = 0; + int64_t minBucketBoundaryDelayNs = 0; + int64_t maxBucketBoundaryDelayNs = 0; } AtomMetricStats; private: diff --git a/cmds/statsd/src/metrics/ValueMetricProducer.cpp b/cmds/statsd/src/metrics/ValueMetricProducer.cpp index 4fc9c37a5537c..ac6c27adceaad 100644 --- a/cmds/statsd/src/metrics/ValueMetricProducer.cpp +++ b/cmds/statsd/src/metrics/ValueMetricProducer.cpp @@ -387,6 +387,8 @@ void ValueMetricProducer::onDataPulled(const std::vectorwrite(FIELD_TYPE_INT64 | FIELD_ID_BUCKET_DROPPED, (long long)pair.second.bucketDropped); + protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_MIN_BUCKET_BOUNDARY_DELAY_NS, + (long long)pair.second.minBucketBoundaryDelayNs); + protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_MAX_BUCKET_BOUNDARY_DELAY_NS, + (long long)pair.second.maxBucketBoundaryDelayNs); protoOutput->end(token); }