-
Notifications
You must be signed in to change notification settings - Fork 55
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
cleanups and refactor of protosanitizer #184
Conversation
Welcome @huww98! |
Hi @huww98. Thanks for your PR. I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
819e5e4
to
278086b
Compare
/ok-to-test |
It now works with all kinds of nested fields, and don't require json.Marshal() twice. The output also looks better for oneof and enum.
@jsafrane Can you also take a look at this one? It should speedup several times for cases like kubernetes-csi/external-provisioner#1310 when the log level is high. |
} | ||
} | ||
|
||
func stripValue(field protoreflect.FieldDescriptor, v protoreflect.Value) any { |
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.
Can be stripValue()
and stripSingleValue()
combined into a single function with a bigger switch?
switch {
case field.IsList():
...
case field.IsMap():
...
case field.Kind() == protoreflect.MessageKind:
...
case field.Kind() == ...
default: return v.Interface()
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 is possible, but less clear, I think. Because for field that IsList()
, its Kind()
still returns the kind of list element. So, we will have multiple case statements matched.
My code structure actually looks very like the official encoder:
https://github.com/protocolbuffers/protobuf-go/blob/b98563540c0a4edb38526bcd6e6c97f9fac1f453/encoding/prototext/encode.go#L201-L212
(I'm not referencing it when writing, but reached agreement eventually :)
for i := range l.Len() { | ||
res[i] = stripSingleValue(field, l.Get(i)) |
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.
For example, what happens when a list has a list? Will it call stripSingleValue()
with a list, which then leads to default:
branch there and thus print the list with potential secrets?
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.
List is represented as repeated field in the protobuf. Like:
repeated VolumeCapability volume_capabilities = 3;
And it cannot be nested without going through a level of message. i.e.:
repeated repeated VolumeCapability volume_capabilities = 3;
is not valid, but this one is:
repeated Topology accessible_topology = 5;
message Topology {
map<string, string> segments = 1;
}
Similarly, map<string, map<string, string>>
or repeated map<string, string>
are not valid.
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 the explanation!
/lgtm
/approve
golang/protobuf#1655 We may get official redact support in the future. But even after that is ready, I think we should still keep ours, because that one will be prototext based, not json. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: huww98, jsafrane The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This PR does a series cleanups and refactors about protosanitizer:
About the output change of protosanitizer:
oneof
is reduced by one.Example diff of the output (manually formatted for diff):
Also added a benchmark to justify the new implementation:
Old:
New:
The new implementation is significantly faster, and allocates less memory
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
protosanitizer now imports csi spec directly, instead of copy over the
e_CsiSecret
. Since this module already requires the csi spec module, this should not break anyone.Support for CSI spec v0.3 is dropped, since the
csi.pb.go
file in that version does not implement the new protoreflect interface. And again, since this module already requires the csi spec module v1, users cannot use this module with v0.3 even without this PR. So, this is not a new breakage.Does this PR introduce a user-facing change?: