-
Notifications
You must be signed in to change notification settings - Fork 175
/
storage.go
49 lines (39 loc) · 1.09 KB
/
storage.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
package metrics
import (
"sync"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type StorageCollector struct {
storageOperationModified *prometheus.CounterVec
}
const (
modifierLabel = "modifier"
skipDuplicates = "skip_duplicates"
retryOnConflict = "retry_on_conflict"
)
var (
onlyOnce sync.Once
collector *StorageCollector
)
func GetStorageCollector() *StorageCollector {
onlyOnce.Do(
func() {
collector = &StorageCollector{
storageOperationModified: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "operation_modifier",
Namespace: "storage",
Subsystem: "badger",
Help: "report number of times a storage operation was modified using a modifier",
}, []string{modifierLabel}),
}
},
)
return collector
}
func (sc *StorageCollector) SkipDuplicate() {
sc.storageOperationModified.With(prometheus.Labels{modifierLabel: skipDuplicates}).Inc()
}
func (sc *StorageCollector) RetryOnConflict() {
sc.storageOperationModified.With(prometheus.Labels{modifierLabel: retryOnConflict}).Inc()
}