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

make: fix verify-dep target #18205

Merged
merged 3 commits into from
Jun 19, 2024
Merged

Conversation

ivanvc
Copy link
Member

@ivanvc ivanvc commented Jun 18, 2024

  • Fix the make verify-dep target to scan also indirect dependencies.
  • Address dependency version mismatches.

Part of #18180.

Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.

@k8s-ci-robot
Copy link

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ivanvc
Copy link
Member Author

ivanvc commented Jun 18, 2024

/test all

@ivanvc
Copy link
Member Author

ivanvc commented Jun 18, 2024

This is an example of a failure (with the current mismatch in dependency versions from the main branch): https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/etcd-io_etcd/18205/pull-etcd-verify/1803142325526859776

@ahrtr, could you PTAL at this? Thanks :)

@henrybear327
Copy link
Contributor

This is an example of a failure (with the current mismatch in dependency versions from the main branch): https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/etcd-io_etcd/18205/pull-etcd-verify/1803142325526859776

@ahrtr, could you PTAL at this? Thanks :)

Just curious @ivanvc, is it possible to show the file paths where the inconsistent versions are extracted from? :)

@ivanvc
Copy link
Member Author

ivanvc commented Jun 18, 2024

Just curious @ivanvc, is it possible to show the file paths where the inconsistent versions are extracted from? :)

Without adding a lot of complexity to the code, I can achieve something like:

Found inconsistent dependency versions:
{
  "google.golang.org/genproto/googleapis/rpc": [
    "v0.0.0-20240318140521-94a12d6c2237",
    "v0.0.0-20240513163218-0867130af1f8",
    "v0.0.0-20240520151616-dc85e6b867a5"
  ],
  "golang.org/x/sys": [
    "v0.19.0",
    "v0.21.0"
  ]
}

google.golang.org/genproto/googleapis/rpc:
./client/v3/go.mod:     google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
./etcdctl/go.mod:       google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
./etcdutl/go.mod:       google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect
./pkg/go.mod:   google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
./tests/go.mod: google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect
./tools/mod/go.mod:     google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
./tools/testgrid-analysis/go.mod:       google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
./server/go.mod:        google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect
./api/go.mod:   google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
./go.mod:       google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect

golang.org/x/sys:
./client/pkg/go.mod:    golang.org/x/sys v0.19.0
./client/v3/go.mod:     golang.org/x/sys v0.21.0 // indirect
./etcdctl/go.mod:       golang.org/x/sys v0.21.0 // indirect
./etcdutl/go.mod:       golang.org/x/sys v0.21.0 // indirect
./pkg/go.mod:   golang.org/x/sys v0.21.0 // indirect
./tests/go.mod: golang.org/x/sys v0.21.0 // indirect
./tools/mod/go.mod:     golang.org/x/sys v0.21.0 // indirect
./tools/testgrid-analysis/go.mod:       golang.org/x/sys v0.21.0 // indirect
./server/go.mod:        golang.org/x/sys v0.21.0 // indirect
./api/go.mod:   golang.org/x/sys v0.21.0 // indirect
./go.mod:       golang.org/x/sys v0.21.0 // indirect

@henrybear327
Copy link
Contributor

Just curious @ivanvc, is it possible to show the file paths where the inconsistent versions are extracted from? :)

Without adding a lot of complexity to the code, I can achieve something like:

Found inconsistent dependency versions:
{
  "google.golang.org/genproto/googleapis/rpc": [
    "v0.0.0-20240318140521-94a12d6c2237",
    "v0.0.0-20240513163218-0867130af1f8",
    "v0.0.0-20240520151616-dc85e6b867a5"
  ],
  "golang.org/x/sys": [
    "v0.19.0",
    "v0.21.0"
  ]
}

google.golang.org/genproto/googleapis/rpc:
./client/v3/go.mod:     google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
./etcdctl/go.mod:       google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
./etcdutl/go.mod:       google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect
./pkg/go.mod:   google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
./tests/go.mod: google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect
./tools/mod/go.mod:     google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
./tools/testgrid-analysis/go.mod:       google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
./server/go.mod:        google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect
./api/go.mod:   google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
./go.mod:       google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect

