Skip to content

Commit

Permalink
topdown: Add trace event when value is resolved externally
Browse files Browse the repository at this point in the history
When an external resolver is used we will emit a new type of trace
event. While not providing a ton of details (for now) it does at least
give some hints as to what happened with the evaluation.

Signed-off-by: Patrick East <[email protected]>
  • Loading branch information
patrick-east authored and tsandall committed Nov 6, 2020
1 parent ee7f123 commit 73efebd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion topdown/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func (e *eval) traceIndex(x ast.Node, msg string) {
e.traceEvent(IndexOp, x, msg)
}

func (e *eval) traceExternalResolve(x ast.Node) {
e.traceEvent(ExternalResolveOp, x, "")
}

func (e *eval) traceEvent(op Op, x ast.Node, msg string) {

if !e.traceEnabled {
Expand Down Expand Up @@ -1330,7 +1334,9 @@ func (e *eval) resolveReadFromStorage(ref ast.Ref, a ast.Value) (ast.Value, erro

if err != nil {
return nil, err
} else if v == nil {
} else if v != nil {
e.traceExternalResolve(e.query[e.index])
} else {

path, err := storage.NewPathForRef(ref)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions topdown/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const (
// IndexOp is emitted during an expression evaluation to represent lookup
// matches.
IndexOp Op = "Index"

// ExternalResolveOp is emitted when resolving a ref using an external
// Resolver.
ExternalResolveOp Op = "ExternalResolve"
)

// VarMetadata provides some user facing information about
Expand Down

0 comments on commit 73efebd

Please sign in to comment.