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: Clickhouse Storage Driver #1342

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

luk3skyw4lker
Copy link

@luk3skyw4lker luk3skyw4lker commented Apr 9, 2024

Adding clickhouse implementation, attending #1204 request

Summary by CodeRabbit

  • New Features

    • Introduced a Clickhouse storage driver for Go applications, enabling interaction with Clickhouse databases.
    • Added configuration options for Clickhouse database connections, including host, port, credentials, and table details.
  • Tests

    • Implemented tests for key operations such as setting, getting, and deleting data in Clickhouse.
    • Set up GitHub Actions workflows for automated testing of Clickhouse and Cloudflare KV projects.
  • Documentation

    • Updated README and configuration files to provide guidance on setting up and using the new Clickhouse storage driver.
  • Chores

    • Modified GitHub Actions workflows to enhance CI/CD processes, including adjustments in the triggering conditions for better automation.

@luk3skyw4lker luk3skyw4lker requested a review from a team as a code owner April 9, 2024 16:53
@luk3skyw4lker luk3skyw4lker requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team April 9, 2024 16:53
Copy link
Contributor

coderabbitai bot commented Apr 9, 2024

Walkthrough

This update introduces a new ClickHouse storage driver for Go applications, enhancing database interaction capabilities. It includes comprehensive configuration options, methods for CRUD operations, and robust testing via GitHub Actions. The changes aim to streamline data handling and improve testing efficiency for Clickhouse and Cloudflare KV projects.

Changes

Files Change Summary
clickhouse/README.md, .../clickhouse.go, .../clickhouse_test.go Introduces ClickHouse storage driver with functions for database interactions and tests for CRUD operations.
clickhouse/config.go Adds configuration functionality for ClickHouse connections, including default settings and SQL queries.
.github/workflows/... Updates GitHub Actions workflows for testing ClickHouse and Cloudflare KV, and adds ClickHouse server setup in benchmark workflow.

🐇✨
In the land of code where the data bytes hop,
A new burrow's built with a ClickHouse on top.
Queries run fast, and the tests do cheer,
For every push and pull, brings changes near.
Hop, hop, hooray! For the bytes that we store,
In the burrow of ClickHouse, forevermore.
🌟🐰


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration 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.

@gaby gaby changed the title feat: add clickhouse implementation feat: Clickhouse Storage Driver Apr 10, 2024
@luk3skyw4lker
Copy link
Author

Taking a look at the failing checks already

@gaby
Copy link
Member

gaby commented Apr 11, 2024

@luk3skyw4lker The go.mod files are still broken. You edited the root one

@luk3skyw4lker
Copy link
Author

@gaby fixed it, sorry to take so long!

@gaby
Copy link
Member

gaby commented Apr 17, 2024

@luk3skyw4lker The benchmark yml has to be updated to run clickhouse

@luk3skyw4lker
Copy link
Author

@gaby I added the clickhouse startup command, should be ok right now

@luk3skyw4lker
Copy link
Author

@gaby the latest commit should fix the error in the benchmark, I changed the clickhouse port to 9001

clickhouse/go.mod Outdated Show resolved Hide resolved
.github/workflows/test-clickhouse.yml Outdated Show resolved Hide resolved

const createTableString = `
CREATE TABLE IF NOT EXISTS {table:Identifier} (
key String
Copy link
Member

Choose a reason for hiding this comment

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

We should make this a function that allows specifying compression type/level. Clickhouse is known for allowing using zstd/lz compression

Copy link
Author

Choose a reason for hiding this comment

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

I'll check out some ways to do that. I haven't come across a create table query specifying the compression method but I'll research for it

Copy link
Author

Choose a reason for hiding this comment

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

About this, seems like the only engine where you could change the compression methods is the MergeTree family and seems a little bit overcomplicated to have all those treatments here. If you guys really want to support this it's possible but it's harder than it seemed initially: https://clickhouse.com/docs/en/sql-reference/statements/create/table#column-compression-codecs

Copy link
Author

Choose a reason for hiding this comment

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

@gaby thoughts?

go.mod Outdated Show resolved Hide resolved
clickhouse/clickhouse_test.go Show resolved Hide resolved
clickhouse/clickhouse_test.go Outdated Show resolved Hide resolved
clickhouse/clickhouse_test.go Show resolved Hide resolved
clickhouse/clickhouse_test.go Show resolved Hide resolved
clickhouse/clickhouse_test.go Outdated Show resolved Hide resolved
@gaby
Copy link
Member

gaby commented Apr 22, 2024

@gaby the latest commit should fix the error in the benchmark, I changed the clickhouse port to 9001

Few comments, benchmarks are working now 💪

@luk3skyw4lker
Copy link
Author

I'm almost done with all the comments, probably will send some code by end of the week. Sorry to not do it sooner!

@gaby
Copy link
Member

gaby commented Apr 30, 2024

@luk3skyw4lker Thanks!

@ReneWerner87
Copy link
Member

@luk3skyw4lker thanks, just ping us when you are done

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2faf158 and bfd7ccc.
Files selected for processing (2)
  • clickhouse/clickhouse.go (1 hunks)
  • clickhouse/clickhouse_test.go (1 hunks)
Files not reviewed due to errors (1)
  • clickhouse/clickhouse_test.go (no review received)
Additional comments not posted (3)
clickhouse/clickhouse.go (3)

103-110: Ensure proper error handling in the Delete method.

The implementation of the Delete method is straightforward and correctly uses the context and parameters. Good job on keeping it concise and clear.


112-114: Ensure proper error handling in the Reset method.

The implementation of the Reset method is straightforward and correctly uses the context. Good job on keeping it concise and clear.


116-118: Ensure proper error handling in the Close method.

The implementation of the Close method is straightforward and correctly handles the session closure. Good job on keeping it concise and clear.

clickhouse/clickhouse.go Outdated Show resolved Hide resolved
clickhouse/clickhouse.go Outdated Show resolved Hide resolved
Comment on lines +33 to +42
if configuration.Clean {
queryWithEngine := fmt.Sprintf(createTableString, engine)
if err := conn.Exec(ctx, queryWithEngine); err != nil {
return &Storage{}, err
}

if err := conn.Exec(ctx, resetDataString); err != nil {
return &Storage{}, err
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling potential SQL injection vulnerabilities.

+ // Ensure that `engine` is sanitized or parameterized to prevent SQL injection.
+ // Example: Validate `engine` against a list of allowed values.

The engine variable is directly used in a SQL query. This could lead to SQL injection if not properly sanitized or validated.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if configuration.Clean {
queryWithEngine := fmt.Sprintf(createTableString, engine)
if err := conn.Exec(ctx, queryWithEngine); err != nil {
return &Storage{}, err
}
if err := conn.Exec(ctx, resetDataString); err != nil {
return &Storage{}, err
}
}
if configuration.Clean {
// Ensure that `engine` is sanitized or parameterized to prevent SQL injection.
// Example: Validate `engine` against a list of allowed values.
queryWithEngine := fmt.Sprintf(createTableString, engine)
if err := conn.Exec(ctx, queryWithEngine); err != nil {
return &Storage{}, err
}
if err := conn.Exec(ctx, resetDataString); err != nil {
return &Storage{}, err
}
}

clickhouse/clickhouse.go Outdated Show resolved Hide resolved
clickhouse/clickhouse.go Show resolved Hide resolved
clickhouse/clickhouse.go Outdated Show resolved Hide resolved
luk3skyw4lker and others added 2 commits May 6, 2024 14:51
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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 bfd7ccc and 0c53f45.
Files selected for processing (1)
  • clickhouse/clickhouse.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • clickhouse/clickhouse.go

luk3skyw4lker and others added 2 commits May 6, 2024 14:52
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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 0c53f45 and bdf87e3.
Files selected for processing (1)
  • clickhouse/clickhouse.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • clickhouse/clickhouse.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants