github.com/aidoskuneen/adk-node@v0.0.0-20220315131952-2e32567cb7f4/metrics/resetting_sample.go (about)

     1  package metrics
     2  
     3  // ResettingSample converts an ordinary sample into one that resets whenever its
     4  // snapshot is retrieved. This will break for multi-monitor systems, but when only
     5  // a single metric is being pushed out, this ensure that low-frequency events don't
     6  // skew th charts indefinitely.
     7  func ResettingSample(sample Sample) Sample {
     8  	return &resettingSample{
     9  		Sample: sample,
    10  	}
    11  }
    12  
    13  // resettingSample is a simple wrapper around a sample that resets it upon the
    14  // snapshot retrieval.
    15  type resettingSample struct {
    16  	Sample
    17  }
    18  
    19  // Snapshot returns a read-only copy of the sample with the original reset.
    20  func (rs *resettingSample) Snapshot() Sample {
    21  	s := rs.Sample.Snapshot()
    22  	rs.Sample.Clear()
    23  	return s
    24  }