generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 2
/
metrics.go
63 lines (57 loc) · 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
54
55
56
57
58
59
60
61
62
63
package commons
import (
"strconv"
kmccache "github.com/kyma-project/kyma-metrics-collector/pkg/cache"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const (
namespace = "kmc"
subsystem = "skr"
TotalQueriesMetricName = "query_total"
ListingNodesAction = "listing_nodes"
ListingPVCsAction = "listing_pvc"
ListingSVCsAction = "listing_svc"
shootNameLabel = "shoot_name"
instanceIdLabel = "instance_id"
runtimeIdLabel = "runtime_id"
subAccountLabel = "sub_account_id"
globalAccountLabel = "global_account_id"
successLabel = "success"
actionLabel = "action"
)
var (
TotalQueriesMetric = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: TotalQueriesMetricName,
Help: "Total number of queries to SKR to get the metrics of the cluster.",
},
[]string{actionLabel, successLabel, shootNameLabel, instanceIdLabel, runtimeIdLabel, subAccountLabel, globalAccountLabel},
)
)
// DeleteMetrics deletes all the metrics for the provided shoot.
// Returns true if some metrics are deleted, returns false if no metrics are deleted for that subAccount.
func DeleteMetrics(shootInfo kmccache.Record) bool {
matchLabels := prometheus.Labels{
shootNameLabel: shootInfo.ShootName,
instanceIdLabel: shootInfo.InstanceID,
runtimeIdLabel: shootInfo.RuntimeID,
subAccountLabel: shootInfo.SubAccountID,
globalAccountLabel: shootInfo.GlobalAccountID,
}
return TotalQueriesMetric.DeletePartialMatch(matchLabels) > 0
}
func RecordSKRQuery(success bool, action string, shootInfo kmccache.Record) {
// the order if the values should be same as defined in the metric declaration.
TotalQueriesMetric.WithLabelValues(
action,
strconv.FormatBool(success),
shootInfo.ShootName,
shootInfo.InstanceID,
shootInfo.RuntimeID,
shootInfo.SubAccountID,
shootInfo.GlobalAccountID,
).Inc()
}