go.temporal.io/server/common/metrics/metrics.go

85 LOC · 4 covered · 81 uncovered · 4 ranges · 9908 concepts · 4 introducers · 5006 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 //go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination metrics_mock.go
2
3 package metrics
4
5 import (
6 "io"
7 "time"
8
9 "go.temporal.io/server/common/log"
10 )
11
12 // Mostly cribbed from
13 // https://github.com/temporalio/sdk-go/blob/master/internal/common/metrics/handler.go
14 // and adapted to depend on golang.org/x/exp/event
15 type (
16 // Handler is a wrapper around a metrics client.
17 // If you are interacting with metrics registered with New*Def functions, e.g. NewCounterDef, please use the With
18 // method of those definitions instead of calling Counter directly on the Handler. This will ensure that you don't
19 // accidentally use the wrong metric type, and you don't need to re-specify metric types or units.
20 Handler interface {
21 // WithTags creates a new Handler with provided Tag list.
22 // Tags are merged with registered Tags from the source Handler.
23 WithTags(...Tag) Handler
24
25 // Counter obtains a counter for the given name.
26 Counter(string) CounterIface
27
28 // Gauge obtains a gauge for the given name.
29 Gauge(string) GaugeIface
30
31 // Timer obtains a timer for the given name.
32 Timer(string) TimerIface
33
34 // Histogram obtains a histogram for the given name.
35 Histogram(string, MetricUnit) HistogramIface
36
37 Stop(log.Logger)
38
39 // StartBatch returns a BatchHandler that can emit a series of metrics as a single "wide event".
40 // If wide events aren't supported in the underlying implementation, metrics can still be sent individually.
41 StartBatch(string) BatchHandler
42 }
43
44 BatchHandler interface {
45 Handler
46 io.Closer
47 }
48
49 // CounterIface is an ever-increasing counter.
50 CounterIface interface {
51 // Record increments the counter value.
52 // Tags provided are merged with the source MetricsHandler
53 Record(int64, ...Tag)
54 }
55 // GaugeIface can be set to any float and represents a latest value instrument.
56 GaugeIface interface {
57 // Record updates the gauge value.
58 // Tags provided are merged with the source MetricsHandler
59 Record(float64, ...Tag)
60 }
61
62 // TimerIface records time durations.
63 TimerIface interface {
64 // Record sets the timer value.
65 // Tags provided are merged with the source MetricsHandler
66 Record(time.Duration, ...Tag)
67 }
68
69 // HistogramIface records a distribution of values.
70 HistogramIface interface {
71 // Record adds a value to the distribution
72 // Tags provided are merged with the source MetricsHandler
73 Record(int64, ...Tag)
74 }
75
76 CounterFunc func(int64, ...Tag)
77 GaugeFunc func(float64, ...Tag)
78 TimerFunc func(time.Duration, ...Tag)
79 HistogramFunc func(int64, ...Tag)
80 )
81
82 > func (c CounterFunc) Record(v int64, tags ...Tag) { c(v, tags...) } metrics.go ×1
83 > func (c GaugeFunc) Record(v float64, tags ...Tag) { c(v, tags...) } metrics.go ×1
84 > func (c TimerFunc) Record(v time.Duration, tags ...Tag) { c(v, tags...) } metrics.go ×1
85 > func (c HistogramFunc) Record(v int64, tags ...Tag) { c(v, tags...) } metrics.go ×1