storage icon indicating copy to clipboard operation
storage copied to clipboard

feat: Clickhouse Storage Driver

Open luk3skyw4lker opened this issue 10 months ago • 11 comments

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 avatar Apr 09 '24 16:04 luk3skyw4lker

[!WARNING]

Review failed

The pull request is closed.

Walkthrough

The update introduces a Clickhouse storage driver for Go applications using the clickhouse-go library, adding functionalities for data management, connection handling, and configuration. It integrates with the Fiber framework, offering methods for setting, retrieving, deleting, and resetting data in the ClickHouse database. Additionally, workflows for testing, benchmarking, and release management via GitHub Actions have been established, ensuring robust and maintainable integration.

Changes

File(s) Change Summary
clickhouse/README.md Added documentation for ClickHouse storage driver setup and usage.
clickhouse/clickhouse.go Introduced clickhouse package with Storage struct and methods for data operations.
clickhouse/clickhouse_test.go Added test and benchmark functions for ClickHouse storage operations.
clickhouse/config.go Implemented configuration setup for ClickHouse connections.
.github/workflows/test-clickhouse.yml Created GitHub Actions workflow for testing ClickHouse.
.github/workflows/test-cloudflarekv.yml Updated workflow to trigger on specific paths for Cloudflare KV project.
.github/workflows/benchmark.yml Added workflow step to start ClickHouse server for benchmarks.
.github/dependabot.yml Added dependency update configuration for ClickHouse package ecosystem.
.github/release-drafter-clickhouse.yml, .github/workflows/release-drafter-clickhouse.yml Configured release drafter for ClickHouse changes.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant ClickhouseDriver
    participant ClickhouseDB

    App->>ClickhouseDriver: New(config)
    ClickhouseDriver-->>ClickhouseDB: Connect with config
    ClickhouseDB-->>ClickhouseDriver: Connection Established

    App->>ClickhouseDriver: Set(key, value, expiration)
    ClickhouseDriver->>ClickhouseDB: Insert data
    ClickhouseDB-->>ClickhouseDriver: Data Inserted

    App->>ClickhouseDriver: Get(key)
    ClickhouseDriver->>ClickhouseDB: Query data
    ClickhouseDB-->>ClickhouseDriver: Return data

    App->>ClickhouseDriver: Delete(key)
    ClickhouseDriver->>ClickhouseDB: Delete data
    ClickhouseDB-->>ClickhouseDriver: Data Deleted

    App->>ClickhouseDriver: Reset()
    ClickhouseDriver->>ClickhouseDB: Reset table
    ClickhouseDB-->>ClickhouseDriver: Table Reset

    App->>ClickhouseDriver: Close()
    ClickhouseDriver->>ClickhouseDB: Close connection
    ClickhouseDB-->>ClickhouseDriver: Connection Closed

Assessment against linked issues

Objective Addressed Explanation
Implement ClickHouse storage driver with control over the table engine (#1204)
Provide methods for setting, getting, deleting, and resetting data in ClickHouse (#1204)

Poem

In code, we find the magic hue, ClickHouse binds, our data new, Set and get, delete with grace, A storage treat in this vast space. 🐇📦✨

[!TIP]

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


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

coderabbitai[bot] avatar Apr 09 '24 16:04 coderabbitai[bot]

Taking a look at the failing checks already

luk3skyw4lker avatar Apr 10 '24 16:04 luk3skyw4lker

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

gaby avatar Apr 11 '24 03:04 gaby

@gaby fixed it, sorry to take so long!

luk3skyw4lker avatar Apr 16 '24 17:04 luk3skyw4lker

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

gaby avatar Apr 17 '24 00:04 gaby

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

luk3skyw4lker avatar Apr 18 '24 18:04 luk3skyw4lker

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

luk3skyw4lker avatar Apr 22 '24 14:04 luk3skyw4lker

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

Few comments, benchmarks are working now 💪

gaby avatar Apr 22 '24 14:04 gaby

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

luk3skyw4lker avatar Apr 29 '24 19:04 luk3skyw4lker

@luk3skyw4lker Thanks!

gaby avatar Apr 30 '24 03:04 gaby

@luk3skyw4lker thanks, just ping us when you are done

ReneWerner87 avatar May 01 '24 15:05 ReneWerner87

@gaby @ReneWerner87 it's all done, compression is added. Sorry to take so long, I was trying to find a way to support all compression codecs but didn't manage to, so I went through with gaby's solution of adding just ZSTD(1) compression to all columns

luk3skyw4lker avatar Jun 20 '24 20:06 luk3skyw4lker

Will check it tomorrow

ReneWerner87 avatar Jun 20 '24 20:06 ReneWerner87

@luk3skyw4lker Overall looks good, just two comments

gaby avatar Jun 25 '24 00:06 gaby

@gaby I'll fix them tomorrow morning, thanks!

luk3skyw4lker avatar Jun 25 '24 00:06 luk3skyw4lker

@gaby I'll fix them tomorrow morning, thanks!

Sounds good 💪

gaby avatar Jun 25 '24 00:06 gaby

@ReneWerner87 @gaby I think it's all done!

luk3skyw4lker avatar Jun 25 '24 12:06 luk3skyw4lker

@luk3skyw4lker Run go mod tidy inside clickhouse folder. Will review after work

gaby avatar Jun 26 '24 14:06 gaby

@gaby done!

luk3skyw4lker avatar Jun 26 '24 14:06 luk3skyw4lker

@luk3skyw4lker There's a issue somewhere in the implementation. The tests fail/pass based on timing

gaby avatar Jun 26 '24 14:06 gaby

@luk3skyw4lker I think callig driver.Context is sharing context between tests. I've seen this happen with Prometheus too.

gaby avatar Jun 26 '24 14:06 gaby

@gaby yeah, I'll have to check this later, tried some stuff but it didn't solve the issue, I'll try it tomorrow morning when I have the time

luk3skyw4lker avatar Jun 26 '24 14:06 luk3skyw4lker

It doesn't seems like the sharing context it's the issue tho, I removed all driver.Context calls and tested it with creating a context.Background() for each separately call and the same error was raised, I'm gonna keep checking it out while I have the time

luk3skyw4lker avatar Jun 26 '24 15:06 luk3skyw4lker

Alright, found out what was going on, even when the expiration value was equal the zero value of the time.Time struct, the IsZero function was returning false, so I changed the comparision and everything works out now. Committing the solution right this instant

luk3skyw4lker avatar Jul 01 '24 14:07 luk3skyw4lker

@gaby I addressed your changes and fixed the issues the driver was having, could you check again please?

luk3skyw4lker avatar Jul 01 '24 15:07 luk3skyw4lker