-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathfactory.go
71 lines (57 loc) · 1.57 KB
/
factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2022 The Jaeger Authors.
// Copyright (c) 2017 Uber Technologies, Inc.
// SPDX-License-Identifier: Apache-2.0
package metrics
import (
"time"
)
// NSOptions defines the name and tags map associated with a factory namespace
type NSOptions struct {
Name string
Tags map[string]string
}
// Options defines the information associated with a metric
type Options struct {
Name string
Tags map[string]string
Help string
}
// TimerOptions defines the information associated with a metric
type TimerOptions struct {
Name string
Tags map[string]string
Help string
Buckets []time.Duration
}
// HistogramOptions defines the information associated with a metric
type HistogramOptions struct {
Name string
Tags map[string]string
Help string
Buckets []float64
}
// Factory creates new metrics
type Factory interface {
Counter(metric Options) Counter
Timer(metric TimerOptions) Timer
Gauge(metric Options) Gauge
Histogram(metric HistogramOptions) Histogram
// Namespace returns a nested metrics factory.
Namespace(scope NSOptions) Factory
}
// NullFactory is a metrics factory that returns NullCounter, NullTimer, and NullGauge.
var NullFactory Factory = nullFactory{}
type nullFactory struct{}
func (nullFactory) Counter(Options) Counter {
return NullCounter
}
func (nullFactory) Timer(TimerOptions) Timer {
return NullTimer
}
func (nullFactory) Gauge(Options) Gauge {
return NullGauge
}
func (nullFactory) Histogram(HistogramOptions) Histogram {
return NullHistogram
}
func (nullFactory) Namespace(NSOptions /* scope */) Factory { return NullFactory }