Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func main() {
if err != nil {
klog.Exitf("list rules: %v", err)
}

klog.Infof("Loaded %d rules", len(ts))
sn := *siteName
if sn == "" {
Expand Down Expand Up @@ -143,7 +144,11 @@ func main() {
}

klog.Infof("Starting update loop: %+v", u)
go u.Loop(ctx)
go func() {
if err := u.Loop(ctx); err != nil {
panic(fmt.Errorf("update loop failed: %w", err))
}
}()

s := site.New(&site.Config{
BaseDirectory: findPath(*siteDir),
Expand Down
2 changes: 1 addition & 1 deletion pkg/triage/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (p *Party) ExecuteCollection(ctx context.Context, s Collection) (*Collectio

// SummarizeCollectionResult adds together statistics about collection results {
func SummarizeCollectionResult(os []*RuleResult) *CollectionResult {
klog.Infof("Summarizing collection result with %s rules...", len(os))
klog.Infof("Summarizing collection result with %d rules...", len(os))

r := &CollectionResult{}

Expand Down
45 changes: 42 additions & 3 deletions pkg/triage/triage.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,49 @@ func (p *Party) Load(r io.Reader) error {

p.engine.MinSimilarity = dc.Settings.MinSimilarity

if _, err := p.ListCollections(); err != nil {
return fmt.Errorf("unable to calculate collections: %v", err)
}
p.logLoaded()
if err := p.validateLoadedConfig(); err != nil {
return fmt.Errorf("validate config: %w", err)
}
return nil
}

func (p *Party) validateLoadedConfig() error {
if len(p.collections) == 0 {
return fmt.Errorf("no 'collections' defined")
}
if len(p.rules) == 0 {
return fmt.Errorf("no 'rules' defined")
}

cols, err := p.ListCollections()
if err != nil {
return fmt.Errorf("list collections: %w", err)
}

filters := 0
for _, c := range cols {
seenRule := map[string]*Rule{}

for _, tid := range c.RuleIDs {
if seenRule[tid] != nil {
return fmt.Errorf("%q has a duplicate rule: %q", c.ID, tid)
}

r, err := p.LookupRule(tid)
if err != nil {
return fmt.Errorf("lookup rule %q: %w", tid, err)
}

seenRule[tid] = &r
filters += len(r.Filters)
}
}

if filters == 0 {
return fmt.Errorf("No 'filters' found in the configuration")
}
klog.Infof("configuration defines %d filters - looking good!", filters)
return nil
}

Expand Down