MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / validateRules

Function validateRules

cmd/fibratus/app/rules/validate.go:44–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42}
43
44func validateRules() error {
45 if err := bootstrap.InitConfigAndLogger(cfg); err != nil {
46 return err
47 }
48
49 isValidExt := func(path string) bool {
50 return filepath.Ext(path) == ".yml" || filepath.Ext(path) == ".yaml"
51 }
52 // load macros and rules
53 for _, m := range cfg.Filters.Macros.FromPaths {
54 paths, err := filepath.Glob(m)
55 if err != nil {
56 return err
57 }
58 for _, path := range paths {
59 if !isValidExt(path) {
60 continue
61 }
62 emo("%v Loading macros from %s\n", emoji.Hook, path)
63 }
64 }
65 if err := cfg.Filters.LoadMacros(); err != nil {
66 return fmt.Errorf("%v %v", emoji.DisappointedFace, err)
67 }
68
69 for _, r := range cfg.Filters.Rules.FromPaths {
70 paths, err := filepath.Glob(r)
71 if err != nil {
72 return err
73 }
74 for _, path := range paths {
75 if !isValidExt(path) {
76 continue
77 }
78 emo("%v Loading rule %s\n", emoji.Package, path)
79 }
80 }
81 if err := cfg.Filters.LoadFilters(); err != nil {
82 return fmt.Errorf("%v %v", emoji.DisappointedFace, err)
83 }
84 if len(cfg.GetFilters()) == 0 {
85 return fmt.Errorf("%v no rules found in %s", emoji.DisappointedFace, strings.Join(cfg.Filters.Rules.FromPaths, ","))
86 }
87
88 warnings := make([]warning, 0)
89
90 // validate rules
91 for _, rule := range cfg.GetFilters() {
92 f := filter.New(rule.Condition, cfg)
93 err := f.Compile()
94 if err != nil {
95 return fmt.Errorf("%v %v", emoji.DisappointedFace, rules.ErrInvalidFilter(rule.Name, err))
96 }
97
98 w := warning{rule: rule.Name}
99 for _, fld := range f.GetFields() {
100 if isDeprecated, dep := fields.IsDeprecated(fld.Name); isDeprecated {
101 w.addMessage(fmt.Sprintf("%s field deprecated in favor of %v", fld.Name.String(), dep.Fields))

Callers 1

validateFunction · 0.85

Calls 14

addMessageMethod · 0.95
InitConfigAndLoggerFunction · 0.92
NewFunction · 0.92
IsDeprecatedFunction · 0.92
isValidExtFunction · 0.85
emoFunction · 0.85
LoadMacrosMethod · 0.80
LoadFiltersMethod · 0.80
GetFiltersMethod · 0.80
HasLabelMethod · 0.80
PrintfMethod · 0.80
CompileMethod · 0.65

Tested by

no test coverage detected