golang.org/x/sys:
./client/pkg/go.mod:    golang.org/x/sys v0.19.0
./client/v3/go.mod:     golang.org/x/sys v0.21.0 // indirect
./etcdctl/go.mod:       golang.org/x/sys v0.21.0 // indirect
./etcdutl/go.mod:       golang.org/x/sys v0.21.0 // indirect
./pkg/go.mod:   golang.org/x/sys v0.21.0 // indirect
./tests/go.mod: golang.org/x/sys v0.21.0 // indirect
./tools/mod/go.mod:     golang.org/x/sys v0.21.0 // indirect
./tools/testgrid-analysis/go.mod:       golang.org/x/sys v0.21.0 // indirect
./server/go.mod:        golang.org/x/sys v0.21.0 // indirect
./api/go.mod:   golang.org/x/sys v0.21.0 // indirect
./go.mod:       golang.org/x/sys v0.21.0 // indirect

Looks good! Thanks for the quick work!

I think with this information it’s faster for reviewers to understand what’s doing on, as the source and type (direct, indirect, etc.) 😀 is very clear!

@ivanvc ivanvc force-pushed the add-make-verify-dep-versions branch from 7b1c81c to 4322740 Compare June 18, 2024 21:18
@ivanvc
Copy link
Member Author

ivanvc commented Jun 18, 2024

/test pull-etcd-verify

@ivanvc
Copy link
Member Author

ivanvc commented Jun 18, 2024

As I was working on this, I realized that there's a similar check already in place:

etcd/scripts/test.sh

Lines 533 to 539 in 0430960

function dump_deps_of_module() {
local module
if ! module=$(run go list -m); then
return 255
fi
run go list -f "{{if not .Indirect}}{{if .Version}}{{.Path}},{{.Version}},${module}{{end}}{{end}}" -m all
}

However, the approach is slightly different. This check runs against go list instead of go mod. The result from the list (removing the indirect check) opens a can of worms, as it lists the whole dependency tree (from go.sum). We can't update deep-level dependencies.

I wonder what approach we should follow, as the current didn't catch the inconsistencies we have right now.

Find attached the output log when removing the {{ if not .Indirect }} condition: verify-dep-output.log.

Update: I found a potential issue on how the current code lists duplicates. After fixing it, the list is shorter. However, AFAIK we don't have the ability to update those deep-level dependencies, as they don't show on the go.mod. Unless we force them in the go.mod, but a go mod tidy would remove them. Updated log output: verify-dep-output-fixed.log.

@ivanvc
Copy link
Member Author

ivanvc commented Jun 19, 2024

/test pull-etcd-verify

@ivanvc
Copy link
Member Author

ivanvc commented Jun 19, 2024

I updated this PR. I have two possible implementations:

  1. New script/Makefile target: 4322740. Intended prow failure: https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/etcd-io_etcd/18205/pull-etcd-verify/1803175651885191168
  2. Update verify-dep to use go mod edit rather than go list, scan for indirect dependencies in the go module, and fix an issue with matching the dependency name: 0bec4c5. Intended prow failure: https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/etcd-io_etcd/18205/pull-etcd-verify/1803218126519668736

I think I prefer the latter option. @jmhbnz, it would be great to have your input too.

@ahrtr
Copy link
Member

ahrtr commented Jun 19, 2024

Great work, thanks @ivanvc

https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/etcd-io_etcd/18205/pull-etcd-verify/1803142325526859776

