Skip to content

Commit

Permalink
Make ClickHouse connection configuration more user-friendly
Browse files Browse the repository at this point in the history
Before this change, Quesma supported only the "clickhouse://" protocol
to connect to ClickHouse. However, ClickHouse also supports the HTTP
protocol (8123) and HTTPS protocol (8443). This PR extends the
ClickHouse connection logic to switch to using HTTP(S) protocol if the
user put that endpoint instead.

This change is motivated by the fact that the HTTPS endpoint is the
first/default endpoint shown on ClickHouse Cloud and by the fact that
we saw a user try to use the HTTP endpoint.
  • Loading branch information
avelanarius committed Oct 31, 2024
1 parent 3b7cce6 commit 2548a84
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion quesma/clickhouse/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
)

func initDBConnection(c *config.QuesmaConfiguration, tlsConfig *tls.Config) *sql.DB {

options := clickhouse.Options{Addr: []string{c.ClickHouse.Url.Host}}

if c.ClickHouse.User != "" || c.ClickHouse.Password != "" || c.ClickHouse.Database != "" {

options.Auth = clickhouse.Auth{
Expand All @@ -29,6 +29,18 @@ func initDBConnection(c *config.QuesmaConfiguration, tlsConfig *tls.Config) *sql
if !c.ClickHouse.DisableTLS {
options.TLS = tlsConfig
}
if c.ClickHouse.Url.Scheme == "clickhouse" {
options.Protocol = clickhouse.Native
} else if c.ClickHouse.Url.Scheme == "http" {
logger.Warn().Msgf("Using HTTP protocol to connect to ClickHouse. We recommend using ClickHouse Native protocol instead (default port 9000).")
options.Protocol = clickhouse.HTTP
options.TLS = nil
} else if c.ClickHouse.Url.Scheme == "https" {
logger.Warn().Msgf("Using HTTPS protocol to connect to ClickHouse. We recommend using ClickHouse Native protocol instead (default port 9000).")
options.Protocol = clickhouse.HTTP
} else {
logger.Error().Msgf("Unknown ClickHouse endpoint protocol '%s' in the provided URL %s. Defaulting to ClickHouse Native protocol. Please provide the ClickHouse URL in the following format: clickhouse://host:port", c.ClickHouse.Url.Scheme, c.ClickHouse.Url.String())
}

info := struct {
Name string
Expand Down

0 comments on commit 2548a84

Please sign in to comment.