github.com/facebookincubator/go-belt@v0.0.0-20230703220935-39cd348f1a38/tool/experimental/metrics/implementation/dummy/dummy_metrics.go (about) 1 // Copyright 2022 Meta Platforms, Inc. and affiliates. 2 // 3 // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 // 5 // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 // 7 // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 // 9 // 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 // 11 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 13 package dummy 14 15 import ( 16 "github.com/facebookincubator/go-belt" 17 "github.com/facebookincubator/go-belt/pkg/field" 18 metrics "github.com/facebookincubator/go-belt/tool/experimental/metrics/types" 19 ) 20 21 // Metrics is a dummy implementation of metrics.Metrics. It returns 22 // safe handlers which won't panic, but they doesn't do anything. 23 type Metrics struct{} 24 25 var _ metrics.Metrics = (*Metrics)(nil) 26 27 // New returns a new instance of Metrics. 28 func New() *Metrics { 29 return (*Metrics)(nil) 30 } 31 32 // WithContextFields implements metrics.Metrics. 33 func (*Metrics) WithContextFields(allFields *field.FieldsChain, newFieldsCount int) belt.Tool { 34 return (*Metrics)(nil) 35 } 36 37 // WithTraceIDs implements metrics.Metrics. 38 func (*Metrics) WithTraceIDs(traceIDs belt.TraceIDs, newTraceIDsCount int) belt.Tool { 39 return (*Metrics)(nil) 40 } 41 42 // Gauge implements metrics.Metrics. 43 func (*Metrics) Gauge(key string) metrics.Gauge { 44 return (*gauge)(nil) 45 } 46 47 // GaugeFields implements metrics.Metrics. 48 func (*Metrics) GaugeFields(key string, additionalFields field.AbstractFields) metrics.Gauge { 49 return (*gauge)(nil) 50 } 51 52 // IntGauge implements metrics.Metrics. 53 func (*Metrics) IntGauge(key string) metrics.IntGauge { 54 return (*intGauge)(nil) 55 } 56 57 // IntGaugeFields implements metrics.Metrics. 58 func (*Metrics) IntGaugeFields(key string, additionalFields field.AbstractFields) metrics.IntGauge { 59 return (*intGauge)(nil) 60 } 61 62 // Count implements metrics.Metrics. 63 func (*Metrics) Count(key string) metrics.Count { 64 return (*count)(nil) 65 } 66 67 // CountFields implements metrics.Metrics. 68 func (*Metrics) CountFields(key string, additionalFields field.AbstractFields) metrics.Count { 69 return (*count)(nil) 70 } 71 72 // Flush implements metrics.Metrics. 73 func (*Metrics) Flush() {} 74 75 type gauge struct{} 76 77 var _ metrics.Gauge = (*gauge)(nil) 78 79 // Value implements metrics.Metric. 80 func (*gauge) Value() any { 81 return float64(0) 82 } 83 84 // Add implements metrics.Gauge. 85 func (*gauge) Add(v float64) metrics.Gauge { 86 return (*gauge)(nil) 87 } 88 89 // WithResetFields implements metrics.Gauge. 90 func (*gauge) WithResetFields(field.AbstractFields) metrics.Gauge { 91 return (*gauge)(nil) 92 } 93 94 type intGauge struct{} 95 96 var _ metrics.IntGauge = (*intGauge)(nil) 97 98 // Value implements metrics.Metric. 99 func (*intGauge) Value() any { 100 return int64(0) 101 } 102 103 // Add implements metrics.IntGauge. 104 func (*intGauge) Add(v int64) metrics.IntGauge { 105 return (*intGauge)(nil) 106 } 107 108 // WithResetFields implements metrics.IntGauge. 109 func (*intGauge) WithResetFields(field.AbstractFields) metrics.IntGauge { 110 return (*intGauge)(nil) 111 } 112 113 type count struct{} 114 115 var _ metrics.Count = (*count)(nil) 116 117 // Value implements metrics.Metric. 118 func (*count) Value() any { 119 return uint64(0) 120 } 121 122 // Add implements metrics.Count. 123 func (*count) Add(v uint64) metrics.Count { 124 return (*count)(nil) 125 } 126 127 // Add implements metrics.WithResetFields. 128 func (*count) WithResetFields(field.AbstractFields) metrics.Count { 129 return (*count)(nil) 130 }