diff --git a/cmd/tetragon/conf.go b/cmd/tetragon/conf.go index 41889b1867d..1778ae7520d 100644 --- a/cmd/tetragon/conf.go +++ b/cmd/tetragon/conf.go @@ -44,15 +44,15 @@ func readConfigSettings(defaultConfDir string, defaultConfDropIn string, dropIns option.ReadConfigDir(defaultConfDropIn) // Read now the passed key --config-dir - if viper.IsSet(keyConfigDir) { - configDir := viper.GetString(keyConfigDir) + if viper.IsSet(option.KeyConfigDir) { + configDir := viper.GetString(option.KeyConfigDir) // viper.IsSet could return true on an empty string reset if configDir != "" { err := option.ReadConfigDir(configDir) if err != nil { - log.WithField(keyConfigDir, configDir).WithError(err).Fatal("Failed to read config from directory") + log.WithField(option.KeyConfigDir, configDir).WithError(err).Fatal("Failed to read config from directory") } else { - log.WithField(keyConfigDir, configDir).Info("Loaded config from directory") + log.WithField(option.KeyConfigDir, configDir).Info("Loaded config from directory") } } } diff --git a/cmd/tetragon/conf_test.go b/cmd/tetragon/conf_test.go index e6fee535a63..ebd3f263c21 100644 --- a/cmd/tetragon/conf_test.go +++ b/cmd/tetragon/conf_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/cilium/tetragon/pkg/defaults" + "github.com/cilium/tetragon/pkg/option" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/stretchr/testify/require" @@ -36,13 +37,13 @@ var ( description: "Test n0 Default configuration", // expected options: default options nothing changes expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: defaults.DefaultTetragonLib, - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(10000), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: defaults.DefaultTetragonLib, + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(10000), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -77,13 +78,13 @@ var ( // expected options: all zeroed / cleared values // As we write empty drop-ins inside /usr/lib/tetragon/tetragon.conf.d/ directory expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -91,13 +92,13 @@ var ( dropIn: true, write: true, // write empty values options: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -125,13 +126,13 @@ var ( { description: "Test n2 Drop-in /usr/lib/tetragon/tetragon.conf.d/", expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "/var/log/tetragon.log_0", - keyHubbleLib: "/usr/lib/tetragon/bpf/_0", - keyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(10000), + option.KeyConfigDir: "", + option.KeyExportFilename: "/var/log/tetragon.log_0", + option.KeyHubbleLib: "/usr/lib/tetragon/bpf/_0", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(10000), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -139,9 +140,9 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_0", - keyHubbleLib: "/usr/lib/tetragon/bpf/_0", - keyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", + option.KeyExportFilename: "/var/log/tetragon.log_0", + option.KeyHubbleLib: "/usr/lib/tetragon/bpf/_0", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -171,13 +172,13 @@ var ( // expected options: all zeroed / cleared values // As we write empty drop-ins inside /usr/local/lib/tetragon/tetragon.conf.d/ directory expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -190,13 +191,13 @@ var ( dropIn: true, write: true, // write empty values options: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, }, { // /etc/tetragon/tetragon.yaml @@ -219,13 +220,13 @@ var ( { description: "Test n4 Drop-in /usr/local/lib/tetragon/tetragon.conf.d/", expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "/var/log/tetragon.log_1", - keyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", - keyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", - keyVerbosity: 1, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(10000), + option.KeyConfigDir: "", + option.KeyExportFilename: "/var/log/tetragon.log_1", + option.KeyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", + option.KeyVerbosity: 1, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(10000), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -233,11 +234,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_0", - keyHubbleLib: "/usr/lib/tetragon/bpf/_0", - keyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", - keyVerbosity: 0, - keyEventQueueSize: uint(0), + option.KeyExportFilename: "/var/log/tetragon.log_0", + option.KeyHubbleLib: "/usr/lib/tetragon/bpf/_0", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", + option.KeyVerbosity: 0, + option.KeyEventQueueSize: uint(0), }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -245,11 +246,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_1", - keyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", - keyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", - keyVerbosity: 1, - keyEventQueueSize: uint(10000), + option.KeyExportFilename: "/var/log/tetragon.log_1", + option.KeyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", + option.KeyVerbosity: 1, + option.KeyEventQueueSize: uint(10000), }, }, { // /etc/tetragon/tetragon.yaml @@ -274,13 +275,13 @@ var ( // expected options: all zeroed / cleared values // As we write empty /etc/tetragon/tetragon.yaml file expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -288,10 +289,10 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_0", - keyHubbleLib: "/usr/lib/tetragon/bpf/_0", - keyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", - keyVerbosity: 1, + option.KeyExportFilename: "/var/log/tetragon.log_0", + option.KeyHubbleLib: "/usr/lib/tetragon/bpf/_0", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", + option.KeyVerbosity: 1, }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -299,10 +300,10 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_1", - keyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", - keyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", - keyVerbosity: 2, + option.KeyExportFilename: "/var/log/tetragon.log_1", + option.KeyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", + option.KeyVerbosity: 2, }, }, { // /etc/tetragon/tetragon.yaml @@ -310,13 +311,13 @@ var ( dropIn: false, write: true, // write empty values options: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, }, { // /etc/tetragon/tetragon.conf.d/ @@ -336,13 +337,13 @@ var ( // expected options: partial update // As we write /etc/tetragon/tetragon.yaml file expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: defaults.DefaultTetragonLib, - keyBTF: "/sys/kernel/btf/vmlinux", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(10000), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: defaults.DefaultTetragonLib, + option.KeyBTF: "/sys/kernel/btf/vmlinux", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(10000), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -361,7 +362,7 @@ var ( write: true, // write values // Partial update only btf options: map[string]interface{}{ - keyBTF: "/sys/kernel/btf/vmlinux", + option.KeyBTF: "/sys/kernel/btf/vmlinux", }, }, { // /etc/tetragon/tetragon.conf.d/ @@ -380,13 +381,13 @@ var ( // Retest default values, assert our testing logic description: "Test n7 Re-test default values", expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: defaults.DefaultTetragonLib, - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(10000), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: defaults.DefaultTetragonLib, + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(10000), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -419,13 +420,13 @@ var ( { description: "Test n8 /etc/tetragon/tetragon.yaml", expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "/var/run/tetragon/tetragon.log_2", - keyHubbleLib: "/var/lib/tetragon/bpf/_2", - keyBTF: "/sys/kernel/btf/vmlinux-etc-tetragon.yaml_2", - keyVerbosity: 2, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(20000), + option.KeyConfigDir: "", + option.KeyExportFilename: "/var/run/tetragon/tetragon.log_2", + option.KeyHubbleLib: "/var/lib/tetragon/bpf/_2", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc-tetragon.yaml_2", + option.KeyVerbosity: 2, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(20000), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -433,11 +434,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_0", - keyHubbleLib: "/usr/lib/tetragon/bpf/_0", - keyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", - keyVerbosity: 0, - keyEventQueueSize: uint(5000), + option.KeyExportFilename: "/var/log/tetragon.log_0", + option.KeyHubbleLib: "/usr/lib/tetragon/bpf/_0", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", + option.KeyVerbosity: 0, + option.KeyEventQueueSize: uint(5000), }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -445,10 +446,10 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_1", - keyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", - keyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", - keyVerbosity: 1, + option.KeyExportFilename: "/var/log/tetragon.log_1", + option.KeyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", + option.KeyVerbosity: 1, }, }, { // /etc/tetragon/tetragon.yaml @@ -456,12 +457,12 @@ var ( dropIn: false, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/run/tetragon/tetragon.log_2", - keyHubbleLib: "/var/lib/tetragon/bpf/_2", - keyBTF: "/sys/kernel/btf/vmlinux-etc-tetragon.yaml_2", - keyVerbosity: 2, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(20000), + option.KeyExportFilename: "/var/run/tetragon/tetragon.log_2", + option.KeyHubbleLib: "/var/lib/tetragon/bpf/_2", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc-tetragon.yaml_2", + option.KeyVerbosity: 2, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(20000), }, }, { // /etc/tetragon/tetragon.conf.d/ @@ -481,13 +482,13 @@ var ( // expected options: all zeroed / cleared values // As we write empty drop-ins inside /etc/tetragon/tetragon.conf.d/ directory expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -510,13 +511,13 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, }, { // config-dir @@ -529,13 +530,13 @@ var ( { description: "Test n10 Drop-in /etc/tetragon/tetragon.conf.d/", expectedOptions: map[string]interface{}{ - keyConfigDir: "", - keyExportFilename: "/var/log/tetragon.log_3", - keyHubbleLib: "/var/lib/tetragon/_3", - keyBTF: "/sys/kernel/btf/vmlinux-etc_3", - keyVerbosity: 3, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "", + option.KeyExportFilename: "/var/log/tetragon.log_3", + option.KeyHubbleLib: "/var/lib/tetragon/_3", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc_3", + option.KeyVerbosity: 3, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(30000), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -543,11 +544,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_0", - keyHubbleLib: "/usr/lib/tetragon/bpf/_0", - keyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", - keyVerbosity: 0, - keyEventQueueSize: uint(5000), + option.KeyExportFilename: "/var/log/tetragon.log_0", + option.KeyHubbleLib: "/usr/lib/tetragon/bpf/_0", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", + option.KeyVerbosity: 0, + option.KeyEventQueueSize: uint(5000), }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -555,11 +556,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_1", - keyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", - keyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", - keyVerbosity: 1, - keyEventQueueSize: uint(10000), + option.KeyExportFilename: "/var/log/tetragon.log_1", + option.KeyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", + option.KeyVerbosity: 1, + option.KeyEventQueueSize: uint(10000), }, }, { // /etc/tetragon/tetragon.yaml @@ -567,12 +568,12 @@ var ( dropIn: false, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/run/tetragon/tetragon.log_2", - keyHubbleLib: "/var/lib/tetragon/bpf/_2", - keyBTF: "/sys/kernel/btf/vmlinux-etc-tetragon.yaml_2", - keyVerbosity: 2, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(20000), + option.KeyExportFilename: "/var/run/tetragon/tetragon.log_2", + option.KeyHubbleLib: "/var/lib/tetragon/bpf/_2", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc-tetragon.yaml_2", + option.KeyVerbosity: 2, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(20000), }, }, { // /etc/tetragon/tetragon.conf.d/ @@ -580,11 +581,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_3", - keyHubbleLib: "/var/lib/tetragon/_3", - keyBTF: "/sys/kernel/btf/vmlinux-etc_3", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyExportFilename: "/var/log/tetragon.log_3", + option.KeyHubbleLib: "/var/lib/tetragon/_3", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc_3", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // config-dir @@ -599,13 +600,13 @@ var ( // expected options: all zeroed / cleared values // As we write empty drop-ins inside --config-dir directory expectedOptions: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/usr.lib.k8s.conf.d", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "/etc/tetragon/usr.lib.k8s.conf.d", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -613,9 +614,9 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/usr.lib.k8s.conf.d", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/usr.lib.k8s.conf.d", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -623,8 +624,8 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /etc/tetragon/tetragon.yaml @@ -632,8 +633,8 @@ var ( dropIn: false, write: true, options: map[string]interface{}{ - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /etc/tetragon/tetragon.conf.d/ @@ -641,8 +642,8 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // config-dir @@ -650,12 +651,12 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, }, }, @@ -665,13 +666,13 @@ var ( // expected options: all zeroed / cleared values // As we write empty drop-ins inside --config-dir directory expectedOptions: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/usr.local.lib.k8s.conf.d", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "/etc/tetragon/usr.local.lib.k8s.conf.d", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -679,9 +680,9 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/usr.lib.k8s.conf.d", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/usr.lib.k8s.conf.d", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -689,9 +690,9 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/usr.local.lib.k8s.conf.d", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/usr.local.lib.k8s.conf.d", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /etc/tetragon/tetragon.yaml @@ -699,8 +700,8 @@ var ( dropIn: false, write: true, options: map[string]interface{}{ - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /etc/tetragon/tetragon.conf.d/ @@ -708,8 +709,8 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // config-dir @@ -717,12 +718,12 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, }, }, @@ -732,13 +733,13 @@ var ( // expected options: all zeroed / cleared values // As we write empty drop-ins inside --config-dir directory expectedOptions: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -746,9 +747,9 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/usr.lib.k8s.conf.d", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/usr.lib.k8s.conf.d", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -756,9 +757,9 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/usr.local.lib.k8s.conf.d", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/usr.local.lib.k8s.conf.d", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /etc/tetragon/tetragon.yaml @@ -766,9 +767,9 @@ var ( dropIn: false, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /etc/tetragon/tetragon.conf.d/ @@ -776,8 +777,8 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // config-dir @@ -785,12 +786,12 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, }, }, @@ -800,13 +801,13 @@ var ( // expected options: all zeroed / cleared values // As we write empty drop-ins inside --config-dir directory expectedOptions: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/tetragon.k8s.conf.d", - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyConfigDir: "/etc/tetragon/tetragon.k8s.conf.d", + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -814,9 +815,9 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/usr.lib.k8s.conf.d", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/usr.lib.k8s.conf.d", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -824,9 +825,9 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/usr.local.lib.k8s.conf.d", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/usr.local.lib.k8s.conf.d", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /etc/tetragon/tetragon.yaml @@ -834,9 +835,9 @@ var ( dropIn: false, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // /etc/tetragon/tetragon.conf.d/ @@ -844,9 +845,9 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/tetragon.k8s.conf.d", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/tetragon.k8s.conf.d", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // config-dir @@ -854,12 +855,12 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "", - keyHubbleLib: "", - keyBTF: "", - keyVerbosity: 0, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(0), + option.KeyExportFilename: "", + option.KeyHubbleLib: "", + option.KeyBTF: "", + option.KeyVerbosity: 0, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(0), }, }, }, @@ -867,13 +868,13 @@ var ( { description: "Test n15 Drop-in --config-dir from /etc/tetragon/tetragon.yaml", expectedOptions: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", - keyExportFilename: "/var/log/tetragon.log_4", - keyHubbleLib: "/var/lib/tetragon/_4", - keyBTF: "/sys/kernel/btf/vmlinux-etc_4", - keyVerbosity: 4, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(40000), + option.KeyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", + option.KeyExportFilename: "/var/log/tetragon.log_4", + option.KeyHubbleLib: "/var/lib/tetragon/_4", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc_4", + option.KeyVerbosity: 4, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(40000), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -881,11 +882,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_0", - keyHubbleLib: "/usr/lib/tetragon/bpf/_0", - keyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", - keyVerbosity: 0, - keyEventQueueSize: uint(5000), + option.KeyExportFilename: "/var/log/tetragon.log_0", + option.KeyHubbleLib: "/usr/lib/tetragon/bpf/_0", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", + option.KeyVerbosity: 0, + option.KeyEventQueueSize: uint(5000), }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -893,11 +894,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_1", - keyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", - keyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", - keyVerbosity: 1, - keyEventQueueSize: uint(10000), + option.KeyExportFilename: "/var/log/tetragon.log_1", + option.KeyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", + option.KeyVerbosity: 1, + option.KeyEventQueueSize: uint(10000), }, }, { // /etc/tetragon/tetragon.yaml @@ -905,13 +906,13 @@ var ( dropIn: false, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", - keyExportFilename: "/var/run/tetragon/tetragon.log_2", - keyHubbleLib: "/var/lib/tetragon/bpf/_2", - keyBTF: "/sys/kernel/btf/vmlinux-etc-tetragon.yaml_2", - keyVerbosity: 2, - keyEnableK8sAPI: true, - keyEventQueueSize: uint(20000), + option.KeyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", + option.KeyExportFilename: "/var/run/tetragon/tetragon.log_2", + option.KeyHubbleLib: "/var/lib/tetragon/bpf/_2", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc-tetragon.yaml_2", + option.KeyVerbosity: 2, + option.KeyEnableK8sAPI: true, + option.KeyEventQueueSize: uint(20000), }, }, { // /etc/tetragon/tetragon.conf.d/ @@ -919,11 +920,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_3", - keyHubbleLib: "/var/lib/tetragon/_3", - keyBTF: "/sys/kernel/btf/vmlinux-etc_3", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyExportFilename: "/var/log/tetragon.log_3", + option.KeyHubbleLib: "/var/lib/tetragon/_3", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc_3", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // config-dir @@ -931,12 +932,12 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_4", - keyHubbleLib: "/var/lib/tetragon/_4", - keyBTF: "/sys/kernel/btf/vmlinux-etc_4", - keyVerbosity: 4, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(40000), + option.KeyExportFilename: "/var/log/tetragon.log_4", + option.KeyHubbleLib: "/var/lib/tetragon/_4", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc_4", + option.KeyVerbosity: 4, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(40000), }, }, }, @@ -944,13 +945,13 @@ var ( { description: "Test n16 Drop-in --config-dir from /etc/tetragon/tetragon.conf.d/", expectedOptions: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/tetragon.k8s.conf.d", - keyExportFilename: "/var/log/tetragon.log_4", - keyHubbleLib: "/var/lib/tetragon/_4", - keyBTF: "/sys/kernel/btf/vmlinux-etc_4", - keyVerbosity: 4, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(40000), + option.KeyConfigDir: "/etc/tetragon/tetragon.k8s.conf.d", + option.KeyExportFilename: "/var/log/tetragon.log_4", + option.KeyHubbleLib: "/var/lib/tetragon/_4", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc_4", + option.KeyVerbosity: 4, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(40000), }, confs: []confInput{ { // /usr/lib/tetragon/tetragon.conf.d/ @@ -958,11 +959,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_0", - keyHubbleLib: "/usr/lib/tetragon/bpf/_0", - keyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", - keyVerbosity: 0, - keyEventQueueSize: uint(5000), + option.KeyExportFilename: "/var/log/tetragon.log_0", + option.KeyHubbleLib: "/usr/lib/tetragon/bpf/_0", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-lib_0", + option.KeyVerbosity: 0, + option.KeyEventQueueSize: uint(5000), }, }, { // /usr/local/lib/tetragon/tetragon.conf.d/ @@ -970,11 +971,11 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_1", - keyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", - keyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", - keyVerbosity: 1, - keyEventQueueSize: uint(10000), + option.KeyExportFilename: "/var/log/tetragon.log_1", + option.KeyHubbleLib: "/usr/local/lib/tetragon/bpf/_1", + option.KeyBTF: "/sys/kernel/btf/vmlinux-usr-local-lib_1", + option.KeyVerbosity: 1, + option.KeyEventQueueSize: uint(10000), }, }, { // /etc/tetragon/tetragon.yaml @@ -982,13 +983,13 @@ var ( dropIn: false, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", - keyExportFilename: "/var/run/tetragon/tetragon.log_2", - keyHubbleLib: "/var/lib/tetragon/bpf/_2", - keyBTF: "/sys/kernel/btf/vmlinux-etc-tetragon.yaml_2", - keyVerbosity: 2, - keyEnableK8sAPI: true, - keyEventQueueSize: uint(20000), + option.KeyConfigDir: "/etc/tetragon/tetragon.yaml.k8s.conf.d", + option.KeyExportFilename: "/var/run/tetragon/tetragon.log_2", + option.KeyHubbleLib: "/var/lib/tetragon/bpf/_2", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc-tetragon.yaml_2", + option.KeyVerbosity: 2, + option.KeyEnableK8sAPI: true, + option.KeyEventQueueSize: uint(20000), }, }, { // /etc/tetragon/tetragon.conf.d/ @@ -996,12 +997,12 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyConfigDir: "/etc/tetragon/tetragon.k8s.conf.d", - keyExportFilename: "/var/log/tetragon.log_3", - keyHubbleLib: "/var/lib/tetragon/_3", - keyBTF: "/sys/kernel/btf/vmlinux-etc_3", - keyVerbosity: 3, - keyEventQueueSize: uint(30000), + option.KeyConfigDir: "/etc/tetragon/tetragon.k8s.conf.d", + option.KeyExportFilename: "/var/log/tetragon.log_3", + option.KeyHubbleLib: "/var/lib/tetragon/_3", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc_3", + option.KeyVerbosity: 3, + option.KeyEventQueueSize: uint(30000), }, }, { // config-dir @@ -1009,12 +1010,12 @@ var ( dropIn: true, write: true, options: map[string]interface{}{ - keyExportFilename: "/var/log/tetragon.log_4", - keyHubbleLib: "/var/lib/tetragon/_4", - keyBTF: "/sys/kernel/btf/vmlinux-etc_4", - keyVerbosity: 4, - keyEnableK8sAPI: false, - keyEventQueueSize: uint(40000), + option.KeyExportFilename: "/var/log/tetragon.log_4", + option.KeyHubbleLib: "/var/lib/tetragon/_4", + option.KeyBTF: "/sys/kernel/btf/vmlinux-etc_4", + option.KeyVerbosity: 4, + option.KeyEnableK8sAPI: false, + option.KeyEventQueueSize: uint(40000), }, }, }, @@ -1151,13 +1152,13 @@ func TestReadConfigSettings(t *testing.T) { } flags := rootCmd.PersistentFlags() - flags.String(keyConfigDir, "", "Configuration directory that contains a file for each option") - flags.String(keyHubbleLib, defaults.DefaultTetragonLib, "Location of Tetragon libs (btf and bpf files)") - flags.String(keyBTF, "", "Location of btf") - flags.String(keyExportFilename, "", "Filename for JSON export. Disabled by default") - flags.Int(keyVerbosity, 0, "set verbosity level for eBPF verifier dumps. Pass 0 for silent, 1 for truncated logs, 2 for a full dump") - flags.Bool(keyEnableK8sAPI, false, "Access Kubernetes API to associate tetragon events with Kubernetes pods") - flags.Uint(keyEventQueueSize, 10000, "Set the size of the internal event queue.") + flags.String(option.KeyConfigDir, "", "Configuration directory that contains a file for each option") + flags.String(option.KeyHubbleLib, defaults.DefaultTetragonLib, "Location of Tetragon libs (btf and bpf files)") + flags.String(option.KeyBTF, "", "Location of btf") + flags.String(option.KeyExportFilename, "", "Filename for JSON export. Disabled by default") + flags.Int(option.KeyVerbosity, 0, "set verbosity level for eBPF verifier dumps. Pass 0 for silent, 1 for truncated logs, 2 for a full dump") + flags.Bool(option.KeyEnableK8sAPI, false, "Access Kubernetes API to associate tetragon events with Kubernetes pods") + flags.Uint(option.KeyEventQueueSize, 10000, "Set the size of the internal event queue.") viper.BindPFlags(flags) t.Run(c.description, func(t *testing.T) { rootCmd.Execute() diff --git a/cmd/tetragon/flags.go b/cmd/tetragon/flags.go deleted file mode 100644 index 6aa46a72816..00000000000 --- a/cmd/tetragon/flags.go +++ /dev/null @@ -1,158 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright Authors of Tetragon - -package main - -import ( - "github.com/cilium/tetragon/pkg/logger" - "github.com/cilium/tetragon/pkg/metrics/metricsconfig" - "github.com/cilium/tetragon/pkg/option" - - "github.com/spf13/viper" -) - -const ( - keyConfigDir = "config-dir" - keyDebug = "debug" - keyHubbleLib = "bpf-lib" - keyBTF = "btf" - keyProcFS = "procfs" - keyKernelVersion = "kernel" - keyVerbosity = "verbose" - keyProcessCacheSize = "process-cache-size" - keyDataCacheSize = "data-cache-size" - keyForceSmallProgs = "force-small-progs" - keyForceLargeProgs = "force-large-progs" - - keyLogLevel = "log-level" - keyLogFormat = "log-format" - - keyEnableK8sAPI = "enable-k8s-api" - keyK8sKubeConfigPath = "k8s-kubeconfig-path" - keyEnableProcessAncestors = "enable-process-ancestors" - - keyMetricsServer = "metrics-server" - keyMetricsLabelFilter = "metrics-label-filter" - keyServerAddress = "server-address" - keyGopsAddr = "gops-address" - keyEnableProcessCred = "enable-process-cred" - keyEnableProcessNs = "enable-process-ns" - keyTracingPolicy = "tracing-policy" - keyTracingPolicyDir = "tracing-policy-dir" - - keyCpuProfile = "cpuprofile" - keyMemProfile = "memprofile" - keyPprofAddr = "pprof-addr" - - keyExportFilename = "export-filename" - keyExportFileMaxSizeMB = "export-file-max-size-mb" - keyExportFileRotationInterval = "export-file-rotation-interval" - keyExportFileMaxBackups = "export-file-max-backups" - keyExportFileCompress = "export-file-compress" - keyExportRateLimit = "export-rate-limit" - keyExportFilePerm = "export-file-perm" - - keyEnableExportAggregation = "enable-export-aggregation" - keyExportAggregationWindowSize = "export-aggregation-window-size" - keyExportAggregationBufferSize = "export-aggregation-buffer-size" - - keyExportAllowlist = "export-allowlist" - keyExportDenylist = "export-denylist" - - keyFieldFilters = "field-filters" - - keyNetnsDir = "netns-dir" - - keyDisableKprobeMulti = "disable-kprobe-multi" - - keyRBSize = "rb-size" - keyRBSizeTotal = "rb-size-total" - keyRBQueueSize = "rb-queue-size" - - keyEventQueueSize = "event-queue-size" - - keyReleasePinnedBPF = "release-pinned-bpf" - - keyEnablePolicyFilter = "enable-policy-filter" - keyEnablePolicyFilterDebug = "enable-policy-filter-debug" - - keyEnablePidSetFilter = "enable-pid-set-filter" - - keyEnableMsgHandlingLatency = "enable-msg-handling-latency" - - keyKmods = "kmods" - - keyEnablePodInfo = "enable-pod-info" - - keyExposeKernelAddresses = "expose-kernel-addresses" -) - -func readAndSetFlags() { - option.Config.HubbleLib = viper.GetString(keyHubbleLib) - option.Config.BTF = viper.GetString(keyBTF) - option.Config.ProcFS = viper.GetString(keyProcFS) - option.Config.KernelVersion = viper.GetString(keyKernelVersion) - option.Config.Verbosity = viper.GetInt(keyVerbosity) - option.Config.ForceSmallProgs = viper.GetBool(keyForceSmallProgs) - option.Config.ForceLargeProgs = viper.GetBool(keyForceLargeProgs) - option.Config.Debug = viper.GetBool(keyDebug) - - option.Config.EnableProcessCred = viper.GetBool(keyEnableProcessCred) - option.Config.EnableProcessNs = viper.GetBool(keyEnableProcessNs) - option.Config.EnableK8s = viper.GetBool(keyEnableK8sAPI) - option.Config.K8sKubeConfigPath = viper.GetString(keyK8sKubeConfigPath) - - option.Config.DisableKprobeMulti = viper.GetBool(keyDisableKprobeMulti) - - option.Config.RBSize = viper.GetInt(keyRBSize) - option.Config.RBSizeTotal = viper.GetInt(keyRBSizeTotal) - option.Config.RBQueueSize = viper.GetInt(keyRBQueueSize) - - option.Config.GopsAddr = viper.GetString(keyGopsAddr) - - logLevel := viper.GetString(keyLogLevel) - logFormat := viper.GetString(keyLogFormat) - logger.PopulateLogOpts(option.Config.LogOpts, logLevel, logFormat) - - option.Config.ProcessCacheSize = viper.GetInt(keyProcessCacheSize) - option.Config.DataCacheSize = viper.GetInt(keyDataCacheSize) - - option.Config.MetricsServer = viper.GetString(keyMetricsServer) - option.Config.MetricsLabelFilter = metricsconfig.ParseMetricsLabelFilter(viper.GetString(keyMetricsLabelFilter)) - option.Config.ServerAddress = viper.GetString(keyServerAddress) - - option.Config.ExportFilename = viper.GetString(keyExportFilename) - option.Config.ExportFileMaxSizeMB = viper.GetInt(keyExportFileMaxSizeMB) - option.Config.ExportFileRotationInterval = viper.GetDuration(keyExportFileRotationInterval) - option.Config.ExportFileMaxBackups = viper.GetInt(keyExportFileMaxBackups) - option.Config.ExportFileCompress = viper.GetBool(keyExportFileCompress) - option.Config.ExportRateLimit = viper.GetInt(keyExportRateLimit) - option.Config.ExportFilePerm = viper.GetString(keyExportFilePerm) - - option.Config.EnableExportAggregation = viper.GetBool(keyEnableExportAggregation) - option.Config.ExportAggregationWindowSize = viper.GetDuration(keyExportAggregationWindowSize) - option.Config.ExportAggregationBufferSize = viper.GetUint64(keyExportAggregationBufferSize) - - option.Config.CpuProfile = viper.GetString(keyCpuProfile) - option.Config.MemProfile = viper.GetString(keyMemProfile) - option.Config.PprofAddr = viper.GetString(keyPprofAddr) - - option.Config.EventQueueSize = viper.GetUint(keyEventQueueSize) - - option.Config.ReleasePinned = viper.GetBool(keyReleasePinnedBPF) - option.Config.EnablePolicyFilter = viper.GetBool(keyEnablePolicyFilter) - option.Config.EnablePolicyFilterDebug = viper.GetBool(keyEnablePolicyFilterDebug) - option.Config.EnableMsgHandlingLatency = viper.GetBool(keyEnableMsgHandlingLatency) - - option.Config.EnablePidSetFilter = viper.GetBool(keyEnablePidSetFilter) - - option.Config.TracingPolicyDir = viper.GetString(keyTracingPolicyDir) - - option.Config.KMods = viper.GetStringSlice(keyKmods) - - option.Config.EnablePodInfo = viper.GetBool(keyEnablePodInfo) - - option.Config.TracingPolicy = viper.GetString(keyTracingPolicy) - - option.Config.ExposeKernelAddresses = viper.GetBool(keyExposeKernelAddresses) -} diff --git a/cmd/tetragon/main.go b/cmd/tetragon/main.go index 31b4e764f88..e730aebdee8 100644 --- a/cmd/tetragon/main.go +++ b/cmd/tetragon/main.go @@ -73,11 +73,11 @@ var ( ) func getExportFilters() ([]*tetragon.Filter, []*tetragon.Filter, error) { - allowList, err := filters.ParseFilterList(viper.GetString(keyExportAllowlist), viper.GetBool(keyEnablePidSetFilter)) + allowList, err := filters.ParseFilterList(viper.GetString(option.KeyExportAllowlist), viper.GetBool(option.KeyEnablePidSetFilter)) if err != nil { return nil, nil, err } - denyList, err := filters.ParseFilterList(viper.GetString(keyExportDenylist), viper.GetBool(keyEnablePidSetFilter)) + denyList, err := filters.ParseFilterList(viper.GetString(option.KeyExportDenylist), viper.GetBool(option.KeyEnablePidSetFilter)) if err != nil { return nil, nil, err } @@ -85,7 +85,7 @@ func getExportFilters() ([]*tetragon.Filter, []*tetragon.Filter, error) { } func getFieldFilters() ([]*tetragon.FieldFilter, error) { - fieldFilters := viper.GetString(keyFieldFilters) + fieldFilters := viper.GetString(option.KeyFieldFilters) filters, err := filters.ParseFieldFilterList(fieldFilters) if err != nil { @@ -172,8 +172,8 @@ func tetragonExecute() error { log.Info("Force loading smallprograms") } - if viper.IsSet(keyNetnsDir) { - defaults.NetnsDir = viper.GetString(keyNetnsDir) + if viper.IsSet(option.KeyNetnsDir) { + defaults.NetnsDir = viper.GetString(option.KeyNetnsDir) } checkprocfs.Check() @@ -584,7 +584,7 @@ func startExporter(ctx context.Context, server *server.Server) error { perms, err := fileutils.RegularFilePerms(option.Config.ExportFilePerm) if err != nil { log.WithError(err).Warnf("Failed to parse export file permission '%s', failing back to %v", - keyExportFilePerm, perms) + option.KeyExportFilePerm, perms) } writer.FileMode = perms @@ -709,7 +709,7 @@ func execute() error { Use: "tetragon", Short: "Tetragon - eBPF-based Security Observability and Runtime Enforcement", Run: func(cmd *cobra.Command, args []string) { - readAndSetFlags() + option.ReadAndSetFlags() if err := startGopsServer(); err != nil { log.WithError(err).Fatal("Failed to start gops") @@ -727,96 +727,96 @@ func execute() error { flags := rootCmd.PersistentFlags() - flags.String(keyConfigDir, "", "Configuration directory that contains a file for each option") - flags.BoolP(keyDebug, "d", false, "Enable debug messages. Equivalent to '--log-level=debug'") - flags.String(keyHubbleLib, defaults.DefaultTetragonLib, "Location of Tetragon libs (btf and bpf files)") - flags.String(keyBTF, "", "Location of btf") - - flags.String(keyProcFS, "/proc/", "Location of procfs to consume existing PIDs") - flags.String(keyKernelVersion, "", "Kernel version") - flags.Int(keyVerbosity, 0, "set verbosity level for eBPF verifier dumps. Pass 0 for silent, 1 for truncated logs, 2 for a full dump") - flags.Int(keyProcessCacheSize, 65536, "Size of the process cache") - flags.Int(keyDataCacheSize, 1024, "Size of the data events cache") - flags.Bool(keyForceSmallProgs, false, "Force loading small programs, even in kernels with >= 5.3 versions") - flags.Bool(keyForceLargeProgs, false, "Force loading large programs, even in kernels with < 5.3 versions") - flags.String(keyExportFilename, "", "Filename for JSON export. Disabled by default") - flags.Int(keyExportFileMaxSizeMB, 10, "Size in MB for rotating JSON export files") - flags.Duration(keyExportFileRotationInterval, 0, "Interval at which to rotate JSON export files in addition to rotating them by size") - flags.Int(keyExportFileMaxBackups, 5, "Number of rotated JSON export files to retain") - flags.Bool(keyExportFileCompress, false, "Compress rotated JSON export files") - flags.String(keyExportFilePerm, defaults.DefaultLogsPermission, "Access permissions on JSON export files") - flags.Int(keyExportRateLimit, -1, "Rate limit (per minute) for event export. Set to -1 to disable") - flags.String(keyLogLevel, "info", "Set log level") - flags.String(keyLogFormat, "text", "Set log format") - flags.Bool(keyEnableK8sAPI, false, "Access Kubernetes API to associate Tetragon events with Kubernetes pods") - flags.String(keyK8sKubeConfigPath, "", "Absolute path of the kubernetes kubeconfig file") - flags.Bool(keyEnableProcessAncestors, true, "Include ancestors in process exec events") - flags.String(keyMetricsServer, "", "Metrics server address (e.g. ':2112'). Disabled by default") - flags.String(keyServerAddress, "localhost:54321", "gRPC server address (e.g. 'localhost:54321' or 'unix:///var/run/tetragon/tetragon.sock'") - flags.String(keyGopsAddr, "", "gops server address (e.g. 'localhost:8118'). Disabled by default") - flags.Bool(keyEnableProcessCred, false, "Enable process_cred events") - flags.Bool(keyEnableProcessNs, false, "Enable namespace information in process_exec and process_kprobe events") - flags.Uint(keyEventQueueSize, 10000, "Set the size of the internal event queue.") + flags.String(option.KeyConfigDir, "", "Configuration directory that contains a file for each option") + flags.BoolP(option.KeyDebug, "d", false, "Enable debug messages. Equivalent to '--log-level=debug'") + flags.String(option.KeyHubbleLib, defaults.DefaultTetragonLib, "Location of Tetragon libs (btf and bpf files)") + flags.String(option.KeyBTF, "", "Location of btf") + + flags.String(option.KeyProcFS, "/proc/", "Location of procfs to consume existing PIDs") + flags.String(option.KeyKernelVersion, "", "Kernel version") + flags.Int(option.KeyVerbosity, 0, "set verbosity level for eBPF verifier dumps. Pass 0 for silent, 1 for truncated logs, 2 for a full dump") + flags.Int(option.KeyProcessCacheSize, 65536, "Size of the process cache") + flags.Int(option.KeyDataCacheSize, 1024, "Size of the data events cache") + flags.Bool(option.KeyForceSmallProgs, false, "Force loading small programs, even in kernels with >= 5.3 versions") + flags.Bool(option.KeyForceLargeProgs, false, "Force loading large programs, even in kernels with < 5.3 versions") + flags.String(option.KeyExportFilename, "", "Filename for JSON export. Disabled by default") + flags.Int(option.KeyExportFileMaxSizeMB, 10, "Size in MB for rotating JSON export files") + flags.Duration(option.KeyExportFileRotationInterval, 0, "Interval at which to rotate JSON export files in addition to rotating them by size") + flags.Int(option.KeyExportFileMaxBackups, 5, "Number of rotated JSON export files to retain") + flags.Bool(option.KeyExportFileCompress, false, "Compress rotated JSON export files") + flags.String(option.KeyExportFilePerm, defaults.DefaultLogsPermission, "Access permissions on JSON export files") + flags.Int(option.KeyExportRateLimit, -1, "Rate limit (per minute) for event export. Set to -1 to disable") + flags.String(option.KeyLogLevel, "info", "Set log level") + flags.String(option.KeyLogFormat, "text", "Set log format") + flags.Bool(option.KeyEnableK8sAPI, false, "Access Kubernetes API to associate Tetragon events with Kubernetes pods") + flags.String(option.KeyK8sKubeConfigPath, "", "Absolute path of the kubernetes kubeconfig file") + flags.Bool(option.KeyEnableProcessAncestors, true, "Include ancestors in process exec events") + flags.String(option.KeyMetricsServer, "", "Metrics server address (e.g. ':2112'). Disabled by default") + flags.String(option.KeyServerAddress, "localhost:54321", "gRPC server address (e.g. 'localhost:54321' or 'unix:///var/run/tetragon/tetragon.sock'") + flags.String(option.KeyGopsAddr, "", "gops server address (e.g. 'localhost:8118'). Disabled by default") + flags.Bool(option.KeyEnableProcessCred, false, "Enable process_cred events") + flags.Bool(option.KeyEnableProcessNs, false, "Enable namespace information in process_exec and process_kprobe events") + flags.Uint(option.KeyEventQueueSize, 10000, "Set the size of the internal event queue.") // Tracing policy file - flags.String(keyTracingPolicy, "", "Tracing policy file to load at startup") + flags.String(option.KeyTracingPolicy, "", "Tracing policy file to load at startup") - flags.String(keyTracingPolicyDir, defaults.DefaultTpDir, "Directory from where to load Tracing Policies") + flags.String(option.KeyTracingPolicyDir, defaults.DefaultTpDir, "Directory from where to load Tracing Policies") // Options for debugging/development, not visible to users - flags.String(keyCpuProfile, "", "Store CPU profile into provided file") - flags.MarkHidden(keyCpuProfile) + flags.String(option.KeyCpuProfile, "", "Store CPU profile into provided file") + flags.MarkHidden(option.KeyCpuProfile) - flags.String(keyMemProfile, "", "Store MEM profile into provided file") - flags.MarkHidden(keyMemProfile) + flags.String(option.KeyMemProfile, "", "Store MEM profile into provided file") + flags.MarkHidden(option.KeyMemProfile) - flags.String(keyPprofAddr, "", "Profile via pprof http") - flags.MarkHidden(keyPprofAddr) + flags.String(option.KeyPprofAddr, "", "Profile via pprof http") + flags.MarkHidden(option.KeyPprofAddr) // JSON export aggregation options. - flags.Bool(keyEnableExportAggregation, false, "Enable JSON export aggregation") - flags.Duration(keyExportAggregationWindowSize, 15*time.Second, "JSON export aggregation time window") - flags.Uint64(keyExportAggregationBufferSize, 10000, "Aggregator channel buffer size") + flags.Bool(option.KeyEnableExportAggregation, false, "Enable JSON export aggregation") + flags.Duration(option.KeyExportAggregationWindowSize, 15*time.Second, "JSON export aggregation time window") + flags.Uint64(option.KeyExportAggregationBufferSize, 10000, "Aggregator channel buffer size") // JSON export filter options - flags.String(keyExportAllowlist, "", "JSON export allowlist") - flags.String(keyExportDenylist, "", "JSON export denylist") + flags.String(option.KeyExportAllowlist, "", "JSON export allowlist") + flags.String(option.KeyExportDenylist, "", "JSON export denylist") // Field filters options for export - flags.String(keyFieldFilters, "", "Field filters for event exports") + flags.String(option.KeyFieldFilters, "", "Field filters for event exports") // Network namespace options - flags.String(keyNetnsDir, "/var/run/docker/netns/", "Network namespace dir") + flags.String(option.KeyNetnsDir, "/var/run/docker/netns/", "Network namespace dir") // Allow to disable kprobe multi interface - flags.Bool(keyDisableKprobeMulti, false, "Allow to disable kprobe multi interface") + flags.Bool(option.KeyDisableKprobeMulti, false, "Allow to disable kprobe multi interface") // Allow to specify perf ring buffer size - flags.Int(keyRBSizeTotal, 0, "Set perf ring buffer size in total for all cpus (default 65k per cpu)") - flags.Int(keyRBSize, 0, "Set perf ring buffer size for single cpu (default 65k)") + flags.Int(option.KeyRBSizeTotal, 0, "Set perf ring buffer size in total for all cpus (default 65k per cpu)") + flags.Int(option.KeyRBSize, 0, "Set perf ring buffer size for single cpu (default 65k)") // Provide option to remove existing pinned BPF programs and maps in Tetragon's // observer dir on startup. Useful for doing upgrades/downgrades. Set to false to // disable. - flags.Bool(keyReleasePinnedBPF, true, "Release all pinned BPF programs and maps in Tetragon BPF directory. Enabled by default. Set to false to disable") + flags.Bool(option.KeyReleasePinnedBPF, true, "Release all pinned BPF programs and maps in Tetragon BPF directory. Enabled by default. Set to false to disable") // Provide option to enable policy filtering. Because the code is new, // this is set to false by default. - flags.Bool(keyEnablePolicyFilter, false, "Enable policy filter code (beta)") - flags.Bool(keyEnablePolicyFilterDebug, false, "Enable policy filter debug messages") + flags.Bool(option.KeyEnablePolicyFilter, false, "Enable policy filter code (beta)") + flags.Bool(option.KeyEnablePolicyFilterDebug, false, "Enable policy filter debug messages") // Provide option to enable the pidSet export filters. - flags.Bool(keyEnablePidSetFilter, false, "Enable pidSet export filters. Not recommended for production use") + flags.Bool(option.KeyEnablePidSetFilter, false, "Enable pidSet export filters. Not recommended for production use") - flags.Bool(keyEnableMsgHandlingLatency, false, "Enable metrics for message handling latency") + flags.Bool(option.KeyEnableMsgHandlingLatency, false, "Enable metrics for message handling latency") - flags.StringSlice(keyKmods, []string{}, "List of kernel modules to load symbols from") + flags.StringSlice(option.KeyKmods, []string{}, "List of kernel modules to load symbols from") - flags.Int(keyRBQueueSize, 65535, "Set size of channel between ring buffer and sensor go routines (default 65k)") + flags.Int(option.KeyRBQueueSize, 65535, "Set size of channel between ring buffer and sensor go routines (default 65k)") - flags.Bool(keyEnablePodInfo, false, "Enable PodInfo custom resource") + flags.Bool(option.KeyEnablePodInfo, false, "Enable PodInfo custom resource") - flags.Bool(keyExposeKernelAddresses, false, "Expose real kernel addresses in events stack traces") + flags.Bool(option.KeyExposeKernelAddresses, false, "Expose real kernel addresses in events stack traces") viper.BindPFlags(flags) return rootCmd.Execute() diff --git a/pkg/metrics/metricsconfig/labelfilter.go b/pkg/metrics/metricsconfig/labelfilter.go deleted file mode 100644 index 27d8f71ffda..00000000000 --- a/pkg/metrics/metricsconfig/labelfilter.go +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright Authors of Tetragon - -package metricsconfig - -import "strings" - -func ParseMetricsLabelFilter(labels string) map[string]interface{} { - result := make(map[string]interface{}) - for _, label := range strings.Split(labels, ",") { - result[label] = nil - } - return result -} diff --git a/pkg/option/flags.go b/pkg/option/flags.go new file mode 100644 index 00000000000..9ff95d61c83 --- /dev/null +++ b/pkg/option/flags.go @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Tetragon + +package option + +import ( + "strings" + + "github.com/cilium/tetragon/pkg/logger" + "github.com/spf13/viper" +) + +const ( + KeyConfigDir = "config-dir" + KeyDebug = "debug" + KeyHubbleLib = "bpf-lib" + KeyBTF = "btf" + KeyProcFS = "procfs" + KeyKernelVersion = "kernel" + KeyVerbosity = "verbose" + KeyProcessCacheSize = "process-cache-size" + KeyDataCacheSize = "data-cache-size" + KeyForceSmallProgs = "force-small-progs" + KeyForceLargeProgs = "force-large-progs" + + KeyLogLevel = "log-level" + KeyLogFormat = "log-format" + + KeyEnableK8sAPI = "enable-k8s-api" + KeyK8sKubeConfigPath = "k8s-kubeconfig-path" + KeyEnableProcessAncestors = "enable-process-ancestors" + + KeyMetricsServer = "metrics-server" + KeyMetricsLabelFilter = "metrics-label-filter" + KeyServerAddress = "server-address" + KeyGopsAddr = "gops-address" + KeyEnableProcessCred = "enable-process-cred" + KeyEnableProcessNs = "enable-process-ns" + KeyTracingPolicy = "tracing-policy" + KeyTracingPolicyDir = "tracing-policy-dir" + + KeyCpuProfile = "cpuprofile" + KeyMemProfile = "memprofile" + KeyPprofAddr = "pprof-addr" + + KeyExportFilename = "export-filename" + KeyExportFileMaxSizeMB = "export-file-max-size-mb" + KeyExportFileRotationInterval = "export-file-rotation-interval" + KeyExportFileMaxBackups = "export-file-max-backups" + KeyExportFileCompress = "export-file-compress" + KeyExportRateLimit = "export-rate-limit" + KeyExportFilePerm = "export-file-perm" + + KeyEnableExportAggregation = "enable-export-aggregation" + KeyExportAggregationWindowSize = "export-aggregation-window-size" + KeyExportAggregationBufferSize = "export-aggregation-buffer-size" + + KeyExportAllowlist = "export-allowlist" + KeyExportDenylist = "export-denylist" + + KeyFieldFilters = "field-filters" + + KeyNetnsDir = "netns-dir" + + KeyDisableKprobeMulti = "disable-kprobe-multi" + + KeyRBSize = "rb-size" + KeyRBSizeTotal = "rb-size-total" + KeyRBQueueSize = "rb-queue-size" + + KeyEventQueueSize = "event-queue-size" + + KeyReleasePinnedBPF = "release-pinned-bpf" + + KeyEnablePolicyFilter = "enable-policy-filter" + KeyEnablePolicyFilterDebug = "enable-policy-filter-debug" + + KeyEnablePidSetFilter = "enable-pid-set-filter" + + KeyEnableMsgHandlingLatency = "enable-msg-handling-latency" + + KeyKmods = "kmods" + + KeyEnablePodInfo = "enable-pod-info" + + KeyExposeKernelAddresses = "expose-kernel-addresses" +) + +func ReadAndSetFlags() { + Config.HubbleLib = viper.GetString(KeyHubbleLib) + Config.BTF = viper.GetString(KeyBTF) + Config.ProcFS = viper.GetString(KeyProcFS) + Config.KernelVersion = viper.GetString(KeyKernelVersion) + Config.Verbosity = viper.GetInt(KeyVerbosity) + Config.ForceSmallProgs = viper.GetBool(KeyForceSmallProgs) + Config.ForceLargeProgs = viper.GetBool(KeyForceLargeProgs) + Config.Debug = viper.GetBool(KeyDebug) + + Config.EnableProcessCred = viper.GetBool(KeyEnableProcessCred) + Config.EnableProcessNs = viper.GetBool(KeyEnableProcessNs) + Config.EnableK8s = viper.GetBool(KeyEnableK8sAPI) + Config.K8sKubeConfigPath = viper.GetString(KeyK8sKubeConfigPath) + + Config.DisableKprobeMulti = viper.GetBool(KeyDisableKprobeMulti) + + Config.RBSize = viper.GetInt(KeyRBSize) + Config.RBSizeTotal = viper.GetInt(KeyRBSizeTotal) + Config.RBQueueSize = viper.GetInt(KeyRBQueueSize) + + Config.GopsAddr = viper.GetString(KeyGopsAddr) + + logLevel := viper.GetString(KeyLogLevel) + logFormat := viper.GetString(KeyLogFormat) + logger.PopulateLogOpts(Config.LogOpts, logLevel, logFormat) + + Config.ProcessCacheSize = viper.GetInt(KeyProcessCacheSize) + Config.DataCacheSize = viper.GetInt(KeyDataCacheSize) + + Config.MetricsServer = viper.GetString(KeyMetricsServer) + Config.MetricsLabelFilter = ParseMetricsLabelFilter(viper.GetString(KeyMetricsLabelFilter)) + Config.ServerAddress = viper.GetString(KeyServerAddress) + + Config.ExportFilename = viper.GetString(KeyExportFilename) + Config.ExportFileMaxSizeMB = viper.GetInt(KeyExportFileMaxSizeMB) + Config.ExportFileRotationInterval = viper.GetDuration(KeyExportFileRotationInterval) + Config.ExportFileMaxBackups = viper.GetInt(KeyExportFileMaxBackups) + Config.ExportFileCompress = viper.GetBool(KeyExportFileCompress) + Config.ExportRateLimit = viper.GetInt(KeyExportRateLimit) + Config.ExportFilePerm = viper.GetString(KeyExportFilePerm) + + Config.EnableExportAggregation = viper.GetBool(KeyEnableExportAggregation) + Config.ExportAggregationWindowSize = viper.GetDuration(KeyExportAggregationWindowSize) + Config.ExportAggregationBufferSize = viper.GetUint64(KeyExportAggregationBufferSize) + + Config.CpuProfile = viper.GetString(KeyCpuProfile) + Config.MemProfile = viper.GetString(KeyMemProfile) + Config.PprofAddr = viper.GetString(KeyPprofAddr) + + Config.EventQueueSize = viper.GetUint(KeyEventQueueSize) + + Config.ReleasePinned = viper.GetBool(KeyReleasePinnedBPF) + Config.EnablePolicyFilter = viper.GetBool(KeyEnablePolicyFilter) + Config.EnablePolicyFilterDebug = viper.GetBool(KeyEnablePolicyFilterDebug) + Config.EnableMsgHandlingLatency = viper.GetBool(KeyEnableMsgHandlingLatency) + + Config.EnablePidSetFilter = viper.GetBool(KeyEnablePidSetFilter) + + Config.TracingPolicyDir = viper.GetString(KeyTracingPolicyDir) + + Config.KMods = viper.GetStringSlice(KeyKmods) + + Config.EnablePodInfo = viper.GetBool(KeyEnablePodInfo) + + Config.TracingPolicy = viper.GetString(KeyTracingPolicy) + + Config.ExposeKernelAddresses = viper.GetBool(KeyExposeKernelAddresses) +} + +func ParseMetricsLabelFilter(labels string) map[string]interface{} { + result := make(map[string]interface{}) + for _, label := range strings.Split(labels, ",") { + result[label] = nil + } + return result +}