Checking dependencies for ./go.mod
�[0;31mFound inconsistent dependency versions:
�[0;31m{
"google.golang.org/genproto/googleapis/rpc": [
"v0.0.0-20240318140521-94a12d6c2237",
"v0.0.0-20240513163218-0867130af1f8",
"v0.0.0-20240520151616-dc85e6b867a5"
],
"golang.org/x/sys": [
"v0.19.0",
"v0.21.0"
]
}
make: *** [Makefile:161: verify-dependency-versions] Error 1

Thanks for the finding.

I updated this PR. I have two possible implementations:

  1. New script/Makefile target: 4322740. Intended prow failure: https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/etcd-io_etcd/18205/pull-etcd-verify/1803175651885191168
  2. Update verify-dep to use go mod edit rather than go list, scan for indirect dependencies in the go module, and fix an issue with matching the dependency name: 0bec4c5. Intended prow failure: https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/etcd-io_etcd/18205/pull-etcd-verify/1803218126519668736

I think I prefer the latter option. @jmhbnz, it would be great to have your input too.

Yes, let's go for simpler solution. No need to add a separate script file

Makefile's target `verify-dep` current behavior is to use `go list` to
check consistent dependency versions from direct dependencies. Ignoring
indirect dependencies in a multi-module project could lead to version
mismatches. If module A imports module B, module B's dependency will be
an indirect dependency in module A. Which can potentially have a version
mismatch. Therefore, use `go mod edit` with indirect dependencies, too.
So it can work with all dependencies defined in go.mod.

Fix displaying dependencies with mismatches, as the old code was
searching with grep just for the prefix, which would show other
dependencies that shared the same prefix.

Signed-off-by: Ivan Valdes <ivan@vald.es>
Ensure that golang.org/x/sys is at the same version across the modules
from the project.

Signed-off-by: Ivan Valdes <ivan@vald.es>
…20240520151616-dc85e6b867a5

Set the same version for google.golang.org/genproto/googleapis/api
across the submodules.

Signed-off-by: Ivan Valdes <ivan@vald.es>
@ivanvc ivanvc force-pushed the add-make-verify-dep-versions branch from d08c8d4 to a016567 Compare June 19, 2024 16:02
@ivanvc ivanvc changed the title make: add verify-dependency-versions target make: fix verify-dep target Jun 19, 2024
@ivanvc ivanvc marked this pull request as ready for review June 19, 2024 16:04
@ivanvc
Copy link
Member Author

ivanvc commented Jun 19, 2024

Updated the description and finalized commits + addressed dependency version mismatches.

/cc @ahrtr

@k8s-ci-robot k8s-ci-robot requested a review from ahrtr June 19, 2024 16:08
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks

Copy link
Member

@jmhbnz jmhbnz left a comment

Choose a reason for hiding this comment

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

LGTM - Nice work @ivanvc

@jmhbnz jmhbnz merged commit 866b8dd into etcd-io:main Jun 19, 2024
49 checks passed
@ivanvc ivanvc deleted the add-make-verify-dep-versions branch June 19, 2024 19:39
@ivanvc
Copy link
Member Author

ivanvc commented Jun 19, 2024

@henrybear327, do you want to give it a try at backporting this to 3.5?

@henrybear327
Copy link
Contributor

@henrybear327, do you want to give it a try at backporting this to 3.5?

Yes! Thank you @ivanvc!

/assign @henrybear327

henrybear327 added a commit to henrybear327/etcd that referenced this pull request Jun 19, 2024
Makefile's target `verify-dep` current behavior is to use `go list` to
check consistent dependency versions from direct dependencies. Ignoring
indirect dependencies in a multi-module project could lead to version
mismatches. If module A imports module B, module B's dependency will be
an indirect dependency in module A. Which can potentially have a version
mismatch. Therefore, use `go mod edit` with indirect dependencies, too.
So it can work with all dependencies defined in go.mod.

Fix displaying dependencies with mismatches, as the old code was
searching with grep just for the prefix, which would show other
dependencies that shared the same prefix.

Reference:
- etcd-io#18205

Signed-off-by: Ivan Valdes <ivan@vald.es>
Signed-off-by: Chun-Hung Tseng <henrybear327@gmail.com>
henrybear327 added a commit to henrybear327/etcd that referenced this pull request Jun 19, 2024
Makefile's target `verify-dep` current behavior is to use `go list` to
check consistent dependency versions from direct dependencies. Ignoring
indirect dependencies in a multi-module project could lead to version
mismatches. If module A imports module B, module B's dependency will be
an indirect dependency in module A. Which can potentially have a version
mismatch. Therefore, use `go mod edit` with indirect dependencies, too.
So it can work with all dependencies defined in go.mod.

Fix displaying dependencies with mismatches, as the old code was
searching with grep just for the prefix, which would show other
dependencies that shared the same prefix.

Reference:
- etcd-io#18205

Signed-off-by: Ivan Valdes <ivan@vald.es>
Signed-off-by: Chun-Hung Tseng <henrybear327@gmail.com>
aneesh1 pushed a commit to DataDog/etcd that referenced this pull request Sep 24, 2024
Makefile's target `verify-dep` current behavior is to use `go list` to
check consistent dependency versions from direct dependencies. Ignoring
indirect dependencies in a multi-module project could lead to version
mismatches. If module A imports module B, module B's dependency will be
an indirect dependency in module A. Which can potentially have a version
mismatch. Therefore, use `go mod edit` with indirect dependencies, too.
So it can work with all dependencies defined in go.mod.

Fix displaying dependencies with mismatches, as the old code was
searching with grep just for the prefix, which would show other
dependencies that shared the same prefix.

Reference:
- etcd-io#18205

Signed-off-by: Ivan Valdes <ivan@vald.es>
Signed-off-by: Chun-Hung Tseng <henrybear327@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants