-
Notifications
You must be signed in to change notification settings - Fork 12
/
metrics.go
102 lines (89 loc) · 3.6 KB
/
metrics.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2018-2019, Square, Inc.
// Package metrics provides Etre metrics.
package metrics
import (
gm "github.com/daniel-nichter/go-metrics"
"github.com/square/etre"
)
var (
defaultSampleSize int = 2000 // unique values, ~16 KiB per metric
latencySampleSize int = 10000 // unique values, ~80 KiB
latencyConfig = gm.Config{Percentiles: []float64{0.99, 0.999}}
medConfig = gm.Config{Percentiles: []float64{0.5}}
)
// See ../metrics.go for docs of each metric. The number/order of these
// does not matter. They are const numbers only to avoid typos and enable
// compile-time checking, e.g. m.Inc(metrics.Reed, 1) will cause error
// "undefined: metrics.Reed". Implementations of Metrics must ensure that
// metric X = etre.MetricReport.X.
const (
Query byte = iota // counter (group and system)
SetOp // counter
Labels // histogram
LatencyMs // histogram
MissSLA // counter
Read // counter
ReadQuery // counter
ReadId // counter
ReadMatch // histogram
ReadLabels // counter
Write // counter
CreateOne // counter
CreateMany // counter
CreateBulk // histogram
UpdateId // counter
UpdateQuery // counter
UpdateBulk // histogram
DeleteId // counter
DeleteQuery // counter
DeleteBulk // histogram
DeleteLabel // counter
LabelRead // counter (per-label)
LabelUpdate // counter (per-label)
LabelDelete // counter (per-label)
DbError // counter (global)
APIError // counter (global)
ClientError // counter (global)
CDCClients // counter (global)
Created // counter
Updated // counter
Deleted // counter
AuthenticationFailed // counter (system)
AuthorizationFailed // counter
InvalidEntityType // counter
)
// Metrics abstracts how metrics are stored and sampled.
type Metrics interface {
// EntityType binds the Metrics instance to an entity type before calling
// other methods. This method must be called first.
//
// The caller is responsible for validating the entity type.
//
// This is only valid for group metrics.
EntityType(string)
// Inc increments the metric name (mn) by n. The metric must be a counter.
Inc(mn byte, n int64)
// IncLabel increments the metric name (mn) counter for the label by 1.
// The metric must be LabelRead, LabelUpdate, or LabelDelete.
//
// This is only valid for group metrics.
IncLabel(mn byte, label string)
// Val records one measurement (n) for the metric name (mn). The metric
// must be a gauge.
Val(mn byte, n int64)
// Trace increments trace value counters by 1.
Trace(map[string]string)
// Report returns a snapshot of all metrics, calculating stats like average
// and percentiles.
Report(reset bool) etre.Metrics
}
type Factory interface {
Make(groupNames []string) Metrics
}
// GroupFactory implements Factory to make Group metrics in the API.
type GroupFactory struct {
Store Store
}
func (f GroupFactory) Make(groupNames []string) Metrics {
return NewGroup(groupNames, f.Store)
}