Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete data bindings in traces for local variables #1208

Closed
istalker2 opened this issue Feb 11, 2019 · 1 comment · Fixed by #1922
Closed

Incomplete data bindings in traces for local variables #1208

istalker2 opened this issue Feb 11, 2019 · 1 comment · Fixed by #1922

Comments

@istalker2
Copy link
Contributor

Trace for the

rule { i = 1  }

looks like

Enter data.foo.rule = _ {} (qid=0, pqid=0)
Eval data.foo.rule = _ {} (qid=0, pqid=0)
Index data.foo.rule = _ {} (qid=0, pqid=0)
Enter rule = true { i = 1 } {} (qid=1, pqid=0)
Eval i = 1 {} (qid=1, pqid=0)
Exit rule = true { i = 1 } {i: 1} (qid=1, pqid=0)
Exit data.foo.rule = _ {_: true} (qid=0, pqid=0)
Redo data.foo.rule = _ {_: true} (qid=0, pqid=0)
Redo data.foo.rule = _ {_: true} (qid=0, pqid=0)
Redo rule = true { i = 1 } {i: 1} (qid=1, pqid=0)
Redo i = 1 {i: 1} (qid=1, pqid=0)

But for the

rule { i := 1  }

it becomes

Enter data.foo.rule = _ {} (qid=0, pqid=0)
Eval data.foo.rule = _ {} (qid=0, pqid=0)
Index data.foo.rule = _ {} (qid=0, pqid=0)
Enter rule = true { __local3__ = 1 } {} (qid=1, pqid=0)
Eval __local3__ = 1 {} (qid=1, pqid=0)
Exit rule = true { __local3__ = 1 } {__local3__: 1} (qid=1, pqid=0)
Exit data.foo.rule = _ {_: true} (qid=0, pqid=0)
Redo data.foo.rule = _ {_: true} (qid=0, pqid=0)
Redo data.foo.rule = _ {_: true} (qid=0, pqid=0)
Redo rule = true { __local3__ = 1 } {__local3__: 1} (qid=1, pqid=0)
Redo __local3__ = 1 {__local3__: 1} (qid=1, pqid=0)

i.e. instead of i we see __local3__. Although it might reflect how local variables are handled by OPA it doesn't give information to track __local3__ back to i

@tsandall
Copy link
Member

We deal with rewritten vars when query results are returned by the rego package. It seems like we need to apply the same kind of logic to the trace events to give callers a result that makes sense to them.

tsandall added a commit to tsandall/opa that referenced this issue Nov 25, 2019
For the longest time, topdown traces have included rewritten/mangled
variable names. This makes it difficult for people to understand the
trace because the variable names they used in their policy do not show
up in the trace. Now that we have the rewritten variable map readily
available during evaluation we can easily provide the user-supplied
variable names.

Technically this commit just fixes the presentation problem. The
inclusion of the variable mapping was done in
d1522c6.

This change also updates the trace emitting code to include local
metadata for all vars that appear in the AST node instead of just vars
that have bindings. This allows us to unmangle all variables in the
node (e.g., otherwise it would not be possible unmangle Enter nodes.)

Fixes open-policy-agent#1208

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit that referenced this issue Nov 26, 2019
For the longest time, topdown traces have included rewritten/mangled
variable names. This makes it difficult for people to understand the
trace because the variable names they used in their policy do not show
up in the trace. Now that we have the rewritten variable map readily
available during evaluation we can easily provide the user-supplied
variable names.

Technically this commit just fixes the presentation problem. The
inclusion of the variable mapping was done in
d1522c6.

This change also updates the trace emitting code to include local
metadata for all vars that appear in the AST node instead of just vars
that have bindings. This allows us to unmangle all variables in the
node (e.g., otherwise it would not be possible unmangle Enter nodes.)

Fixes #1208

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants