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

Regenerate protobuf files #1359

Merged
merged 2 commits into from
Aug 18, 2024
Merged

Regenerate protobuf files #1359

merged 2 commits into from
Aug 18, 2024

Conversation

Danielius1922
Copy link
Member

No description provided.

Copy link
Contributor

coderabbitai bot commented Aug 18, 2024

Walkthrough

The updates enhance the generated code for gRPC services and message handling, focusing on version increments for protoc tools and modernizing type declarations. Key improvements include transitioning from interface{} to any, incorporating generics in service definitions, and refining error management in message processing. These changes not only align with contemporary Go practices but also maintain backward compatibility, ensuring a smooth transition for existing implementations.

Changes

Files Change Summary
pkg/net/grpc/stub.pb_test.go Updated version numbers for protoc-gen-go; modified type declarations from interface{} to any.
pkg/net/grpc/stub_grpc.pb_test.go Upgraded protoc-gen-go-grpc and protoc versions; introduced generics in TestStream method signatures and replaced custom stream types with generic ones.
coap-gateway/service/service.go Enhanced error handling in New function; standardized message processing with MakeMessage.
coap-gateway/service/session.go Integrated otelcoap.MakeMessage for improved message format; no changes to error handling.
coap-gateway/test/test.go Streamlined socket closure checks; introduced ListenSocket and ListenSockets types for better management.
pkg/opentelemetry/otelcoap/opentelemetry.go Introduced Message struct; updated functions to use the new structure for better clarity.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    Client->>Server: Send TestRequest
    Server->>Client: Stream TestResponse
    Client->>Server: Send more TestRequest
    Server->>Client: Stream more TestResponse
Loading

Poem

In a world of code so bright,
A rabbit hops with sheer delight.
From interface{} to any we cheer,
Generics now bring us closer, my dear.
With gRPC flows that smoothly entwine,
Let’s celebrate changes—oh, how divine! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6428ac1 and 097dff5.

Files ignored due to path filters (34)
  • certificate-authority/pb/cert.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • certificate-authority/pb/service.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • certificate-authority/pb/service.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
  • certificate-authority/pb/service_grpc.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • certificate-authority/pb/signingRecords.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/cancelCommands.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/devices.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/events.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/getDevicesMetadata.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/getPendingCommands.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/hubConfiguration.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/service.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/service_grpc.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/updateDeviceMetadata.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • identity-store/events/events.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • identity-store/pb/devices.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • identity-store/pb/service.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • identity-store/pb/service_grpc.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • m2m-oauth-server/pb/service.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • m2m-oauth-server/pb/service.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
  • m2m-oauth-server/pb/service_grpc.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • resource-aggregate/commands/commands.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • resource-aggregate/commands/resources.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • resource-aggregate/cqrs/aggregate/test/aggregate_test.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • resource-aggregate/cqrs/eventbus/pb/eventbus.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • resource-aggregate/events/events.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • resource-aggregate/service/service.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • resource-aggregate/service/service_grpc.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • resource-directory/pb/getLatestDeviceETags.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • resource-directory/pb/service.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • resource-directory/pb/service_grpc.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • snippet-service/pb/service.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • snippet-service/pb/service.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
  • snippet-service/pb/service_grpc.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
Files selected for processing (2)
  • pkg/net/grpc/stub.pb_test.go (4 hunks)
  • pkg/net/grpc/stub_grpc.pb_test.go (6 hunks)
Files skipped from review due to trivial changes (1)
  • pkg/net/grpc/stub.pb_test.go
Additional comments not posted (8)
pkg/net/grpc/stub_grpc.pb_test.go (8)

52-58: Approved: Use of generics in TestStream method implementation.

The update to use grpc.GenericClientStream[TestRequest, TestResponse] ensures improved type safety while maintaining existing functionality.


62-63: Acknowledged: Backward compatibility with type alias.

The type alias for StubService_TestStreamClient ensures backward compatibility with existing code that references the prior non-generic stream type.


130-131: Acknowledged: Backward compatibility with type alias.

The type alias for StubService_TestStreamServer ensures backward compatibility with existing code that references the prior non-generic stream type.


127-127: Approved: Use of generics in _StubService_TestStream_Handler.

The update to use grpc.GenericServerStream[TestRequest, TestResponse] ensures improved type safety while maintaining existing functionality.


98-104: Approved: Embedding check in RegisterStubServiceServer.

