@@ -3,19 +3,17 @@ package translator
3
3
import "regexp"
4
4
5
5
func RemoveSysdigLabels (expr , excludeScope string ) string {
6
- // Remove scopes of sysdig kube_cluster_name=~$cluster for example
7
- scope := "kube_cluster_name|kube_namespace_name|kube_pod_name|kube_workload_name|kube_node_name|agent_tag_cluster|instance|node|namespace|host_hostname"
8
- if excludeScope != "" {
9
- scope = scope + "|" + excludeScope
6
+ regex := regexp .MustCompile ("" )
7
+ if excludeScope == "all" {
8
+ expr = RemoveAllScopes (expr , excludeScope )
9
+ } else {
10
+ // Remove scopes of sysdig kube_cluster_name=~$cluster for example
11
+ scope := "kube_cluster_name|kube_namespace_name|kube_pod_name|kube_workload_name|kube_node_name|agent_tag_cluster|instance|node|namespace|host_hostname"
12
+ if excludeScope != "" {
13
+ scope = scope + "|" + excludeScope
14
+ }
15
+ expr = RemoveAllScopes (expr , scope )
10
16
}
11
- regex := regexp .MustCompile ("(?:" + scope + ")" + "\\ s*(?:=|=~|!=|!~)\\ $[\\ w_]*," )
12
- expr = regex .ReplaceAllString (expr , "" )
13
- regex = regexp .MustCompile ("(?:" + scope + ")" + "\\ s*(?:=|=~|!=|!~)\" [\\ w_-]*\" ," )
14
- expr = regex .ReplaceAllString (expr , "" )
15
- regex = regexp .MustCompile ("(?:" + scope + ")" + "\\ s*(?:=|=~|!=|!~)\\ $[\\ w_]*\\ }" )
16
- expr = regex .ReplaceAllString (expr , "}" )
17
- regex = regexp .MustCompile ("(?:" + scope + ")" + "\\ s*(?:=|=~|!=|!~)\" [\\ w_-]*\" }" )
18
- expr = regex .ReplaceAllString (expr , "}" )
19
17
// Remove the sysdig aggregation
20
18
aggregation := "kube_cluster_name|kube_namespace_name|kube_pod_name|kube_workload_name|kube_node_name|agent_tag_cluster"
21
19
aggregation = aggregation + "|" + excludeScope
@@ -48,5 +46,22 @@ func RemoveSysdigLabels(expr, excludeScope string) string {
48
46
regex = regexp .MustCompile ("\\ n" )
49
47
expr = regex .ReplaceAllString (expr , "" )
50
48
// Add trailing \n, very important don't touch
49
+ regex = regexp .MustCompile ("\\ [\\ $__interval\\ ]" )
50
+ expr = regex .ReplaceAllString (expr , "[5m]" )
51
+ return expr
52
+ }
53
+
54
+ func RemoveAllScopes (expr , scope string ) string {
55
+ if scope == "all" {
56
+ scope = "\\ w"
57
+ }
58
+ regex := regexp .MustCompile ("(?:" + scope + ")+" + "\\ s*(?:=|=~|!=|!~)\\ $[\\ w_]*," )
59
+ expr = regex .ReplaceAllString (expr , "" )
60
+ regex = regexp .MustCompile ("(?:" + scope + ")+" + "\\ s*(?:=|=~|!=|!~)\" [\\ w_-]*\" ," )
61
+ expr = regex .ReplaceAllString (expr , "" )
62
+ regex = regexp .MustCompile ("(?:" + scope + ")+" + "\\ s*(?:=|=~|!=|!~)\\ $[\\ w_]*\\ }" )
63
+ expr = regex .ReplaceAllString (expr , "}" )
64
+ regex = regexp .MustCompile ("(?:" + scope + ")+" + "\\ s*(?:=|=~|!=|!~)\" [\\ w_-]*\" }" )
65
+ expr = regex .ReplaceAllString (expr , "}" )
51
66
return expr
52
67
}
0 commit comments