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
chore(orc8r): Protobuf upgrade #12546
Conversation
Thanks for opening a PR! 💯
Howto
More infoPlease take a moment to read through the Magma project's
If this is your first Magma PR, also consider reading
|
a25a5d3
to
446999f
Compare
c08cf43
to
f2a1019
Compare
fcb38a1
to
7c2a77b
Compare
7c2a77b
to
db4eb19
Compare
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.
9b69b94
to
ec9874a
Compare
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 splitting Go 1.18 PR. a few minor comments inline. Also - would it be possible to get rid of most of the cloning calls that are still left in the implementation?
The PR improved configurator interface by eliminating passing the message structs by value, but there is still quite a few intentional struct copies left there (please see inline).
feg/gateway/services/testcore/pcrf/mock_pcrf/mock_driven_pcrf_test.go
Outdated
Show resolved
Hide resolved
assert.Equal(t, want, got.IpMappings) | ||
for i := range want { | ||
test_utils.AssertMessagesEqual(t, want[i], got.IpMappings[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.
test_utils.AssertListsEqual(t, want[i], got.IpMappings[i])
and then in test_utils.go:
// AssertListsEqual compares two lists of proto messages.
func AssertListsEqual(t *testing.T, expected, actual interface{}) {
e, a := reflect.ValueOf(expected), reflect.ValueOf(actual)
if ekind, akind := e.Kind(), a.Kind(); ekind != akind || ekind != reflect.Slice {
assert.Equal(t, expected, actual)
}
assert.Equal(t, e.Len(), a.Len())
for i := 0; i < e.Len(); i++ {
expVal, actVal := e.Index(i).Interface(), a.Index(i).Interface()
expMsg, msgOk := expVal.(proto.Message)
actualMsg, actOk := actVal.(proto.Message)
if msgOk && actOk && proto.Equal(expMsg, actualMsg) {
continue
}
assert.Equal(t, expVal, actVal)
}
}
orc8r/cloud/go/services/bootstrapper/servicers/registration/registration.go
Outdated
Show resolved
Hide resolved
orc8r/cloud/go/services/bootstrapper/servicers/registration/registration.go
Outdated
Show resolved
Hide resolved
orc8r/cloud/go/services/configurator/storage/sql_network_helpers.go
Outdated
Show resolved
Hide resolved
orc8r/cloud/go/services/configurator/storage/sql_network_helpers.go
Outdated
Show resolved
Hide resolved
Hi @magma/approvers-domain-proxy, could we please ask one of you to take a look at this if you get the chance? Any help with getting this through would be really appreciated as it's blocking a couple of things. Thanks! 🙂 |
Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com>
…module (order: lexically sorted relative paths of go.mod files, relative to /Users/azb/VSCProjects/magma), this is repeated until no changes in go.mod and go.sum files are generated anymore, two iterations were needed Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com>
Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com>
Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com>
Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com>
1128b2a
to
85e4343
Compare
|
Sorry, unintentional misclick. -.- |
Thanks for the reviews! :) |
@emakeev Thank you for the review! Left some questions underneath some of your comments. As for the comments referring to Edit: Also added your line about the changes in configurator API to the summary of this PR. |
- introduce test_utils.Separator to deal with random whitespaces in string representations - use proto.Equal for comparison of proto Messages, often wrapped in custom functions to suit the particular purpose - use pointers to avoid copying or use proto.Clone where necessary to copy messages fix build and test errors Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> fix more test Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> replace whitespaces Signed-off-by: Alex Jahl <alexander.jahl@tngtech.com> fix more test Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> add compare method that circumvents random whitespaces insertion in string representations of proto messages Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> add separators Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> refactor assertMapsEqual, add to proto utils Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> add compare for ExpectedErrorSubstring and add separators in expeceted errors and substrings Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com>
…1.15 Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com>
Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> Signed-off-by: Cameron Voisey <cameron.voisey@tngtech.com>
e97ab88
to
1d9642a
Compare
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.
Let us know when is this ready to be merged
Feel free to merge! |
* bump protobuf to v1.5.2 in orc8r/cloud/go and orc8r/gateway/go Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> * propagate changes to remaining modules: running go mod tidy in every module (order: lexically sorted relative paths of go.mod files, relative to /Users/azb/VSCProjects/magma), this is repeated until no changes in go.mod and go.sum files are generated anymore, two iterations were needed Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> * add missing go_package option Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> * ./build.py --generate Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> * add untracked proto generated file Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> * fix build and test errors due to proto v2 implementation - introduce test_utils.Separator to deal with random whitespaces in string representations - use proto.Equal for comparison of proto Messages, often wrapped in custom functions to suit the particular purpose - use pointers to avoid copying or use proto.Clone where necessary to copy messages fix build and test errors Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> fix more test Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> replace whitespaces Signed-off-by: Alex Jahl <alexander.jahl@tngtech.com> fix more test Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> add compare method that circumvents random whitespaces insertion in string representations of proto messages Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> add separators Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> refactor assertMapsEqual, add to proto utils Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> add compare for ExpectedErrorSubstring and add separators in expeceted errors and substrings Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> * pin golang.org/x/net to revision that is compatible with go versions 1.15 Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> * update and sync dependencies with go mod tidy Signed-off-by: Alexander zur Bonsen <alexander.zur.bonsen@tngtech.com> Signed-off-by: Cameron Voisey <cameron.voisey@tngtech.com>
Summary
Upgrades
github.com/golang/protobuf
inorc8r/cloud/go
andorc8r/gateway/go
tov1.5.2
.This is a prerequisite for the Go upgrade in #12151.
More details on protobuf modules: There are two APIs arount. API v1 is published in
github.com/golang/protobuf
, API v2 ingoogle.golang.org/protobuf
. But versions>=v1.4.0
ofgithub.com/golang/protobuf
rely on the proto implementation that backs API v2 - while keeping API v1.This makes some changes necessary:
In the v2 implementation message structs contain a sync.Mutex which is supposed to discourage copying of messages. Every attempt to do so fails in govet copylocks checks. (The new API is published in google.golang.org/protobuf, see https://go.dev/blog/protobuf-apiv2 for more details). Consequently protobuf messages have to be passed as pointers.
Comparisons can be done with proto.Equal instead of using assert.Equal (which also compares implementation details). String comparison can be tricky, since protobuf doesn't guarantee the stability of the representation of the generated strings.
We actually encountered tests, that failed due to randomly appearing whitespaces in strings. Turns out that protobuf generates these into string representations (see for example golang/protobuf#1269). To work around that, we add a function in
orc8r/cloud/go/test_utils/unit_test_proto_utils.go
which divides the message into parts at inserted separators and checks the parts.Copying, where necessary, can be done with proto.Clone.
The most significant required change is the modification of configurator APIs/interfaces which were erroneously designed to pass & return config structures by value, the rest of the changes are mostly related to unit tests.
Further changes:
Pin
golang.org/x/net
to revision that is compatible with go versions in build environments. Can be removed with Go upgrade, tracked in #12559.Test Plan
./build.py -c
vagrant up cwag && vagrant ssh cwag && cd magma/cwf/gateway && make precommit
Additional Information
Done in pairing with @sebathomas, @voisey, @ajahl.
This change is backwards-breaking