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

chore(orc8r): Protobuf upgrade #12546

Merged
merged 8 commits into from Apr 28, 2022
Merged

Conversation

alexzurbonsen
Copy link
Contributor

@alexzurbonsen alexzurbonsen commented Apr 23, 2022

Summary

Upgrades github.com/golang/protobuf in orc8r/cloud/go and orc8r/gateway/go to v1.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 in google.golang.org/protobuf. But versions >=v1.4.0 of github.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

  • CI
  • precommit check in orc8r/cloud/docker, ./build.py -c
  • local tests with running orc8r and AGW: tested various workflows like
    • setting configs with swagger
    • propagation of mconfig to AGW
  • cwag precommit test, vagrant up cwag && vagrant ssh cwag && cd magma/cwf/gateway && make precommit
  • cwag integ test: https://docs.magmacore.org/docs/cwf/dev_testing#run-integration-tests

Additional Information

@pull-request-size pull-request-size bot added the size/XXL Denotes a Pull Request that changes 1000+ lines. label Apr 23, 2022
@github-actions
Copy link
Contributor

Thanks for opening a PR! 💯

A couple initial guidelines

Howto

  • Reviews. The "Reviewers" listed for this PR are the Magma maintainers who will shepherd it.
  • Checks. All required CI checks must pass before merge.
  • Merge. Once approved and passing CI checks, use the ready2merge label to indicate the maintainers can merge your PR.

More info

Please take a moment to read through the Magma project's

If this is your first Magma PR, also consider reading

@github-actions github-actions bot added component: cwf component: feg FEG-gateway related issues component: orc8r Orchestrator-related issue labels Apr 23, 2022
feg/cloud/go/protos/s6a_proxy.pb.go Show resolved Hide resolved
feg/cloud/go/protos/s6a_proxy.pb.go Show resolved Hide resolved
lte/cloud/go/protos/oai/nas_state.pb.go Show resolved Hide resolved
lte/cloud/go/protos/oai/nas_state.pb.go Show resolved Hide resolved
lte/cloud/go/protos/oai/nas_state.pb.go Show resolved Hide resolved
lte/cloud/go/protos/oai/nas_state.pb.go Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Apr 23, 2022

feg-workflow

    2 files  202 suites   38s ⏱️
371 tests 371 ✔️ 0 💤 0
385 runs  385 ✔️ 0 💤 0

Results for commit 1d9642a.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 23, 2022

cloud-workflow

    7 files  356 suites   2m 12s ⏱️
974 tests 974 ✔️ 0 💤 0

Results for commit 1d9642a.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 23, 2022

agw-workflow

     77 files     122 suites   7m 25s ⏱️
1 158 tests 1 149 ✔️ 9 💤 0
1 159 runs  1 150 ✔️ 9 💤 0

Results for commit 1d9642a.

♻️ This comment has been updated with latest results.

@alexzurbonsen
Copy link
Contributor Author

@emakeev The summary of #12526 contains some lines that sound pretty helpful. Can we add them here as well?

@alexzurbonsen alexzurbonsen marked this pull request as ready for review April 26, 2022 10:05
@alexzurbonsen alexzurbonsen requested review from a team, xbend and uri200 April 26, 2022 10:05
Copy link
Member

@maxhbr maxhbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very good to me (up to very minor comments, that can be skipped). The split into commits makes it very easy to review!
🎉

Hope this gets merged soon, as it is already mostly covered by reviews in #12151 (and the approach is also supported by #12526)

cwf/cloud/go/go.mod Outdated Show resolved Hide resolved
orc8r/lib/go/protos/marshaler_test.go Outdated Show resolved Hide resolved
orc8r/cloud/go/test_utils/unit_test_proto_utils.go Outdated Show resolved Hide resolved
Copy link
Contributor

@emakeev emakeev left a 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).

assert.Equal(t, want, got.IpMappings)
for i := range want {
test_utils.AssertMessagesEqual(t, want[i], got.IpMappings[i])
}
Copy link
Contributor

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/metricsd/client_api.go Outdated Show resolved Hide resolved
@voisey
Copy link
Contributor

voisey commented Apr 27, 2022

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>
@xbend
Copy link
Contributor

xbend commented Apr 27, 2022

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! 🙂

@xbend xbend closed this Apr 27, 2022
@xbend xbend reopened this Apr 27, 2022
@xbend
Copy link
Contributor

xbend commented Apr 27, 2022

Sorry, unintentional misclick. -.-
Approval from domain proxy granted.

@alexzurbonsen
Copy link
Contributor Author

Thanks for the reviews! :)

@alexzurbonsen
Copy link
Contributor Author

alexzurbonsen commented Apr 27, 2022

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).

@emakeev Thank you for the review! Left some questions underneath some of your comments.
But most of the proto.Clones are gone now.

As for the comments referring to test_utils.AssertListsEqual we intend to look into that in a separate PR, after things got merged. They are tracked in this issue #12571. Let us know if you prefer a different approach though.
Otherwise we would land this PR as soon as CI is repaired.

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>
@voisey voisey added the ready2merge This PR is ready to be merged (is approved and passes all required checks) label Apr 27, 2022
Copy link
Contributor

@uri200 uri200 left a 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

@alexzurbonsen
Copy link
Contributor Author

Let us know when is this ready to be merged

Feel free to merge!

@sebathomas sebathomas merged commit 89f5888 into magma:master Apr 28, 2022
emakeev pushed a commit to emakeev/magma that referenced this pull request Aug 5, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: cwf component: feg FEG-gateway related issues component: orc8r Orchestrator-related issue ready2merge This PR is ready to be merged (is approved and passes all required checks) size/XXL Denotes a Pull Request that changes 1000+ lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet