-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
963b388
commit c7f424d
Showing
1 changed file
with
49 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ func TestLoadConfig(t *testing.T) { | |
require.NoError(t, err) | ||
|
||
defaultCfg := createDefaultConfig() | ||
defaultCfg.(*Config).collectorVersionResolver = NewDefaultTestCollectorVersionResolver() | ||
defaultCfg.(*Config).Endpoint = defaultEndpoint | ||
|
||
storageID := component.MustNewIDWithName("file_storage", "clickhouse") | ||
|
@@ -47,14 +48,15 @@ func TestLoadConfig(t *testing.T) { | |
{ | ||
id: component.NewIDWithName(metadata.Type, "full"), | ||
expected: &Config{ | ||
Endpoint: defaultEndpoint, | ||
Database: "otel", | ||
Username: "foo", | ||
Password: "bar", | ||
TTL: 72 * time.Hour, | ||
LogsTableName: "otel_logs", | ||
TracesTableName: "otel_traces", | ||
CreateSchema: true, | ||
collectorVersionResolver: NewDefaultTestCollectorVersionResolver(), | ||
Endpoint: defaultEndpoint, | ||
Database: "otel", | ||
Username: "foo", | ||
Password: "bar", | ||
TTL: 72 * time.Hour, | ||
LogsTableName: "otel_logs", | ||
TracesTableName: "otel_traces", | ||
CreateSchema: true, | ||
TimeoutSettings: exporterhelper.TimeoutConfig{ | ||
Timeout: 5 * time.Second, | ||
}, | ||
|
@@ -89,6 +91,7 @@ func TestLoadConfig(t *testing.T) { | |
t.Run(tt.id.String(), func(t *testing.T) { | ||
factory := NewFactory() | ||
cfg := factory.CreateDefaultConfig() | ||
cfg.(*Config).collectorVersionResolver = NewDefaultTestCollectorVersionResolver() | ||
|
||
sub, err := cm.Sub(tt.id.String()) | ||
require.NoError(t, err) | ||
|
@@ -282,7 +285,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
wantChOptions: ChOptions{ | ||
Secure: false, | ||
}, | ||
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&compress=lz4", | ||
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "Support tcp scheme", | ||
|
@@ -292,7 +295,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
wantChOptions: ChOptions{ | ||
Secure: false, | ||
}, | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "prefers database name from config over from DSN", | ||
|
@@ -305,7 +308,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
wantChOptions: ChOptions{ | ||
Secure: false, | ||
}, | ||
want: "clickhouse://foo:[email protected]:9000/otel?async_insert=true&compress=lz4", | ||
want: "clickhouse://foo:[email protected]:9000/otel?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "use database name from DSN if not set in config", | ||
|
@@ -317,7 +320,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
wantChOptions: ChOptions{ | ||
Secure: false, | ||
}, | ||
want: "clickhouse://foo:[email protected]:9000/otel?async_insert=true&compress=lz4", | ||
want: "clickhouse://foo:[email protected]:9000/otel?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "invalid config", | ||
|
@@ -337,7 +340,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
wantChOptions: ChOptions{ | ||
Secure: true, | ||
}, | ||
want: "https://127.0.0.1:9000/default?async_insert=true&compress=lz4&secure=true", | ||
want: "https://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4&secure=true", | ||
}, | ||
{ | ||
name: "Preserve query parameters", | ||
|
@@ -347,7 +350,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
wantChOptions: ChOptions{ | ||
Secure: true, | ||
}, | ||
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&compress=lz4&foo=bar&secure=true", | ||
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4&foo=bar&secure=true", | ||
}, | ||
{ | ||
name: "Parse clickhouse settings", | ||
|
@@ -359,7 +362,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
DialTimeout: 30 * time.Second, | ||
Compress: clickhouse.CompressionBrotli, | ||
}, | ||
want: "https://127.0.0.1:9000/default?async_insert=true&compress=br&dial_timeout=30s&secure=true", | ||
want: "https://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=br&dial_timeout=30s&secure=true", | ||
}, | ||
{ | ||
name: "Should respect connection parameters", | ||
|
@@ -370,29 +373,29 @@ func TestConfig_buildDSN(t *testing.T) { | |
wantChOptions: ChOptions{ | ||
Secure: true, | ||
}, | ||
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&compress=lz4&foo=bar&secure=true", | ||
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4&foo=bar&secure=true", | ||
}, | ||
{ | ||
name: "support replace database in DSN with config to override database", | ||
fields: fields{ | ||
Endpoint: "tcp://127.0.0.1:9000/otel", | ||
Database: "override", | ||
}, | ||
want: "tcp://127.0.0.1:9000/override?async_insert=true&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/override?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "when config option is missing, preserve async_insert false in DSN", | ||
fields: fields{ | ||
Endpoint: "tcp://127.0.0.1:9000?async_insert=false", | ||
}, | ||
want: "tcp://127.0.0.1:9000/default?async_insert=false&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=false&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "when config option is missing, preserve async_insert true in DSN", | ||
fields: fields{ | ||
Endpoint: "tcp://127.0.0.1:9000?async_insert=true", | ||
}, | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "ignore config option when async_insert is present in connection params as false", | ||
|
@@ -402,7 +405,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
AsyncInsert: &configTrue, | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=false&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=false&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "ignore config option when async_insert is present in connection params as true", | ||
|
@@ -412,7 +415,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
AsyncInsert: &configFalse, | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "ignore config option when async_insert is present in DSN as false", | ||
|
@@ -421,7 +424,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
AsyncInsert: &configTrue, | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=false&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=false&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "use async_insert true config option when it is not present in DSN", | ||
|
@@ -430,7 +433,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
AsyncInsert: &configTrue, | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "use async_insert false config option when it is not present in DSN", | ||
|
@@ -439,15 +442,15 @@ func TestConfig_buildDSN(t *testing.T) { | |
AsyncInsert: &configFalse, | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=false&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=false&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "set async_insert to true when not present in config or DSN", | ||
fields: fields{ | ||
Endpoint: "tcp://127.0.0.1:9000", | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "connection_params takes priority over endpoint and async_insert option.", | ||
|
@@ -457,7 +460,7 @@ func TestConfig_buildDSN(t *testing.T) { | |
AsyncInsert: &configFalse, | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "use compress br config option when it is not present in DSN", | ||
|
@@ -466,15 +469,15 @@ func TestConfig_buildDSN(t *testing.T) { | |
Compress: "br", | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=br", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=br", | ||
}, | ||
{ | ||
name: "set compress to lz4 when not present in config or DSN", | ||
fields: fields{ | ||
Endpoint: "tcp://127.0.0.1:9000", | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "connection_params takes priority over endpoint and compress option.", | ||
|
@@ -483,12 +486,29 @@ func TestConfig_buildDSN(t *testing.T) { | |
ConnectionParams: map[string]string{"compress": "br"}, | ||
Compress: "lz4", | ||
}, | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=br", | ||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=br", | ||
}, | ||
{ | ||
name: "include default otel product info in DSN", | ||
fields: fields{ | ||
Endpoint: "tcp://127.0.0.1:9000", | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=otelcol%2Ftest&compress=lz4", | ||
}, | ||
{ | ||
name: "correctly append default product info when value is included in DSN", | ||
fields: fields{ | ||
Endpoint: "tcp://127.0.0.1:9000?client_info_product=customProductInfo%2Fv1.2.3", | ||
}, | ||
|
||
want: "tcp://127.0.0.1:9000/default?async_insert=true&client_info_product=customProductInfo%2Fv1.2.3%2Cotelcol%2Ftest&compress=lz4", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cfg := createDefaultConfig().(*Config) | ||
cfg.collectorVersionResolver = NewDefaultTestCollectorVersionResolver() | ||
mergeConfigWithFields(cfg, tt.fields) | ||
dsn, err := cfg.buildDSN() | ||
|
||
|