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

Merged
merged 46 commits into from
Jul 3, 2024

Conversation

luk3skyw4lker
Copy link
Contributor

@luk3skyw4lker luk3skyw4lker commented Apr 9, 2024

Adding clickhouse implementation.

Fixes #1204

Summary by CodeRabbit

  • New Features

    • Added ClickHouse storage driver for Go applications.
    • Introduced functions for managing ClickHouse storage: initialize, get, set, delete, reset, and close connections.
    • Added configuration and examples for ClickHouse storage in the README.
  • Documentation

    • Updated README with installation instructions and examples for ClickHouse configuration.
  • Tests

    • Added test functions and benchmarks for ClickHouse storage operations.
  • Chores

    • Set up GitHub Actions workflows for testing and benchmarking ClickHouse.
    • Added release drafter configuration for ClickHouse.

@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

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
Loading

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.

@gaby gaby changed the title feat: add clickhouse implementation feat: Clickhouse Storage Driver Apr 10, 2024
@luk3skyw4lker
Copy link
Contributor 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
Contributor 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
Contributor Author

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

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 4311191 and f4ee2db.

Files selected for processing (1)
  • clickhouse/README.md (1 hunks)
Additional context used
LanguageTool
clickhouse/README.md

[uncategorized] ~44-~44: Possible missing comma found. (AI_HYDRA_LEO_MISSING_COMMA)
Context: ...ickhouse-server ``` After running this command you're ready to start using the storage...

Markdownlint
clickhouse/README.md

5-5: Expected: h2; Actual: h3 (MD001, heading-increment)
Heading levels should only increment by one level at a time


46-46: Expected: 1; Actual: 0; Below (MD022, blanks-around-headings)
Headings should be surrounded by blank lines


30-30: null (MD031, blanks-around-fences)
Fenced code blocks should be surrounded by blank lines


48-48: null (MD031, blanks-around-fences)
Fenced code blocks should be surrounded by blank lines


53-53: null (MD031, blanks-around-fences)
Fenced code blocks should be surrounded by blank lines


119-119: null (MD047, single-trailing-newline)
Files should end with a single newline character

Additional comments not posted (2)
clickhouse/README.md (2)

1-4: Header and introduction look good.

The introduction succinctly describes the purpose of the storage driver and provides a useful link to the clickhouse-go library.


25-44: Installation instructions are clear and detailed.

The steps for installing the Clickhouse storage driver and setting up a local environment using Docker are well-documented and easy to follow.

Tools
LanguageTool

[uncategorized] ~44-~44: Possible missing comma found. (AI_HYDRA_LEO_MISSING_COMMA)
Context: ...ickhouse-server ``` After running this command you're ready to start using the storage...

Markdownlint

30-30: null (MD031, blanks-around-fences)
Fenced code blocks should be surrounded by blank lines

@ReneWerner87 ReneWerner87 requested a review from gaby June 26, 2024 14:14
@gaby
Copy link
Member

gaby commented Jun 26, 2024

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

@luk3skyw4lker
Copy link
Contributor Author

@gaby done!

@gaby
Copy link
Member

gaby commented Jun 26, 2024

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

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

gaby commented Jun 26, 2024

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

@luk3skyw4lker
Copy link
Contributor Author

@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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f4ee2db and 0228c63.

Files ignored due to path filters (1)
  • clickhouse/go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (4)
  • .github/dependabot.yml (1 hunks)
  • clickhouse/clickhouse.go (1 hunks)
  • clickhouse/clickhouse_test.go (1 hunks)
  • clickhouse/config.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • .github/dependabot.yml
  • clickhouse/config.go
Additional context used
Learnings (1)
clickhouse/clickhouse.go (1)
Learnt from: luk3skyw4lker
PR: gofiber/storage#1342
File: clickhouse/clickhouse.go:57-58
Timestamp: 2024-05-09T23:43:16.810Z
Learning: The pattern of returning `nil` for empty keys or values is consistent across different storage drivers in the gofiber/storage repository, including Redis, Rueidis, and MongoDB.
Additional comments not posted (13)
clickhouse/clickhouse.go (4)

121-123: LGTM!

The Reset function looks good and follows the expected logic.


125-127: LGTM!

The Close function looks good and follows the expected logic.


44-47: Handle the result of the Ping method.

The Ping method is called at the creation of a Storage instance, but its result is not checked. This could lead to scenarios where an unresponsive or faulty connection is used, leading to further errors.

err = conn.Ping(ctx)
if err != nil {
  return nil, err
}

Likely invalid or redundant comment.


57-58: Ensure proper handling of empty keys and values.

Returning nil when key or value is empty might hide bugs. It's better to return an explicit error to notify the caller of the invalid input.

- return nil
+ return fmt.Errorf("key and value must not be empty")

Likely invalid or redundant comment.

clickhouse/clickhouse_test.go (9)

23-33: LGTM!

The Test_Connection function looks good and follows the expected logic.


35-48: LGTM!

