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

ClickHouse: Add Support for Secure Connection #436

Merged
merged 10 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/platforms/clickhouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ connections:
host: "some-clickhouse-host.somedomain.com"
port: 9000
database: "dev" #Optional for other assets, uneffective when using ClickHouse as an ingestr destination, as ingestr takes the database name from the asset file.
http_port: 8123 #Only specify if you are using clickhouse as ingestr destination, by default it is 8123
http_port: 8443 #Only specify if you are using clickhouse as ingestr destination, by default it is 8443
secure: 1 #Only specify if you are using clickhouse as ingestr destination, by default, it is set to 1 (secure). Use 0 for a non-secure connection and 1 for a secure connection.
```
## Ingestr Assets:
After adding connection in `bruin.yml`. To ingest data to clickhouse, you need to create an [asset configuration](/assets/ingestr#asset-structure) file. This file defines the data flow from the source to the destination. Create a YAML file (e.g., stripe_ingestion.yml) inside the assets folder and add the following content:
Expand Down
6 changes: 5 additions & 1 deletion integration-tests/expected_connections_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@
},
"http_port": {
"type": "integer"
},
"secure": {
"type": "integer"
}
},
"additionalProperties": false,
Expand All @@ -211,7 +214,8 @@
"host",
"port",
"database",
"http_port"
"http_port",
"secure"
]
},
"Connections": {
Expand Down
22 changes: 18 additions & 4 deletions pkg/clickhouse/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package clickhouse

import (
"fmt"
"net/url"
"strconv"

click_house "github.com/ClickHouse/clickhouse-go/v2"
)
Expand All @@ -13,6 +15,7 @@ type Config struct {
Port int
Database string
HTTPPort int
Secure *int
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid using pointers?

Instead treat 0 as the null value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, we cannot treat 0 as a null value because 0 indicates a non-secure connection, 1 means a secure connection, and "not set" is represented as nil. For that I have to use pointer

}

func (c *Config) ToClickHouseOptions() *click_house.Options {
Expand All @@ -28,10 +31,21 @@ func (c *Config) ToClickHouseOptions() *click_house.Options {
}

func (c *Config) GetIngestrURI() string {
uri := url.URL{
Scheme: "clickhouse",
User: url.UserPassword(c.Username, c.Password),
Host: fmt.Sprintf("%s:%d", c.Host, c.Port),
}
query := url.Values{}

if c.HTTPPort != 0 {
//nolint:nosprintfhostport
return fmt.Sprintf("clickhouse://%s:%s@%s:%d?http_port=%d", c.Username, c.Password, c.Host, c.Port, c.HTTPPort)
query.Set("http_port", strconv.Itoa(c.HTTPPort))
}
if c.Secure != nil {
query.Set("secure", strconv.Itoa(*c.Secure))
}
//nolint:nosprintfhostport
return fmt.Sprintf("clickhouse://%s:%s@%s:%d", c.Username, c.Password, c.Host, c.Port)

uri.RawQuery = query.Encode()

return uri.String()
}
1 change: 1 addition & 0 deletions pkg/config/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ type ClickHouseConnection struct {
Port int `yaml:"port" json:"port" mapstructure:"port"`
Database string `yaml:"database" json:"database" mapstructure:"database"`
HTTPPort int `yaml:"http_port" json:"http_port" mapstructure:"http_port"`
Secure *int `yaml:"secure" json:"secure" mapstructure:"secure"`
}

func (c ClickHouseConnection) GetName() string {
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestLoadFromFile(t *testing.T) {
servicefile = "/path/to/service_account.json"
}

clickhouseSecureValue := 0

devEnv := Environment{
Connections: &Connections{
GoogleCloudPlatform: []GoogleCloudPlatformConnection{
Expand Down Expand Up @@ -224,6 +226,7 @@ func TestLoadFromFile(t *testing.T) {
Path: duckPath,
},
},

ClickHouse: []ClickHouseConnection{
{
Name: "conn-clickhouse",
Expand All @@ -233,6 +236,7 @@ func TestLoadFromFile(t *testing.T) {
Password: "clickhousepass",
Database: "clickhousedb",
HTTPPort: 8124,
Secure: &clickhouseSecureValue,
},
},
Hubspot: []HubspotConnection{
Expand Down
1 change: 1 addition & 0 deletions pkg/config/testdata/simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ environments:
password: "clickhousepass"
database: "clickhousedb"
http_port: 8124
secure: 0
gcs:
- name: "gcs-1"
service_account_file: "/path/to/service_account.json"
Expand Down
1 change: 1 addition & 0 deletions pkg/config/testdata/simple_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ environments:
password: "clickhousepass"
database: "clickhousedb"
http_port: 8124
secure: 0
gcs:
- name: "gcs-1"
service_account_file: "/path/to/service_account.json"
Expand Down
1 change: 1 addition & 0 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,7 @@ func (m *Manager) AddClickHouseConnectionFromConfig(connection *config.ClickHous
Password: connection.Password,
Database: connection.Database,
HTTPPort: connection.HTTPPort,
Secure: connection.Secure,
})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/python/uv.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var AvailablePythonVersions = map[string]bool{
const (
UvVersion = "0.5.0"
pythonVersionForIngestr = "3.11"
ingestrVersion = "0.13.0"
ingestrVersion = "0.13.2"
)

// UvChecker handles checking and installing the uv package manager.
Expand Down