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

Refactor flyteadmin to pass proto structs as pointers #5717

Merged
merged 4 commits into from
Sep 5, 2024

Conversation

Sovietaced
Copy link
Contributor

@Sovietaced Sovietaced commented Sep 2, 2024

Why are the changes needed?

Go structs generated by protoc-gen-go contain a DoNotCopy mutex so that go vet will complain and discourage people from copying these go structs.

The flyteadmin code doesn't respect these intentions and has many of these warnings. 1,135 to be exact. The orange warnings are a bit noisy in the IDE and I noticed the golangci config ignores them.

As someone who comes from a Java background I'm guessing that the intent of passing around copies of these go structs is to prevent nil pointer errors and employ defensive programming. I think in most circumstances this makes sense, but in this case gRPC and protoc-gen-go are very intentional about using pointers. The structs are never nil in the gRPC API handlers, they are just passed with pointers so that the structs are used safely.

Having said that, this pull request attempts to refactor flyteadmin to use pointers for protobuf structs throughout the codebase to eliminate these warnings. It updates the golangci config to ignore the singular unavoidable and safe copy that is made.

see: https://stackoverflow.com/questions/64183794/why-do-the-go-generated-protobuf-files-contain-mutex-locks

How was this patch tested?

Unit tests and integration test have been updated.

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Copy link

codecov bot commented Sep 2, 2024

Codecov Report

Attention: Patch coverage is 72.05624% with 159 lines in your changes missing coverage. Please review.

Project coverage is 36.20%. Comparing base (7a91799) to head (0f75532).
Report is 157 commits behind head on master.

Files with missing lines Patch % Lines
flyteadmin/pkg/manager/mocks/signal_interface.go 14.28% 9 Missing and 9 partials ⚠️
...ytepropeller/pkg/compiler/common/mocks/workflow.go 0.00% 16 Missing ⚠️
...ller/pkg/compiler/common/mocks/workflow_builder.go 17.64% 8 Missing and 6 partials ⚠️
...cloudevent/implementations/cloudevent_publisher.go 0.00% 6 Missing ⚠️
flyteadmin/pkg/rpc/adminservice/attributes.go 40.00% 6 Missing ⚠️
flytepropeller/pkg/compiler/common/mocks/task.go 0.00% 6 Missing ⚠️
flyteadmin/pkg/manager/impl/workflow_manager.go 73.68% 5 Missing ⚠️
flyteadmin/pkg/manager/impl/execution_manager.go 91.30% 2 Missing and 2 partials ⚠️
flyteadmin/pkg/manager/impl/launch_plan_manager.go 80.00% 4 Missing ⚠️
flyteadmin/pkg/manager/mocks/metrics_interface.go 0.00% 4 Missing ⚠️
... and 40 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5717      +/-   ##
==========================================
+ Coverage   36.17%   36.20%   +0.03%     
==========================================
  Files        1303     1303              
  Lines      109663   109543     -120     
==========================================
- Hits        39667    39657      -10     
+ Misses      65851    65768      -83     
+ Partials     4145     4118      -27     
Flag Coverage Δ
unittests-datacatalog 51.37% <ø> (ø)
unittests-flyteadmin 55.59% <76.71%> (+0.30%) ⬆️
unittests-flytecopilot 12.17% <ø> (ø)
unittests-flytectl 62.17% <100.00%> (-0.02%) ⬇️
unittests-flyteidl 7.12% <ø> (ø)
unittests-flyteplugins 53.34% <ø> (ø)
unittests-flytepropeller 41.76% <28.57%> (-0.01%) ⬇️
unittests-flytestdlib 55.35% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Jason Parraga <[email protected]>
@@ -36,5 +36,6 @@ linters-settings:
- prefix(github.com/flyteorg)
skip-generated: true
issues:
exclude:
- copylocks
exclude-rules:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fine grained ignore

Copy link
Contributor

Choose a reason for hiding this comment

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

why does this still need to be excluded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/flyteorg/flyte/pull/5717/files/0f75532e95adab4fb43c5ce380a9b11808eced30#diff-68d7b4389844bb5dec320a0854bdb20122c9fcb4356c32dce5dff80a55ee486eR33-R34

The code copies the a security context to the flyte workflow custom resource, which stores it as a non-pointer so I think its inevitable unless I write some conversion method to traverse the security context and reconstruct a non-pointer version. I felt it was probably less error prone and more future proof to do a deep copy and ignore the warning.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for explaining, leaving this as an exception makes sense!

@@ -78,20 +78,15 @@ func GetValidTaskRequestWithOverrides(project string, domain string, name string
}
}

func GetValidTaskSpecBytes() []byte {
Copy link
Contributor Author

@Sovietaced Sovietaced Sep 2, 2024

Choose a reason for hiding this comment

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

This was unused so I just removed it, I think that should be safe since this is a testutils package?

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good and thank you!

@Sovietaced Sovietaced marked this pull request as ready for review September 2, 2024 22:13
@davidmirror-ops davidmirror-ops added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Sep 3, 2024
Copy link
Contributor

@katrogan katrogan left a comment

Choose a reason for hiding this comment

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

this is awesome!

@@ -36,5 +36,6 @@ linters-settings:
- prefix(github.com/flyteorg)
skip-generated: true
issues:
exclude:
- copylocks
exclude-rules:
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this still need to be excluded?

@katrogan katrogan merged commit 5f69589 into flyteorg:master Sep 5, 2024
53 checks passed
pmahindrakar-oss pushed a commit that referenced this pull request Sep 9, 2024
bgedik pushed a commit to bgedik/flyte that referenced this pull request Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants