go.temporal.io/server@v1.23.0/common/metrics/metrics.go (about) 1 // The MIT License 2 // 3 // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. 4 // 5 // Copyright (c) 2020 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 //go:generate mockgen -copyright_file ../../LICENSE -package $GOPACKAGE -source $GOFILE -destination metrics_mock.go 26 27 package metrics 28 29 import ( 30 "time" 31 32 "go.temporal.io/server/common/log" 33 ) 34 35 // Mostly cribbed from 36 // https://github.com/temporalio/sdk-go/blob/master/internal/common/metrics/handler.go 37 // and adapted to depend on golang.org/x/exp/event 38 type ( 39 // Handler is a wrapper around a metrics client. 40 // If you are interacting with metrics registered with New*Def functions, e.g. NewCounterDef, please use the With 41 // method of those definitions instead of calling Counter directly on the Handler. This will ensure that you don't 42 // accidentally use the wrong metric type, and you don't need to re-specify metric types or units. 43 Handler interface { 44 // WithTags creates a new Handler with provided Tag list. 45 // Tags are merged with registered Tags from the source Handler. 46 WithTags(...Tag) Handler 47 48 // Counter obtains a counter for the given name. 49 Counter(string) CounterIface 50 51 // Gauge obtains a gauge for the given name. 52 Gauge(string) GaugeIface 53 54 // Timer obtains a timer for the given name. 55 Timer(string) TimerIface 56 57 // Histogram obtains a histogram for the given name. 58 Histogram(string, MetricUnit) HistogramIface 59 60 Stop(log.Logger) 61 } 62 63 // CounterIface is an ever-increasing counter. 64 CounterIface interface { 65 // Record increments the counter value. 66 // Tags provided are merged with the source MetricsHandler 67 Record(int64, ...Tag) 68 } 69 // GaugeIface can be set to any float and repesents a latest value instrument. 70 GaugeIface interface { 71 // Record updates the gauge value. 72 // Tags provided are merged with the source MetricsHandler 73 Record(float64, ...Tag) 74 } 75 76 // TimerIface records time durations. 77 TimerIface interface { 78 // Record sets the timer value. 79 // Tags provided are merged with the source MetricsHandler 80 Record(time.Duration, ...Tag) 81 } 82 83 // HistogramIface records a distribution of values. 84 HistogramIface interface { 85 // Record adds a value to the distribution 86 // Tags provided are merged with the source MetricsHandler 87 Record(int64, ...Tag) 88 } 89 90 CounterFunc func(int64, ...Tag) 91 GaugeFunc func(float64, ...Tag) 92 TimerFunc func(time.Duration, ...Tag) 93 HistogramFunc func(int64, ...Tag) 94 ) 95 96 func (c CounterFunc) Record(v int64, tags ...Tag) { c(v, tags...) } 97 func (c GaugeFunc) Record(v float64, tags ...Tag) { c(v, tags...) } 98 func (c TimerFunc) Record(v time.Duration, tags ...Tag) { c(v, tags...) } 99 func (c HistogramFunc) Record(v int64, tags ...Tag) { c(v, tags...) }