Skip to content

Commit 7266606

Browse files
committed
flag(stores): new flag format
1 parent 584c3eb commit 7266606

File tree

11 files changed

+829
-381
lines changed

11 files changed

+829
-381
lines changed

pkg/cmd/cobra/cobra.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,17 @@ func GetTraceeRunner(c *cobra.Command, version string) (cmd.Runner, error) {
141141
cfg.CgroupFSPath = res.CgroupfsPath
142142
cfg.CgroupFSForce = res.CgroupfsForce
143143

144-
// Process Tree command line flags
145-
146-
procTreeFlags, err := GetFlagsFromViper("proctree")
147-
if err != nil {
148-
return runner, err
149-
}
150-
151-
procTree, err := flags.PrepareProcTree(procTreeFlags)
152-
if err != nil {
153-
return runner, err
154-
}
155-
cfg.ProcTree = procTree
156-
157-
// DNS Cache command line flags
158-
159-
dnsCacheFlags, err := GetFlagsFromViper("dnscache")
144+
// Stores command line flags
145+
storesFlags, err := GetFlagsFromViper("stores")
160146
if err != nil {
161147
return runner, err
162148
}
163-
164-
dnsCache, err := flags.PrepareDnsCache(dnsCacheFlags)
149+
stores, err := flags.PrepareStores(storesFlags)
165150
if err != nil {
166151
return runner, err
167152
}
168-
169-
cfg.DNSCacheConfig = dnsCache
153+
cfg.DNSCacheConfig = stores.DNS
154+
cfg.ProcTree = stores.Process
170155

171156
// Capture command line flags - via cobra flag
172157

pkg/cmd/cobra/config.go

Lines changed: 53 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func GetFlagsFromViper(key string) ([]string, error) {
2424
switch key {
2525
case serverflag.ServerFlag:
2626
flagger = &ServerConfig{}
27-
case "proctree":
28-
flagger = &ProcTreeConfig{}
27+
case "stores":
28+
flagger = &StoresConfig{}
2929
case "capabilities":
3030
flagger = &CapabilitiesConfig{}
3131
case "containers":
@@ -34,8 +34,6 @@ func GetFlagsFromViper(key string) ([]string, error) {
3434
flagger = &LogConfig{}
3535
case "output":
3636
flagger = &OutputConfig{}
37-
case "dnscache":
38-
flagger = &DnsCacheConfig{}
3937
default:
4038
return nil, errfmt.Errorf("unrecognized key: %s", key)
4139
}
@@ -160,64 +158,6 @@ func (c *SocketConfig) flags() []string {
160158
return flags
161159
}
162160

163-
//
164-
// proctree flag
165-
//
166-
167-
type ProcTreeConfig struct {
168-
Source string `mapstructure:"source"`
169-
Cache ProcTreeCacheConfig `mapstructure:"cache"`
170-
}
171-
172-
type ProcTreeCacheConfig struct {
173-
Process int `mapstructure:"process"`
174-
Thread int `mapstructure:"thread"`
175-
}
176-
177-
func (c *ProcTreeConfig) flags() []string {
178-
flags := make([]string, 0)
179-
180-
if c.Source != "" {
181-
if c.Source == "none" {
182-
flags = append(flags, "none")
183-
} else {
184-
flags = append(flags, fmt.Sprintf("source=%s", c.Source))
185-
}
186-
}
187-
if c.Cache.Process != 0 {
188-
flags = append(flags, fmt.Sprintf("process-cache=%d", c.Cache.Process))
189-
}
190-
if c.Cache.Thread != 0 {
191-
flags = append(flags, fmt.Sprintf("thread-cache=%d", c.Cache.Thread))
192-
}
193-
194-
return flags
195-
}
196-
197-
//
198-
// dnscache flag
199-
//
200-
201-
type DnsCacheConfig struct {
202-
Enable bool `mapstructure:"enable"`
203-
Size int `mapstructure:"size"`
204-
}
205-
206-
func (c *DnsCacheConfig) flags() []string {
207-
flags := make([]string, 0)
208-
209-
if !c.Enable {
210-
flags = append(flags, "none")
211-
return flags
212-
}
213-
214-
if c.Size != 0 {
215-
flags = append(flags, fmt.Sprintf("size=%d", c.Size))
216-
}
217-
218-
return flags
219-
}
220-
221161
//
222162
// capabilities flag
223163
//
@@ -480,3 +420,54 @@ type OutputWebhookConfig struct {
480420
GoTemplate string `mapstructure:"gotemplate"`
481421
ContentType string `mapstructure:"content-type"`
482422
}
423+
424+
//
425+
// stores flag
426+
//
427+
428+
type ProcessConfig struct {
429+
Enabled bool `mapstructure:"enabled"`
430+
Processes int `mapstructure:"processes"`
431+
Threads int `mapstructure:"threads"`
432+
Source string `mapstructure:"source"`
433+
Procfs bool `mapstructure:"use-procfs"`
434+
}
435+
436+
type DNSConfig struct {
437+
Enabled bool `mapstructure:"enabled"`
438+
Size int `mapstructure:"size"`
439+
}
440+
441+
type StoresConfig struct {
442+
DNS DNSConfig `mapstructure:"dns"`
443+
Process ProcessConfig `mapstructure:"process"`
444+
}
445+
446+
func (c *StoresConfig) flags() []string {
447+
flags := []string{}
448+
449+
if c.DNS.Enabled {
450+
flags = append(flags, fmt.Sprintf("dns.enabled=%v", c.DNS.Enabled))
451+
}
452+
if c.DNS.Size != 0 {
453+
flags = append(flags, fmt.Sprintf("dns.size=%d", c.DNS.Size))
454+
}
455+
456+
if c.Process.Enabled {
457+
flags = append(flags, fmt.Sprintf("process.enable=%v", c.Process.Enabled))
458+
}
459+
if c.Process.Processes != 0 {
460+
flags = append(flags, fmt.Sprintf("process.processes=%d", c.Process.Processes))
461+
}
462+
if c.Process.Threads != 0 {
463+
flags = append(flags, fmt.Sprintf("process.threads=%d", c.Process.Threads))
464+
}
465+
if c.Process.Source != "" {
466+
flags = append(flags, fmt.Sprintf("process.source=%s", c.Process.Source))
467+
}
468+
if c.Process.Procfs {
469+
flags = append(flags, fmt.Sprintf("process.use-procfs=%v", c.Process.Procfs))
470+
}
471+
472+
return flags
473+
}

0 commit comments

Comments
 (0)