blob: 0ead061ebd64c6a83c3cfee2f9321cb82091dab6 [file] [log] [blame]
Girish Kumar46d7c3a2020-05-18 12:06:33 +00001// 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
15package metrics
16
17import (
18 "time"
19)
20
21// NSOptions defines the name and tags map associated with a factory namespace
22type NSOptions struct {
23 Name string
24 Tags map[string]string
25}
26
27// Options defines the information associated with a metric
28type Options struct {
29 Name string
30 Tags map[string]string
31 Help string
32}
33
34// TimerOptions defines the information associated with a metric
35type 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
43type HistogramOptions struct {
44 Name string
45 Tags map[string]string
46 Help string
47 Buckets []float64
48}
49
50// Factory creates new metrics
51type 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.
62var NullFactory Factory = nullFactory{}
63
64type nullFactory struct{}
65
66func (nullFactory) Counter(options Options) Counter {
67 return NullCounter
68}
69func (nullFactory) Timer(options TimerOptions) Timer {
70 return NullTimer
71}
72func (nullFactory) Gauge(options Options) Gauge {
73 return NullGauge
74}
75func (nullFactory) Histogram(options HistogramOptions) Histogram {
76 return NullHistogram
77}
78func (nullFactory) Namespace(scope NSOptions) Factory { return NullFactory }