-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
metrics.go
53 lines (45 loc) · 1.2 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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package kvstore
import (
"fmt"
"strings"
"github.com/cilium/cilium/pkg/metrics"
"github.com/cilium/cilium/pkg/time"
)
const (
metricDelete = "delete"
metricRead = "read"
metricSet = "set"
)
func GetScopeFromKey(key string) string {
s := strings.SplitN(key, "/", 5)
if len(s) < 4 {
if len(key) >= 12 {
return key[:12]
}
return key
}
return fmt.Sprintf("%s/%s", s[2], s[3])
}
func increaseMetric(key, kind, action string, duration time.Duration, err error) {
if !metrics.KVStoreOperationsDuration.IsEnabled() {
return
}
namespace := GetScopeFromKey(key)
outcome := metrics.Error2Outcome(err)
metrics.KVStoreOperationsDuration.
WithLabelValues(namespace, kind, action, outcome).Observe(duration.Seconds())
}
func trackEventQueued(key string, typ EventType, duration time.Duration) {
if !metrics.KVStoreEventsQueueDuration.IsEnabled() {
return
}
metrics.KVStoreEventsQueueDuration.WithLabelValues(GetScopeFromKey(key), typ.String()).Observe(duration.Seconds())
}
func recordQuorumError(err string) {
if !metrics.KVStoreQuorumErrors.IsEnabled() {
return
}
metrics.KVStoreQuorumErrors.WithLabelValues(err).Inc()
}