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

COSI-44: Integrate Local gRPC Provisioner Server, and Refactor COSI Driver for Improved Maintainability and Observability #24

Merged
merged 11 commits into from
Nov 21, 2024

Conversation

anurag4DSB
Copy link
Collaborator

@anurag4DSB anurag4DSB commented Nov 15, 2024

Note for Reviewers

  • Reviewing by individual commits in order is recommended.
  • 🙈 Yes, there is a typo in the branch name, but that wouldn't matter when merging.

This PR enhances code coverage and refines the cosi-driver project by integrating a local gRPC provisioner server and reorganizing related components. Key changes are as follows:

  • Improved Code Coverage: Increased coverage from 75.53% to 77%. (can be improved, we will see in the future)
  • Provisioner Server Integration (COSI-44): Introduced a locally controlled gRPC provisioner server, copied from the Kubernetes SIGs repository for container object storage interfaces. This enables fine-grained control over gRPC server operations, preparing for OpenTelemetry integration.
  • Migrated package pkg/provisioner to pkg/grpcfactory, aligning with its function as a factory for gRPC services. Renamed internal files for better context clarity.
  • Improved package functionality, ensuring deprecated gRPC functions are replaced with up-to-date approaches, while noting areas for future migration.
  • Refactoring and Renaming for Clarity: renamed provisioner.go in driver package to provisioner_ser_impl.go
  • New Tests Added for gRPC Factory Components: grpc-factory-server.go, grpc-factory-interceptors.go, grpc-factory-client.go, and grpc-factory.go now have dedicated unit tests to validate key functionality and ensure reliable behavior.

Screenshots of Coverage Improvement:
New Coverage: 77%
Screenshot 2024-11-14 at 22 38 14

Original Coverage: 75.52%
Screenshot 2024-11-14 at 22 37 48

This PR introduces non-functional changes to the code, primarily improving maintainability and testing and preparing the codebase for observability enhancements with OpenTelemetry.

Base automatically changed from feature/COSI-63-add-codecov-granularity to main November 15, 2024 15:54
@@ -0,0 +1,32 @@
/*
Copy link

Choose a reason for hiding this comment

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

Could we just do a LICENSE file? (nitpick)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes we can, will remove from all in one go

)

var (
_ cosi.IdentityClient = &COSIProvisionerClient{}
Copy link

Choose a reason for hiding this comment

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

What do these lines do? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here’s a professional and clear response you can use to reply to the comment:

These lines are compile-time assertions that ensure COSIProvisionerClient implements the cosi.IdentityClient interface. Here’s what they do:

var (
	_ cosi.IdentityClient = &COSIProvisionerClient{}
)

This syntax assigns a pointer to COSIProvisionerClient to a variable of type cosi.IdentityClient (using _ as a placeholder). It’s a way to enforce, at compile time, that COSIProvisionerClient satisfies the cosi.IdentityClient interface.

If COSIProvisionerClient is missing any methods required by the cosi.IdentityClient interface, this code will trigger a compilation error. It’s a common pattern in Go to ensure a struct or type adheres to an interface, especially when there’s no explicit assignment elsewhere in the code.

Without this line, a mismatch between the struct and interface might only be caught at runtime when the struct is used incorrectly. And I want to be aligned with COSI spec now that we have migrated the provisioner server on our side. ;)

Let me know if you’d like further clarification! 😊
(BTW, it was from SIGS repo, orignally)

pkg/grpcfactory/client_test.go Show resolved Hide resolved
Copy provisioner server to cosi-driver
[Source](https://github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar/tree/master/pkg/provisioner)

This commit sets the stage for introducing open telemetry.
This introduces the gRPC server to the cosi-driver. With better control
of the code running the gRPC server, we can introduce open telemetry to
the cosi-driver at gRPC level.
- Renamed package `pkg/provisioner` to `pkg/grpcfactory` to better
 reflect its role in creating gRPC server.
- Renamed files within `pkg/grpcfactory` to match the new package
  context: `provisioner.go` → `grpc_factory.go`
- Renamed `pkg/driver/provisioner.go` to
  `pkg/driver/provisioner_server_impl.go` to clarify that it contains
  the `ProvisionerServer` implementation.
- Updated imports and references in `cmd/scality-cosi-driver/cmd.go` and
  throughout the codebase to reflect these changes.
- No functional changes; code logic remains the same.
@anurag4DSB anurag4DSB force-pushed the feature/COSI-44-instroduce-rpc-factory branch from 87cf433 to 4bcaa5c Compare November 19, 2024 17:51
@anurag4DSB
Copy link
Collaborator Author

anurag4DSB commented Nov 19, 2024

Rebased to origin/main and pushed.

Copy link

codecov bot commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 77.06422% with 25 lines in your changes missing coverage. Please review.

Project coverage is 76.01%. Comparing base (297b62e) to head (9214660).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
pkg/grpcfactory/server.go 66.66% 8 Missing and 2 partials ⚠️
pkg/grpcfactory/grpc_factory.go 84.74% 7 Missing and 2 partials ⚠️
pkg/grpcfactory/interceptors.go 70.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
pkg/driver/provisioner_server_impl.go 73.33% <ø> (ø)
pkg/grpcfactory/interceptors.go 70.00% <70.00%> (ø)
pkg/grpcfactory/grpc_factory.go 84.74% <84.74%> (ø)
pkg/grpcfactory/server.go 66.66% <66.66%> (ø)
Components Coverage Δ
🏠 Main Package ∅ <ø> (∅)
🚗 Driver Package 68.09% <ø> (ø)
📡 gRPC Factory Package 77.06% <77.06%> (∅)
🔧 Util Client Package 91.89% <ø> (ø)
@@            Coverage Diff             @@
##             main      #24      +/-   ##
==========================================
+ Coverage   75.52%   76.01%   +0.48%     
==========================================
  Files           4        7       +3     
  Lines         237      346     +109     
==========================================
+ Hits          179      263      +84     
- Misses         51       70      +19     
- Partials        7       13       +6     
---- 🚨 Try these New Features:

Comment on lines +78 to +79
IdentityClient: cosi.NewIdentityClient(conn),
ProvisionerClient: cosi.NewProvisionerClient(conn),

Choose a reason for hiding this comment

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

Ah I didn't know you could assign an embedded interface like this, good to know!

pkg/grpcfactory/interceptors.go Outdated Show resolved Hide resolved
pkg/grpcfactory/grpc_factory_suite_test.go Outdated Show resolved Hide resolved
Comment on lines 31 to 32
ctx context.Context
cancel context.CancelFunc

Choose a reason for hiding this comment

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

I don't think you need those, if you add the argument ctx SpecContext to each test case, it would be canceled automatically when the test case completes, I believe.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I keep forgetting that, will do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed

Comment on lines +69 to +70
select {
case err := <-errChan:
Expect(err).NotTo(HaveOccurred())
default:
// No errors
}

Choose a reason for hiding this comment

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

It seems to me this select would give 100ms for the server to crash with an error, and succeed in all other cases (the server continues to run after 100ms, or the server crashes after 100ms). Would it be better to have only one good behavior expected, whether it's that the server doesn't stop or that the server stops with a success response? (I believe the former is what's expected, in case we can fail the test if the channel has any value, including nil)

pkg/grpcfactory/interceptors_test.go Outdated Show resolved Hide resolved
pkg/grpcfactory/client_test.go Outdated Show resolved Hide resolved
Comment on lines +105 to +106
Expect(err).NotTo(HaveOccurred())
Expect(client).NotTo(BeNil())

Choose a reason for hiding this comment

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

Maybe it doesn't matter much, but we don't seem to check anything about whether the interceptor is present or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah! I didn't put much effort into it yet, as it was part of migrated code.

Copy link
Collaborator Author

@anurag4DSB anurag4DSB Nov 21, 2024

Choose a reason for hiding this comment

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

But will be improved in the coming weeks: https://scality.atlassian.net/browse/COSI-62

Made improvements to the provisioner package to enhance code simplicity
and handle deprecated gRPC functions.

- Embedded cosi.IdentityClient and cosi.ProvisionerClient interfaces
  into COSIProvisionerClient in client.go to simplify the client
  implementation, reducing boilerplate code.

- Corrected condition checks in apiLogger in interceptors.go to ensure
  JSON marshalling errors are handled properly. Enhanced logging to
  include error information if the API call fails.

- In provisioner.go, removed deprecated grpc.WithBlock() and
  acknowledged grpc.Dial deprecation. Proceeded without deprecated
  options, allowing asynchronous connection establishment. Noted that
  migrating to grpc.NewClient requires significant changes.

- Ensured listener cleanup in server.go by adding defer
  listener.Close(), preventing resource leaks. Improved error messages
  for clarity and
  consistency.
@anurag4DSB anurag4DSB force-pushed the feature/COSI-44-instroduce-rpc-factory branch from 9b077b9 to 9214660 Compare November 21, 2024 11:44
@anurag4DSB anurag4DSB merged commit da6e298 into main Nov 21, 2024
8 checks passed
@anurag4DSB anurag4DSB deleted the feature/COSI-44-instroduce-rpc-factory branch November 21, 2024 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants