-
Notifications
You must be signed in to change notification settings - Fork 328
/
metricslabels.go
48 lines (42 loc) · 1.27 KB
/
metricslabels.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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Tetragon
package option
import (
"strings"
"github.com/cilium/tetragon/pkg/metrics"
)
func DefaultLabelFilter() metrics.LabelFilter {
return metrics.LabelFilter{
"namespace": true,
"workload": true,
"pod": true,
"binary": true,
}
}
func ParseMetricsLabelFilter(labelsString string) []string {
labels := []string{}
for _, l := range strings.Split(labelsString, ",") {
l = strings.TrimSpace(l)
labels = append(labels, l)
}
return labels
}
// CreateProcessLabels creates a new ProcessLabels struct with the global labels
// filter applied. To have a metric respect the labels filter, we have to:
// 1. Define a granular metric with ProcessLabels type parameter (see pkg/metrics/granularmetric.go).
// 2. When calling WithLabelValues, pass a ProcessLabels struct created with CreateProcessLabels.
func CreateProcessLabels(namespace, workload, pod, binary string) *metrics.ProcessLabels {
if !Config.MetricsLabelFilter["namespace"] {
namespace = ""
}
if !Config.MetricsLabelFilter["workload"] {
workload = ""
}
if !Config.MetricsLabelFilter["pod"] {
pod = ""
}
if !Config.MetricsLabelFilter["binary"] {
binary = ""
}
return metrics.NewProcessLabels(namespace, workload, pod, binary)
}