github.com/uber-go/tally/v4@v4.1.17/reporter.go (about) 1 // Copyright (c) 2021 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package tally 22 23 import "time" 24 25 // BaseStatsReporter implements the shared reporter methods. 26 type BaseStatsReporter interface { 27 // Capabilities returns the capabilities description of the reporter. 28 Capabilities() Capabilities 29 30 // Flush asks the reporter to flush all reported values. 31 Flush() 32 } 33 34 // StatsReporter is a backend for Scopes to report metrics to. 35 type StatsReporter interface { 36 BaseStatsReporter 37 38 // ReportCounter reports a counter value 39 ReportCounter( 40 name string, 41 tags map[string]string, 42 value int64, 43 ) 44 45 // ReportGauge reports a gauge value 46 ReportGauge( 47 name string, 48 tags map[string]string, 49 value float64, 50 ) 51 52 // ReportTimer reports a timer value 53 ReportTimer( 54 name string, 55 tags map[string]string, 56 interval time.Duration, 57 ) 58 59 // ReportHistogramValueSamples reports histogram samples for a bucket 60 ReportHistogramValueSamples( 61 name string, 62 tags map[string]string, 63 buckets Buckets, 64 bucketLowerBound, 65 bucketUpperBound float64, 66 samples int64, 67 ) 68 69 // ReportHistogramDurationSamples reports histogram samples for a bucket 70 ReportHistogramDurationSamples( 71 name string, 72 tags map[string]string, 73 buckets Buckets, 74 bucketLowerBound, 75 bucketUpperBound time.Duration, 76 samples int64, 77 ) 78 } 79 80 // CachedStatsReporter is a backend for Scopes that pre allocates all 81 // counter, gauges, timers & histograms. This is harder to implement but more performant. 82 type CachedStatsReporter interface { 83 BaseStatsReporter 84 85 // AllocateCounter pre allocates a counter data structure with name & tags. 86 AllocateCounter( 87 name string, 88 tags map[string]string, 89 ) CachedCount 90 91 // AllocateGauge pre allocates a gauge data structure with name & tags. 92 AllocateGauge( 93 name string, 94 tags map[string]string, 95 ) CachedGauge 96 97 // AllocateTimer pre allocates a timer data structure with name & tags. 98 AllocateTimer( 99 name string, 100 tags map[string]string, 101 ) CachedTimer 102 103 // AllocateHistogram pre allocates a histogram data structure with name, tags, 104 // value buckets and duration buckets. 105 AllocateHistogram( 106 name string, 107 tags map[string]string, 108 buckets Buckets, 109 ) CachedHistogram 110 } 111 112 // CachedCount interface for reporting an individual counter 113 type CachedCount interface { 114 ReportCount(value int64) 115 } 116 117 // CachedGauge interface for reporting an individual gauge 118 type CachedGauge interface { 119 ReportGauge(value float64) 120 } 121 122 // CachedTimer interface for reporting an individual timer 123 type CachedTimer interface { 124 ReportTimer(interval time.Duration) 125 } 126 127 // CachedHistogram interface for reporting histogram samples to buckets 128 type CachedHistogram interface { 129 ValueBucket( 130 bucketLowerBound, bucketUpperBound float64, 131 ) CachedHistogramBucket 132 DurationBucket( 133 bucketLowerBound, bucketUpperBound time.Duration, 134 ) CachedHistogramBucket 135 } 136 137 // CachedHistogramBucket interface for reporting histogram samples to a specific bucket 138 type CachedHistogramBucket interface { 139 ReportSamples(value int64) 140 }