Skip to content

Fix clickhouse proxy issue: hosts as query string DSN not parsed, also add alt_hosts support for DSN #1546

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
37 changes: 19 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
* Add length check to `FixedString` to prevent panic by @SpencerTorres in https://github.com/ClickHouse/clickhouse-go/pull/1534
### Other Changes 🛠
* chore: replace github.com/pkg/errors with stdlib by @hazzik in https://github.com/ClickHouse/clickhouse-go/pull/1530
* add database, hosts, alt_hosts query string DSN by @kokizzu in https://github.com/ClickHouse/clickhouse-go/pull/1541

## New Contributors
* @hazzik made their first contribution in https://github.com/ClickHouse/clickhouse-go/pull/1530

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.33.1...v2.34.0

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.33.1...v2.34.0
# v2.33.1, 2025-03-18 <!-- Release notes generated using configuration in .github/release.yml at main -->

## What's Changed
### Bug fixes 🐛
* fix concurrent map write errors with context by @SpencerTorres in https://github.com/ClickHouse/clickhouse-go/pull/1523


**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.33.0...v2.33.1

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.33.0...v2.33.1
# v2.33.0, 2025-03-07 <!-- Release notes generated using configuration in .github/release.yml at main -->

## What's Changed
Expand All @@ -41,26 +42,26 @@
* @Exca-DK made their first contribution in https://github.com/ClickHouse/clickhouse-go/pull/1500
* @holycheater made their first contribution in https://github.com/ClickHouse/clickhouse-go/pull/1517

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.32.2...v2.33.0

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.32.2...v2.33.0
# v2.32.2, 2025-02-20 <!-- Release notes generated using configuration in .github/release.yml at main -->

## What's Changed
### Bug Fixes 🐛
* fix: decode prefix of nested columns in Variant by @SpencerTorres in https://github.com/ClickHouse/clickhouse-go/pull/1506


**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.32.1...v2.32.2

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.32.1...v2.32.2
# v2.32.1, 2025-02-17 <!-- Release notes generated using configuration in .github/release.yml at main -->

## What's Changed
### Bug Fixes 🐛
* fix: enable Array() support for Variant, Dynamic, JSON by @SpencerTorres in https://github.com/ClickHouse/clickhouse-go/pull/1501


**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.32.0...v2.32.1

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.32.0...v2.32.1
# v2.32.0, 2025-02-14 <!-- Release notes generated using configuration in .github/release.yml at main -->

## What's Changed
Expand All @@ -81,8 +82,8 @@
## New Contributors
* @pablomatiasgomez made their first contribution in https://github.com/ClickHouse/clickhouse-go/pull/1497

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.31.0...v2.32.0

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.31.0...v2.32.0
# v2.31.0, 2025-02-10 <!-- Release notes generated using configuration in .github/release.yml at main -->

## What's Changed
Expand All @@ -97,8 +98,8 @@
## New Contributors
* @serprex made their first contribution in https://github.com/ClickHouse/clickhouse-go/pull/1493

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.30.3...2.31.0

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.30.3...2.31.0
# v2.30.3, 2025-02-03 <!-- Release notes generated using configuration in .github/release.yml at main -->

## What's Changed
Expand All @@ -108,8 +109,8 @@
## New Contributors
* @lobachpavel made their first contribution in https://github.com/ClickHouse/clickhouse-go/pull/1487

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.30.2...v2.30.3

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.30.2...v2.30.3
# v2.30.2, 2025-01-30 <!-- Release notes generated using configuration in .github/release.yml at main -->

## What's Changed
Expand All @@ -120,8 +121,8 @@
## New Contributors
* @matevzmihalic made their first contribution in https://github.com/ClickHouse/clickhouse-go/pull/1478

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.30.1...v2.30.2

**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.30.1...v2.30.2
# v2.30.1, 2025-01-17 <!-- Release notes generated using configuration in .github/release.yml at v2.30.1 -->

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ conn.SetConnMaxLifetime(time.Hour)

## DSN

* hosts - comma-separated list of single address hosts for load-balancing and failover
* hosts/alt_hosts - comma-separated list of single address hosts for load-balancing and failover
* username/password - auth credentials
* database - select the current default database
* dial_timeout - a duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix such as "300ms", "1s". Valid time units are "ms", "s", "m". (default 30s)
Expand Down
2 changes: 2 additions & 0 deletions clickhouse_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ func (o *Options) fromDSN(in string) error {

for v := range params {
switch v {
case "hosts", "alt_hosts":
o.Addr = append(o.Addr, strings.Split(params.Get(v), ",")...)
case "debug":
o.Debug, _ = strconv.ParseBool(params.Get(v))
case "compress":
Expand Down
26 changes: 26 additions & 0 deletions clickhouse_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,32 @@ func TestParseDSN(t *testing.T) {
},
"",
},
{
"clickhouse proxy with hosts as query string",
"tcp://127.0.0.1/?hosts=127.0.0.2,127.0.0.3",
&Options{
Protocol: Native,
TLS: nil,
Addr: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3"},
Settings: Settings{},
Auth: Auth{},
scheme: "tcp",
},
"",
},
{
"clickhouse proxy with alt_hosts as query string",
"tcp://127.0.0.1/?alt_hosts=127.0.0.3",
&Options{
Protocol: Native,
TLS: nil,
Addr: []string{"127.0.0.1", "127.0.0.3"},
Settings: Settings{},
Auth: Auth{},
scheme: "tcp",
},
"",
},
}

for _, testCase := range testCases {
Expand Down