The check ensures that UnimplementedStubServiceServer is embedded by value, preventing potential runtime panics.


18-19: Acknowledged: gRPC version requirements.

The assertions and version requirements ensure compatibility with gRPC-Go v1.64.0 or later.


31-31: LGTM! Verify usage of the updated TestStream method.

The change to use a generic grpc.BidiStreamingClient[TestRequest, TestResponse] enhances type safety and aligns with modern Go practices.

Ensure that all usages of this method in the codebase are updated to accommodate the new signature.

Verification successful

All usages of the TestStream method have been updated successfully.

The TestStream method is correctly used with the new generic signature across the codebase, including in test files. This confirms that the changes are consistent and properly integrated.

  • Verified in pkg/net/grpc/stub_grpc.pb_test.go and pkg/net/grpc/interceptor_test.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the updated `TestStream` method in the codebase.

# Test: Search for the `TestStream` method usage. Expect: Only occurrences with the new signature.
rg --type go -A 5 'TestStream'

Length of output: 6666


70-70: LGTM! Verify implementations of the updated TestStream method.

The change to use a generic grpc.BidiStreamingServer[TestRequest, TestResponse] enhances type safety and aligns with modern Go practices.

Ensure that all implementations of this method in the codebase are updated to accommodate the new signature.

Verification successful

Implementations of TestStream method updated

The TestStream method with the new generic signature is implemented in the UnimplementedStubServiceServer struct within pkg/net/grpc/stub_grpc.pb_test.go. Ensure all other relevant implementations are similarly updated.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all implementations of the updated `TestStream` method in the codebase.

# Test: Search for the `TestStream` method implementation. Expect: Only occurrences with the new signature.
rg --type go -A 5 'func TestStream'

Length of output: 414


Script:

#!/bin/bash
# Description: Search for the `TestStream` method within interfaces or structs to verify its implementation.

# Adjusted search pattern to look for `TestStream` in the context of interfaces or structs.
ast-grep --lang go --pattern 'func ($_ TestStream)($_) $_'

Length of output: 405


Script:

#!/bin/bash
# Description: Refine search for the `TestStream` method in interfaces or structs to verify its implementation.

# Use ripgrep to search for `TestStream` method definitions in the context of interfaces or structs.
rg --type go 'TestStream\(grpc\.BidiStreamingServer\[TestRequest, TestResponse\]\)'

Length of output: 334

With blockwise transfer enabled a data race in message.BodySize
could occur. The issue is fixed by getting and caching of the
message size before writing of the response message is started.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (2)
test/test.go (2)

1007-1029: Ensure proper error handling in IsClosed.

The IsClosed method correctly attempts to bind to the address to check if the socket is closed. It uses require.NoError for error handling, which is appropriate for test scenarios. However, consider using assert.NoError if you want the tests to continue running after a failure, providing more comprehensive test results.

- require.NoError(t, err)
+ assert.NoError(t, err)

1033-1054: Optimize socket closure check in CheckForClosedSockets.

The CheckForClosedSockets method effectively checks socket closure with a timeout. However, consider using a more descriptive variable name instead of j for the loop counter to improve readability.

- for j := 0; j < 900; j++ {
+ for attempt := 0; attempt < 900; attempt++ {
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 097dff5 and d23c85d.

Files ignored due to path filters (2)
  • test/helm/mock.plgd.cloud.yaml is excluded by !**/*.yaml
  • test/helm/try.plgd.cloud.yaml is excluded by !**/*.yaml
Files selected for processing (5)
  • coap-gateway/service/service.go (3 hunks)
  • coap-gateway/service/session.go (1 hunks)
  • coap-gateway/test/test.go (1 hunks)
  • pkg/opentelemetry/otelcoap/opentelemetry.go (3 hunks)
  • test/test.go (1 hunks)
Additional comments not posted (12)
pkg/opentelemetry/otelcoap/opentelemetry.go (5)

31-33: New Message struct introduced.

The new Message struct encapsulates the Size attribute. This promotes encapsulation and type safety, which is a good practice.


61-65: Updated Event method for MessageType.

The Event method now uses the Message struct. This change is consistent with the new struct-based approach and improves type safety.


94-94: Updated MessageReceivedEvent function.

This function now accepts the Message struct, aligning with the new design. Ensure that all calls to this function are updated accordingly.

Verification successful

Function calls to MessageReceivedEvent are correctly updated.

All identified calls to the MessageReceivedEvent function have been updated to match the new signature with the Message struct. No further action is needed.

  • coap-gateway/service/service.go: Call uses otelcoap.MakeMessage(req.Message).
  • coap-gateway/service/session.go: Call uses otelcoap.MakeMessage(resp).
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `MessageReceivedEvent` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 'MessageReceivedEvent\('

Length of output: 1209


98-98: Updated MessageSentEvent function.

This function now uses the Message struct. Ensure that all calls to this function are updated to match the new signature.

Verification successful

Function calls to MessageSentEvent are updated.

All identified calls to MessageSentEvent in the codebase have been updated to match the new signature using the Message struct. No outdated calls were found.

  • coap-gateway/service/session.go: MessageSentEvent(ctx, otelcoap.MakeMessage(req))
  • coap-gateway/service/service.go: MessageSentEvent(req.Context(), otelcoap.MakeMessage(resp))
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `MessageSentEvent` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 'MessageSentEvent\('

Length of output: 1412


Line range hint 35-57: Check error handling in MakeMessage.

The MakeMessage function computes the size of a message. Ensure that the error handling logic for the Size method is appropriate and that size = 0 is a suitable fallback.

coap-gateway/test/test.go (1)

75-82: Refactor checkForClosedSockets to use ListenSockets.

The refactoring simplifies the logic for checking closed sockets by using the test.ListenSockets type. This enhances readability and maintainability. Ensure that test.ListenSockets is correctly implemented and integrated.

Verification successful

Refactoring Verified: CheckForClosedSockets is correctly integrated with ListenSockets.

The method CheckForClosedSockets is implemented and used as intended, confirming the refactoring suggestion. The integration enhances readability and maintainability as expected.

  • ListenSockets is defined and used in test/test.go.
  • CheckForClosedSockets is utilized in coap-gateway/test/test.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and integration of `test.ListenSockets`.

# Test: Search for the `ListenSockets` type definition and its methods. Expect: Proper implementation and usage.
rg --type go -A 5 'type ListenSockets'

Length of output: 352


Script:

#!/bin/bash
# Description: Search for usages of the `CheckForClosedSockets` method to verify its integration.

# Test: Find all occurrences of `CheckForClosedSockets` to ensure it's used correctly.
rg 'CheckForClosedSockets'

Length of output: 167

coap-gateway/service/service.go (3)

345-349: Enhance error handling in New function.

The New function now handles errors from createServices by closing the NATS connection. This prevents resource leaks and improves robustness.


434-434: Utilize MakeMessage in makeCommandTask.

The MakeMessage function is used for message processing, ensuring consistency and maintainability. Verify that MakeMessage is correctly implemented and integrated.


418-418: Utilize MakeMessage in processCommandTask.

The MakeMessage function is used for message processing, ensuring consistency and maintainability. Verify that MakeMessage is correctly implemented and integrated.

Verification successful

MakeMessage is correctly implemented and integrated. The function is consistently used across the codebase in MessageSentEvent and MessageReceivedEvent, ensuring proper message processing for telemetry purposes.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and integration of `MakeMessage`.

# Test: Search for the `MakeMessage` function definition and its usage. Expect: Proper implementation and usage.
rg --type go -A 5 'func MakeMessage'

Length of output: 452


Script:

#!/bin/bash
# Description: Search for the usage of `MakeMessage` in the codebase to verify its integration and usage consistency.
rg --type go 'MakeMessage'

Length of output: 509

test/test.go (2)

1002-1005: Encapsulate socket properties in ListenSocket.

The ListenSocket type encapsulates the network type and address, which promotes clarity and reusability. This design aligns with best practices.


1031-1031: Use ListenSockets to manage multiple sockets.

The ListenSockets type, as a slice of ListenSocket, provides a structured way to manage multiple sockets. This enhances the modularity and reusability of the code.

coap-gateway/service/session.go (1)

222-230: Enhance observability with otelcoap.MakeMessage.

The use of otelcoap.MakeMessage to wrap request and response messages improves telemetry and observability. Ensure that the wrapped messages contain all necessary attributes for effective monitoring.

Copy link

sonarcloud bot commented Aug 18, 2024

@Danielius1922 Danielius1922 merged commit 7590dcd into main Aug 18, 2024
39 checks passed
@Danielius1922 Danielius1922 deleted the adam/feature/update-protobufs branch August 18, 2024 10:22
This was referenced Sep 14, 2024
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.

1 participant