Skip to content

Commit

Permalink
[exporter/clickhouse] Fix create database failure (#23666)
Browse files Browse the repository at this point in the history
resolve:
#23664
  • Loading branch information
Frapschen committed Jun 26, 2023
1 parent 6f0fabb commit bf00ae8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
20 changes: 20 additions & 0 deletions .chloggen/fix-create-database-fail.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: clickhouseexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix clickhouse exporter create database fail

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [23664]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
11 changes: 9 additions & 2 deletions exporter/clickhouseexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,15 @@ func (cfg *Config) buildDSN(database string) (string, error) {
// Override database if specified in config.
if cfg.Database != "" {
dsnURL.Path = cfg.Database
} else if database == "" && cfg.Database == "" && dsnURL.Path == "" {
// Use default database if not specified in any other place.
}

// Override database if specified in database param.
if database != "" {
dsnURL.Path = database
}

// Use default database if not specified in any other place.
if database == "" && cfg.Database == "" && dsnURL.Path == "" {
dsnURL.Path = defaultDatabase
}

Expand Down
15 changes: 13 additions & 2 deletions exporter/clickhouseexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestConfig_buildDSN(t *testing.T) {
Database: "otel",
},
args: args{
database: defaultDatabase,
database: "otel",
},
wantChOptions: ChOptions{
Secure: false,
Expand Down Expand Up @@ -201,7 +201,8 @@ func TestConfig_buildDSN(t *testing.T) {
},
args: args{},
want: "clickhouse://127.0.0.1:9000/default?foo=bar&secure=true",
}, {
},
{
name: "Parse clickhouse settings",
fields: fields{
Endpoint: "https://127.0.0.1:9000?secure=true&dial_timeout=30s&compress=lz4",
Expand All @@ -226,6 +227,16 @@ func TestConfig_buildDSN(t *testing.T) {
args: args{},
want: "clickhouse://127.0.0.1:9000/default?foo=bar&secure=true",
},
{
name: "support replace database in DSN to default database",
fields: fields{
Endpoint: "tcp://127.0.0.1:9000/otel",
},
args: args{
database: defaultDatabase,
},
want: "tcp://127.0.0.1:9000/default",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit bf00ae8

Please sign in to comment.