Skip to content

Commit

Permalink
re-enabled node search path logic
Browse files Browse the repository at this point in the history
it was disabled from testing, re-enabled it

Signed-off-by: quobix <dave@quobix.com>
  • Loading branch information
daveshanley committed Jan 19, 2024
1 parent 47949ab commit 262d4e3
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions motor/rule_applicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,43 +630,41 @@ func runRule(ctx ruleContext, doneChan chan bool) {

if givenPath != "$" {

// create a timeout on this, if we can't get a result within 100ms, then
// create a timeout on this, if we can't get a result within 2s, then
// try again, but with the unresolved spec.
lookupCtx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500)
lookupCtx, cancel := context.WithTimeout(context.Background(), time.Second*2)
defer cancel()
nodesChan := make(chan []*yaml.Node)
errChan := make(chan error)
//cancelChan := make(chan bool)

go findNodes(ctx.specNode, givenPath, errChan, nodesChan)
//topBreak:
topBreak:
select {
case nodes = <-nodesChan:
break
case err = <-errChan:
fmt.Println("giving up finding nodes")
ctx.logger.Error("error looking for nodes", "path", givenPath, "rule", ctx.rule.Id, "error", err)
break
case <-lookupCtx.Done():
ctx.logger.Warn("timeout looking for nodes, trying again with unresolved spec.", "path", givenPath)
break
//
//// ok, this timed out, let's try again with the unresolved spec.
//lookupCtxFinal, finalCancel := context.WithTimeout(context.Background(), time.Millisecond*100)
//defer finalCancel()
//
//go findNodes(ctx.specNodeUnresolved, givenPath, errChan, nodesChan)
//
//select {
//case nodes = <-nodesChan:
// break
//case err = <-errChan:
// break
//case <-lookupCtxFinal.Done():
// err = fmt.Errorf("timed out looking for nodes using path '%s'", givenPath)
// ctx.logger.Error("timeout looking for unresolved nodes, giving up.", "path", givenPath, "rule",
// ctx.rule.Id)
// break topBreak
//}

// ok, this timed out, let's try again with the unresolved spec.
lookupCtxFinal, finalCancel := context.WithTimeout(context.Background(), time.Second*2)
defer finalCancel()

go findNodes(ctx.specNodeUnresolved, givenPath, errChan, nodesChan)

select {
case nodes = <-nodesChan:
break
case err = <-errChan:
break
case <-lookupCtxFinal.Done():
err = fmt.Errorf("timed out looking for nodes using path '%s'", givenPath)
ctx.logger.Error("timeout looking for unresolved nodes, giving up.", "path", givenPath, "rule",
ctx.rule.Id)
break topBreak
}
}

} else {
Expand Down

0 comments on commit 262d4e3

Please sign in to comment.