mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame^] | 1 | // Copyright (c) 2017 Uber Technologies, Inc. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package metrics |
| 16 | |
| 17 | import ( |
| 18 | "time" |
| 19 | ) |
| 20 | |
| 21 | // NSOptions defines the name and tags map associated with a factory namespace |
| 22 | type NSOptions struct { |
| 23 | Name string |
| 24 | Tags map[string]string |
| 25 | } |
| 26 | |
| 27 | // Options defines the information associated with a metric |
| 28 | type Options struct { |
| 29 | Name string |
| 30 | Tags map[string]string |
| 31 | Help string |
| 32 | } |
| 33 | |
| 34 | // TimerOptions defines the information associated with a metric |
| 35 | type TimerOptions struct { |
| 36 | Name string |
| 37 | Tags map[string]string |
| 38 | Help string |
| 39 | Buckets []time.Duration |
| 40 | } |
| 41 | |
| 42 | // HistogramOptions defines the information associated with a metric |
| 43 | type HistogramOptions struct { |
| 44 | Name string |
| 45 | Tags map[string]string |
| 46 | Help string |
| 47 | Buckets []float64 |
| 48 | } |
| 49 | |
| 50 | // Factory creates new metrics |
| 51 | type Factory interface { |
| 52 | Counter(metric Options) Counter |
| 53 | Timer(metric TimerOptions) Timer |
| 54 | Gauge(metric Options) Gauge |
| 55 | Histogram(metric HistogramOptions) Histogram |
| 56 | |
| 57 | // Namespace returns a nested metrics factory. |
| 58 | Namespace(scope NSOptions) Factory |
| 59 | } |
| 60 | |
| 61 | // NullFactory is a metrics factory that returns NullCounter, NullTimer, and NullGauge. |
| 62 | var NullFactory Factory = nullFactory{} |
| 63 | |
| 64 | type nullFactory struct{} |
| 65 | |
| 66 | func (nullFactory) Counter(options Options) Counter { |
| 67 | return NullCounter |
| 68 | } |
| 69 | func (nullFactory) Timer(options TimerOptions) Timer { |
| 70 | return NullTimer |
| 71 | } |
| 72 | func (nullFactory) Gauge(options Options) Gauge { |
| 73 | return NullGauge |
| 74 | } |
| 75 | func (nullFactory) Histogram(options HistogramOptions) Histogram { |
| 76 | return NullHistogram |
| 77 | } |
| 78 | func (nullFactory) Namespace(scope NSOptions) Factory { return NullFactory } |