The Test_Set function looks good and follows the expected logic.


50-63: LGTM!

The Test_Set_With_Exp function looks good and follows the expected logic.


65-84: LGTM!

The Test_Get function looks good and follows the expected logic.


86-112: LGTM!

The Test_Get_With_Exp function looks good and follows the expected logic.


162-182: LGTM!

The Benchmark_Clickhouse_Set function looks good and follows the expected logic.


184-206: LGTM!

The Benchmark_Clickhouse_Get function looks good and follows the expected logic.


208-229: LGTM!

The Benchmark_Clickhouse_Set_And_Delete function looks good and follows the expected logic.


114-135: Add a test to ensure the deleted key is not retrievable.

After deleting a key, you should verify that attempting to retrieve the key returns an expected result (e.g., key not found). This ensures that the delete operation functions correctly.

+ assert.Equal(t, []byte{}, value)

This additional check ensures the delete functionality is robust and behaves as expected under normal conditions.

Likely invalid or redundant comment.

clickhouse/clickhouse.go Show resolved Hide resolved
clickhouse/clickhouse.go Outdated Show resolved Hide resolved
clickhouse/clickhouse.go Show resolved Hide resolved
clickhouse/clickhouse.go Outdated Show resolved Hide resolved
clickhouse/clickhouse.go Show resolved Hide resolved
clickhouse/clickhouse_test.go Show resolved Hide resolved
clickhouse/clickhouse_test.go Show resolved Hide resolved
@luk3skyw4lker
Copy link
Contributor Author

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

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 0228c63 and e744bc0.

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

@ReneWerner87 ReneWerner87 requested a review from gaby July 3, 2024 12:00
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 (8)
clickhouse/README.md (8)

1-1: Add a blank line after the header for proper markdown formatting.

This ensures the document adheres to markdown best practices.

# Clickhouse
+ 

5-5: Ensure each heading is followed by a blank line.

This is a markdown formatting requirement to separate content visually and structurally.

### Table of Contents
+ 
Tools
Markdownlint

5-5: Expected: h2; Actual: h3
Heading levels should only increment by one level at a time

(MD001, heading-increment)


13-13: Add blank lines around fenced code blocks.

This improves readability and adheres to markdown best practices.

### Signatures
+ 
+ 

25-25: Correct markdown formatting around headings and code blocks.

Ensure there are blank lines around headings and code blocks to meet markdown standards.

### Installation
+ 
+ 

30-30: Surround fenced code blocks with blank lines.

This improves readability and adheres to markdown best practices.

Install the clickhouse implementation:
+ 
```bash
go get github.com/gofiber/storage/clickhouse

<details>
<summary>Tools</summary>

<details>
<summary>Markdownlint</summary><blockquote>

30-30: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

</blockquote></details>

</details>

---

`44-44`: **Add a comma after introductory phrases.**

This improves readability and adheres to grammatical best practices.

```diff
After running this command you're ready to start using the storage and connecting to the database.
+ 
After running this command, you're ready to start using the storage and connecting to the database.
Tools
LanguageTool

[uncategorized] ~44-~44: Possible missing comma found.
Context: ...ickhouse-server ``` After running this command you're ready to start using the storage...

(AI_HYDRA_LEO_MISSING_COMMA)


49-49: Surround fenced code blocks with blank lines.

This improves readability and adheres to markdown best practices.

You can use the following options to create a clickhouse storage driver:
+ 
```go
import "github.com/gofiber/storage/clickhouse"

<details>
<summary>Tools</summary>

<details>
<summary>Markdownlint</summary><blockquote>

49-49: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

</blockquote></details>

</details>

---

`81-81`: **Replace hard tabs with spaces for consistency in markdown files.**

The use of hard tabs in markdown files can lead to inconsistent formatting across different viewers and editors.

```diff
-	// The host of the database. Ex: 127.0.0.1
+    // The host of the database. Ex: 127.0.0.1
-	Host string
+    Host string
-	// The port where the database is supposed to listen to. Ex: 9000
+    // The port where the database is supposed to listen to. Ex: 9000
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e744bc0 and f9d76aa.

Files selected for processing (1)
  • clickhouse/README.md (1 hunks)
Additional context used
LanguageTool
clickhouse/README.md

[uncategorized] ~44-~44: Possible missing comma found.
Context: ...ickhouse-server ``` After running this command you're ready to start using the storage...

(AI_HYDRA_LEO_MISSING_COMMA)

Markdownlint
clickhouse/README.md

5-5: Expected: h2; Actual: h3
Heading levels should only increment by one level at a time

(MD001, heading-increment)


30-30: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


49-49: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

LGTM, I updated a few comments and added -race to tests.

@ReneWerner87 ReneWerner87 merged commit 9209ae4 into gofiber:main Jul 3, 2024
8 of 9 checks passed
@luk3skyw4lker luk3skyw4lker deleted the feat/add-clickhouse-storage branch July 3, 2024 20:40
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.

🚀 [Feature]: ClickHouse Implementation
3 participants