-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add --format discard to opa eval #6080
Add --format discard to opa eval #6080
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, I've left a few suggestions 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! One final thing would be to add some docs, I think we can just add one line here:
Line 236 in ecac4c7
--format=raw : output the values from query results in a scripting friendly format |
Sure, I missed it, my bad |
Is this fine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all your work on this @26tanishabanik. I think it looks good now 🙂. I'll mention to the others to give this a final look over before we get it merged in.
cmd/eval.go
Outdated
@@ -232,6 +234,7 @@ Set the output format with the --format flag. | |||
--format=pretty : output query results in a human-readable format | |||
--format=source : output partial evaluation results in a source format | |||
--format=raw : output the values from query results in a scripting friendly format | |||
--format=discard : output the result field as "discarded" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks for adding it 🙂!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Seems to mis-aligned with the previous line. Also in output the result field as "discarded"
lets clarify if this is the case when the result is non-nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@26tanishabanik can you please look into 👆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I had formatted it, and now did it again 🤔, have pushed it the change
Sure, thanks a lot 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@26tanishabanik the changes look good. Few comments inline. Thanks for working on this!
cmd/eval.go
Outdated
@@ -232,6 +234,7 @@ Set the output format with the --format flag. | |||
--format=pretty : output query results in a human-readable format | |||
--format=source : output partial evaluation results in a source format | |||
--format=raw : output the values from query results in a scripting friendly format | |||
--format=discard : output the result field as "discarded" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Seems to mis-aligned with the previous line. Also in output the result field as "discarded"
lets clarify if this is the case when the result is non-nil.
go.sum
Outdated
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= | ||
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this file change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, might have changed when running go mod tidy
, I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reverted the change
@@ -1312,6 +1312,116 @@ time.clock(input.y, time.clock(input.x)) | |||
} | |||
} | |||
|
|||
func TestEvalDiscardOutput(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful if we add a test case for the scenario when the result is nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added that as a second case in that tests struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected opa eval '1*2+3' -format=discard
to produce nothing unless something like --profile
was set. @charlieegan3 and @26tanishabanik am I missing something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, if I remember properly, the idea was to set it empty if the result is itself nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see three desirable behaviours as goals for this:
- Undefined results are not shown as discarded as they were never there in the first place.
- Discarded results appear differently from undefined results to make the distinction clear.
--format=discard
will always produce valid JSON. From the issue (Add --format discard toopa eval
#5863) it's meant to be the 'opposite' of--format=raw
which removes all structure around the result.
In the go run main.go eval '1*2+3' --format=discard
example, the result defined and so is discarded in the output. We can't return {}
since it'd break goal 2.
$ go run main.go eval '1*2+3' --format=discard
{
"result": "discarded"
}
I think this handling of undefined results is also correct:
$ go run main.go eval '1' --format=discard
{
"result": "discarded"
}
$ go run main.go eval 'input.undefined' --format=discard
{}
(I think that what we have at the moment does this, but open to other ideas)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should we proceed further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll let @ashutosh-narkar weigh in to check we're all in agreement on the desired outputs first. I can work with you again on this tomorrow if we need to make any updates 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thanks 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds fine. Thanks for the clarification @26tanishabanik and @charlieegan3.
@charlieegan3 , @ashutosh-narkar , not sure, why this error is coming: |
cmd/eval.go
Outdated
@@ -232,6 +234,7 @@ Set the output format with the --format flag. | |||
--format=pretty : output query results in a human-readable format | |||
--format=source : output partial evaluation results in a source format | |||
--format=raw : output the values from query results in a scripting friendly format | |||
--format=discard : output the result field as "discarded" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: output the result field as "discarded"
lets clarify that this is the case when the result is non-nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@26tanishabanik sorry I meant lets update the text in the --format=discard
description to something like --format=discard : output the result field as "discarded" when non-nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will update that
@26tanishabanik I've added one small comment. Also can you please squash your commits and author a message per these guidelines and we can get this in. Thanks for working on this! |
Fixes: open-policy-agent#5863 Signed-off-by: 26tanishabanik <26tanishabanik@gmail.com>
13a073e
to
f27dd20
Compare
Signed-off-by: Tanisha Banik <26tanishabanik@gmail.com>
Signed-off-by: 26tanishabanik <26tanishabanik@gmail.com>
Is the commit fine now, @ashutosh-narkar ? |
Hey @26tanishabanik looks like some additional files (
This will sync upstream changes to your local branch. You can then (force) push your commit. |
@ashutosh-narkar , these files were already there, right? |
Hey @26tanishabanik, Yeah I think so. It looks like there are some new lines that weren't there before in those files. |
Thanks, @charlieegan3 , will fix those |
Hey @26tanishabanik, it'd be nice to get this into the next release. We're nearly there. I think you can address the go.mod diffs with:
Then |
…open-policy-agent#5863 Signed-off-by: 26tanishabanik <26tanishabanik@gmail.com>
Sure, @charlieegan3, thanks 🙂 |
@ashutosh-narkar , @charlieegan3 , Are there any other changes required from my end? |
Hey @26tanishabanik, it looks like there are still some changes in the go.mod file. How about we do this:
The three sets of changes which we need to remove are:
When we're done here, they should not appear in the PR diff. |
fabfe31
to
9253704
Compare
Can you check now? |
🤔 hmm, I think that merging from main won't do the job here. I can still see the changes to go.mod, go.sum and modules.txt... running
And pushing a new commit without merging main, should address the issue. (I'm heading out for the day, I'll check back tomorrow morning UK time.) |
@26tanishabanik if it's easier you can close this PR. Then create new branch synced with Create a new branch:
Now add your changes:
Then create a PR. Hope this helps. |
@ashutosh-narkar , @charlieegan3 , please check #6103 |
👏 Thanks @26tanishabanik for all the time you spent on this one. Great to see it's been merged now 🙂 great work. |
Thanks @charlieegan3 for your guidance 🙂 |
Very welcome! |
Why the changes in this PR are needed?
fixes #5863
What are the changes in this PR?
adds a subcommand for
format
which will discard the resultNotes to assist PR review:
Further comments: