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

feat: getting ready for initial Go SDK #3

Merged
merged 6 commits into from
Oct 6, 2024

Conversation

madflojo
Copy link
Member

@madflojo madflojo commented Oct 6, 2024

This PR represents a working protobuf collection for the SDK.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new Protocol Buffers definitions for SQL execution and query handling.
    • Enhanced HTTP client and response structures with additional fields for better request and response handling.
    • Added new message types for key retrieval operations in the KVStore interface.
    • New metrics features with additional fields for detailed observations.
  • Improvements

    • Updated build processes and configurations to streamline SDK generation.
    • Modified package paths for Protocol Buffers to reflect new import structures.
  • Bug Fixes

    • Removed deprecated SQL-related message definitions to improve clarity and maintainability.

Copy link
Contributor

coderabbitai bot commented Oct 6, 2024

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on the CI workflow, Makefile, and Protocol Buffers definitions. Key updates include the addition of a step to install the protoc-gen-go-vtproto tool in the CI configuration, modifications to the build commands in the Makefile, and the introduction of new message types and fields in various .proto files. Additionally, some existing messages have been removed, and package paths have been updated for Go code generation.

Changes

File Change Summary
.github/workflows/ci.yml - Added step to install protoc-gen-go-vtproto tool.
- Updated command from make all clean to make build clean.
- Set environment variable GOPATH to /home/runner/go.
Makefile - Renamed default target from all to build.
- Updated go target to generate SDK code from ./sdk directory.
proto/sql.proto - Removed SQLQuery and SQLQueryResponse message definitions.
sdk/http.proto - Updated go_package option.
- Added fields to HTTPClient and HTTPClientResponse messages.
sdk/kvstore.proto - Updated go_package option.
- Added KVStoreKeys and KVStoreKeysResponse message definitions.
sdk/metrics.proto - Updated go_package option.
- Added fields to MetricsGauge and MetricsHistogram messages.
sdk/sql.proto - Introduced new messages: SQLExec, SQLExecResponse, SQLQuery, and SQLQueryResponse.
sdk/tarmac.proto - Updated go_package option.

Possibly related PRs

Poem

In the meadow where code hops and plays,
New tools and paths brighten our days.
With protoc and Makefile in tow,
We build and create, watch our project grow!
Goodbye to old queries, hello to the new,
In the world of Tarmac, there’s much we can do! 🐇✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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: 4

🧹 Outside diff range and nitpick comments (7)
Makefile (3)

8-8: LGTM: Default target renamed appropriately.

The default target has been renamed from all to build, which is more descriptive of the action being performed. This change is consistent with the updated .PHONY declaration and maintains the same functionality.

Consider adding a comment above this line to explicitly state that this is the default target, for improved readability. For example:

# Default target
build: go

13-14: LGTM: SDK generation process updated and improved.

The changes to the go target enhance the build process by adding SDK generation capabilities. The new echo statement improves user feedback, and the updated protoc command reflects the project's new structure and tooling.

Consider the following improvements:

  1. Add error checking to ensure the required tools are installed:

    @command -v protoc >/dev/null 2>&1 || { echo >&2 "protoc is required but not installed. Aborting."; exit 1; }
    @command -v ${GOPATH}/bin/protoc-gen-go >/dev/null 2>&1 || { echo >&2 "protoc-gen-go is required but not installed. Aborting."; exit 1; }
    @command -v ${GOPATH}/bin/protoc-gen-go-vtproto >/dev/null 2>&1 || { echo >&2 "protoc-gen-go-vtproto is required but not installed. Aborting."; exit 1; }
  2. Consider using variables for repeated paths and options to improve maintainability:

    PROTOC_GEN_GO := ${GOPATH}/bin/protoc-gen-go
    PROTOC_GEN_GO_VTPROTO := ${GOPATH}/bin/protoc-gen-go-vtproto
    PROTOC_OPTS := -I=./sdk --go_out=$(GO_OUT) --go-vtproto_out=$(GO_OUT)
    PROTOC_PLUGINS := --plugin protoc-gen-go="$(PROTOC_GEN_GO)" --plugin protoc-gen-go-vtproto="$(PROTOC_GEN_GO_VTPROTO)"
    
    protoc $(PROTOC_OPTS) $(PROTOC_PLUGINS) ./sdk/*.proto
  3. Add a check to ensure the SDK directory exists:

    @[ -d "./sdk" ] || { echo >&2 "SDK directory not found. Aborting."; exit 1; }

These changes will make the Makefile more robust and easier to maintain.


Issues Identified in Makefile Changes

The verification process revealed the following issues that need to be addressed to ensure the Makefile changes function correctly:

  • Missing Go Tools: The required tools protoc, protoc-gen-go, and protoc-gen-go-vtproto are not found in PATH or GOPATH/bin. These are essential for generating Go code from .proto files.

  • Residual 'proto' References: Found references to the proto directory outside of the Makefile (e.g., in .github/workflows/ci.yml and README.md). These may need to be updated to reflect the new sdk directory structure.

Please address these issues to ensure the build process operates as expected.

🔗 Analysis chain

Line range hint 1-20: Overall assessment: Changes align well with PR objectives.

The modifications to the Makefile effectively support the generation of the Go SDK, which is the primary objective of this PR. The changes maintain good Makefile practices and improve the build process by focusing on SDK generation.

To ensure the changes are consistent across the project, please run the following verification script:

This script will help ensure that the changes in the Makefile are consistent with the project structure and that all necessary tools are available.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of SDK-related changes across the project.

# Test 1: Check if the SDK directory exists
if [ ! -d "./sdk" ]; then
  echo "Error: SDK directory not found. The Makefile assumes its existence."
  exit 1
fi

# Test 2: Verify the presence of .proto files in the SDK directory
proto_files=$(find ./sdk -name "*.proto")
if [ -z "$proto_files" ]; then
  echo "Warning: No .proto files found in the SDK directory. The Makefile may not function as expected."
fi

# Test 3: Check for any remaining references to the old 'proto' directory
old_proto_refs=$(grep -R "proto" --exclude=Makefile --exclude-dir=.git .)
if [ ! -z "$old_proto_refs" ]; then
  echo "Warning: Found references to 'proto' directory outside of Makefile. These may need to be updated:"
  echo "$old_proto_refs"
fi

# Test 4: Verify the presence of required Go tools
required_tools=("protoc" "protoc-gen-go" "protoc-gen-go-vtproto")
for tool in "${required_tools[@]}"; do
  if ! command -v "$tool" &> /dev/null; then
    echo "Error: Required tool '$tool' not found in PATH or GOPATH/bin."
  fi
done

echo "Verification complete."

Length of output: 9325

.github/workflows/ci.yml (1)

36-37: Approve the addition of protoc-gen-go-vtproto with a version pinning suggestion.

The addition of the protoc-gen-go-vtproto installation step is appropriate for integrating vtprotobuf into the build process. This aligns with the PR objective of preparing for the initial Go SDK.

Consider pinning the version of protoc-gen-go-vtproto to ensure reproducible builds. For example:

- name: Install protoc-gen-go-vtproto
  run: go install github.com/planetscale/vtprotobuf/cmd/[email protected]

Replace v0.4.0 with the desired version.

sdk/metrics.proto (1)

18-21: Consider using an enum for the action field.

The addition of the action field to MetricsGauge is a good improvement, allowing for more flexible gauge operations. However, using a string for this purpose might not be the most type-safe approach.

Consider using an enum instead of a string for better type safety and to prevent invalid values. Here's a suggested implementation:

enum GaugeAction {
  GAUGE_ACTION_UNSPECIFIED = 0;
  GAUGE_ACTION_INCREMENT = 1;
  GAUGE_ACTION_DECREMENT = 2;
}

message MetricsGauge {
  string name = 1;
  GaugeAction action = 2;
}

This approach would provide compile-time checks and prevent invalid action values.

sdk/http.proto (1)

23-26: LGTM with suggestion: Added insecure field to HTTPClient

The addition of the 'insecure' boolean field is valuable for scenarios involving self-signed certificates. The field is well-placed and properly commented, including a caution about its use.

However, given the potential security implications of disabling TLS host verification, consider adding more comprehensive documentation or safeguards:

  1. Add a more detailed comment explaining the specific use cases for this option.
  2. Consider implementing a logging mechanism that warns when this option is used in production environments.
  3. If possible, add a configuration option to entirely disable this feature in security-sensitive deployments.

Would you like assistance in drafting extended documentation for this field?

sdk/kvstore.proto (1)

79-103: LGTM. Consider adding a default value for return_proto.

The new KVStoreKeys message and the updated KVStoreKeysResponse message are well-structured and documented. They provide a clear mechanism for retrieving keys from the KV store.

Consider adding a default value for the return_proto field in the KVStoreKeys message. This can help clarify the default behavior when the field is not explicitly set. For example:

-  bool return_proto = 1;
+  bool return_proto = 1 [default = false];

This change would make it clear that by default, the response will be returned as a JSON string unless explicitly set to true.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3764129 and 0b21f2c.

📒 Files selected for processing (8)
  • .github/workflows/ci.yml (1 hunks)
  • Makefile (1 hunks)
  • proto/sql.proto (0 hunks)
  • sdk/http.proto (2 hunks)
  • sdk/kvstore.proto (4 hunks)
  • sdk/metrics.proto (3 hunks)
  • sdk/sql.proto (1 hunks)
  • sdk/tarmac.proto (2 hunks)
💤 Files with no reviewable changes (1)
  • proto/sql.proto
✅ Files skipped from review due to trivial changes (1)
  • sdk/tarmac.proto
🧰 Additional context used
🔇 Additional comments (13)
Makefile (1)

6-6: LGTM: Phony target declaration updated correctly.

The .PHONY declaration has been appropriately updated to reflect the change from all to build as the default target. This maintains good Makefile practices by correctly declaring all phony targets.

.github/workflows/ci.yml (1)

40-40: Verify Makefile changes for the build target.

The change from make all clean to make build clean appears to align with the PR objectives. However, it's important to ensure that the build target in the Makefile correctly includes all necessary steps for generating language files, especially considering the new vtprotobuf integration.

Please run the following script to verify the Makefile changes:

sdk/metrics.proto (2)

29-31: LGTM! Good addition to MetricsHistogram.

The addition of the value field to MetricsHistogram is a necessary and well-implemented change. Using a double type is appropriate for histogram values, and the comment clearly explains the purpose of the field.


4-4: LGTM! Verify Go import statements.

The go_package option update looks good. It provides a more specific and structured path for the generated Go code.

Please ensure that all Go code importing these protobuf definitions is updated to use the new package path. Run the following script to check for any outdated imports:

sdk/http.proto (6)

13-15: LGTM: Added headers field to HTTPClient

The addition of the 'headers' field as a map of string key-value pairs is a good improvement. It allows for flexible specification of custom HTTP headers in the client request.


16-18: LGTM: Added url field to HTTPClient

The addition of the 'url' field as a string is essential for specifying the target URL for the HTTP request. The field is well-placed and properly commented.


19-22: LGTM: Added body field to HTTPClient

The addition of the 'body' field as bytes is crucial for including payload data in the HTTP request. The field is well-defined and properly commented, explaining its purpose clearly.


35-44: LGTM: Comprehensive updates to HTTPClientResponse

The additions to the HTTPClientResponse message (code, headers, and body fields) provide a well-structured representation of HTTP responses. These changes are symmetrical to the additions in the HTTPClient message, which is excellent for consistency and ease of use.

Each field is appropriately numbered and well-commented, clearly explaining its purpose:

  • The 'code' field for the HTTP status code
  • The 'headers' field for response headers
  • The 'body' field for the response payload

This comprehensive structure will greatly facilitate handling of HTTP responses in the SDK.


Line range hint 1-44: Overall assessment: Well-structured and comprehensive updates

The changes to sdk/http.proto significantly enhance the HTTP-related message structures, providing a more comprehensive representation of both HTTP requests and responses. The additions to both HTTPClient and HTTPClientResponse messages are symmetrical, logical, and well-documented.

Key improvements:

  1. Updated go_package option for better organization
  2. Added fields for headers, URL, body, and insecure option in HTTPClient
  3. Added fields for status code, headers, and body in HTTPClientResponse

These changes align well with the PR objective of preparing for the initial Go SDK, offering a robust foundation for HTTP operations. The new structure should facilitate easier and more flexible HTTP handling in the SDK.

One minor suggestion to consider is enhancing the documentation around the 'insecure' option to ensure its judicious use.

Overall, these changes represent a significant step forward in the SDK's HTTP capabilities.


6-6: LGTM: Updated go_package option

The go_package option has been appropriately updated to reflect the new organization for the generated Go code. This change aligns with the PR objective of preparing for the initial Go SDK.

To ensure consistency, please verify that any existing Go code importing the old package has been updated. Run the following script to check for any remaining references to the old package:

✅ Verification successful

go_package option change verification

No Go files were found in the repository, ensuring that there are no existing references to the old package path.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for references to the old package path in Go files

rg --type go "github.com/tarmac-project/tarmac/proto"

Length of output: 202


Script:

#!/bin/bash
# Description: List all Go files and search for references to the old package path without using --type go

# List all .go files
echo "Listing all Go files:"
fd --extension go

# Search for references without type filtering
echo "Searching for 'github.com/tarmac-project/tarmac/proto' in Go files:"
rg "github.com/tarmac-project/tarmac/proto" --type go

Length of output: 426

sdk/kvstore.proto (3)

27-27: LGTM. Improved readability.

The addition of a blank line after the status field in the KVStoreGetResponse message improves readability and is consistent with good protobuf formatting practices.


41-41: LGTM. Consistent formatting.

The addition of a blank line after the key field in the KVStoreSet message improves readability and maintains consistency with the formatting in other messages.


6-6: LGTM. Verify import statements in existing Go code.

The go_package option update looks good. It appears to be moving the generated Go code to a more specific package, which is a good practice for organization.

Please ensure that all import statements in existing Go code that use these protobuf definitions are updated accordingly. Run the following script to check for any outdated imports:

✅ Verification successful

.github/workflows/ci.yml Outdated Show resolved Hide resolved
sdk/sql.proto Show resolved Hide resolved
Comment on lines +51 to +53
// Data is a JSON encoded byte slice of the data returned by the query.
bytes data = 5;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Define Structured Messages for Query Results Instead of JSON-Encoded bytes

The data field in SQLQueryResponse contains JSON-encoded data as a byte slice. Leveraging Protobuf's capability to define structured messages for the query results can enhance type safety, performance, and interoperability. Consider defining a repeated message type to represent each row in the result set.

sdk/sql.proto Show resolved Hide resolved
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 and nitpick comments (1)
.github/workflows/ci.yml (1)

38-39: Consider pinning the version of protoc-gen-go-vtproto.

Adding the installation of protoc-gen-go-vtproto is good as it ensures the necessary tools are available. However, using @latest might lead to unexpected behavior if there are breaking changes in future versions.

Consider pinning to a specific version for better reproducibility:

- run: go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@latest
+ run: go install github.com/planetscale/vtprotobuf/cmd/[email protected]

Replace v0.4.0 with the current latest version or the version that's compatible with your project.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 56f5052 and 808e37c.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
.github/workflows/ci.yml (3)

9-11: LGTM: Good practice to set default shell.

Setting the default shell to bash ensures consistency across all steps in the workflow. This is a good practice that can help prevent potential issues caused by different shell behaviors.


43-44: Reconsider the necessity of setting GOPATH.

While the GOPATH has been set to a more appropriate location (/home/runner/go) compared to the previous suggestion (/root/go), it's worth reconsidering whether setting GOPATH is necessary at all.

Modern Go projects using modules typically don't require GOPATH to be set explicitly. If GOPATH is indeed necessary for your build process, please clarify why. Otherwise, consider removing this environment variable setting.

You can run the following script to check if GOPATH is used in the build process:

#!/bin/bash
# Description: Check if GOPATH is used in the build process

# Test: Search for GOPATH usage in Makefile and Go files
echo "Searching for GOPATH usage in Makefile:"
grep -n GOPATH Makefile

echo "Searching for GOPATH usage in .go files:"
grep -r -n GOPATH --include="*.go" .

If these searches return no results, it might indicate that GOPATH is not necessary for your build process.


42-42: Verify Makefile changes corresponding to this update.

The make command has been changed from all clean to build clean. This likely corresponds to changes in the Makefile.

Please ensure that:

  1. The build target in the Makefile includes all necessary steps previously covered by the all target.
  2. No crucial steps are omitted in this transition.

You can run the following script to check the Makefile changes:

✅ Verification successful

[/run_scripts]


Makefile update verified.

The build target correctly replaces the all target and includes all necessary steps as previously defined.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check Makefile changes related to 'all' and 'build' targets

# Test: Display relevant Makefile changes
echo "Makefile changes related to 'all' and 'build' targets:"
git diff origin/main -- Makefile | grep -E '(all|build):'

Length of output: 210


Script:

#!/bin/bash
# Description: Display the full definition of the 'build' target in the Makefile

echo "Full definition of the 'build' target:"
rg -A5 '^build:' Makefile

Length of output: 213

@madflojo madflojo merged commit da705a0 into tarmac-project:main Oct 6, 2024
2 checks passed
@madflojo madflojo deleted the src branch October 6, 2024 22:01
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