From 0ab4df9fd7fc5b3342b4336a3e9d42d0d81d5310 Mon Sep 17 00:00:00 2001 From: adityachopra29 Date: Thu, 23 Jan 2025 12:44:50 +0530 Subject: [PATCH 1/5] create clickhouse dir Signed-off-by: adityachopra29 --- plugin/storage/clickhouse/config.go | 1 + plugin/storage/clickhouse/config_test.go | 1 + plugin/storage/clickhouse/options.go | 1 + plugin/storage/clickhouse/options_test.go | 1 + 4 files changed, 4 insertions(+) create mode 100644 plugin/storage/clickhouse/config.go create mode 100644 plugin/storage/clickhouse/config_test.go create mode 100644 plugin/storage/clickhouse/options.go create mode 100644 plugin/storage/clickhouse/options_test.go diff --git a/plugin/storage/clickhouse/config.go b/plugin/storage/clickhouse/config.go new file mode 100644 index 00000000000..dc864de3954 --- /dev/null +++ b/plugin/storage/clickhouse/config.go @@ -0,0 +1 @@ +package clickhouse \ No newline at end of file diff --git a/plugin/storage/clickhouse/config_test.go b/plugin/storage/clickhouse/config_test.go new file mode 100644 index 00000000000..dc864de3954 --- /dev/null +++ b/plugin/storage/clickhouse/config_test.go @@ -0,0 +1 @@ +package clickhouse \ No newline at end of file diff --git a/plugin/storage/clickhouse/options.go b/plugin/storage/clickhouse/options.go new file mode 100644 index 00000000000..dc864de3954 --- /dev/null +++ b/plugin/storage/clickhouse/options.go @@ -0,0 +1 @@ +package clickhouse \ No newline at end of file diff --git a/plugin/storage/clickhouse/options_test.go b/plugin/storage/clickhouse/options_test.go new file mode 100644 index 00000000000..dc864de3954 --- /dev/null +++ b/plugin/storage/clickhouse/options_test.go @@ -0,0 +1 @@ +package clickhouse \ No newline at end of file From 0d8a1883324b1ea794df2d182d0ed981f4f3dd4b Mon Sep 17 00:00:00 2001 From: adityachopra29 Date: Sat, 25 Jan 2025 23:52:52 +0530 Subject: [PATCH 2/5] create Connection configuration Signed-off-by: adityachopra29 --- plugin/storage/clickhouse/config.go | 82 ++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/plugin/storage/clickhouse/config.go b/plugin/storage/clickhouse/config.go index dc864de3954..1a0ea885682 100644 --- a/plugin/storage/clickhouse/config.go +++ b/plugin/storage/clickhouse/config.go @@ -1 +1,81 @@ -package clickhouse \ No newline at end of file +package clickhouse + +import( + "time" + + "go.opentelemetry.io/collector/config/configtls" +) + +const ( + +) + +// Configuration is clickhouse's internal configuration data +type Configuration struct{ + Connection Connection `mapstructure:"connection"` + +} + +type Connection struct { + // Servers contains a list of hosts that are used to connect to the cluster. + Servers []string `mapstructure:"servers" valid:"required,url"` + // LocalDC contains the name of the local Data Center (DC) for DC-aware host selection + LocalDC string `mapstructure:"local_dc"` + // Database is the database name for Jaeger service on the server + Database string `mapstructure:"database_name"` + // The port used when dialing to a cluster. + Port int `mapstructure:"port"` + // DisableAutoDiscovery, if set to true, will disable the cluster's auto-discovery features. + DisableAutoDiscovery bool `mapstructure:"disable_auto_discovery"` + // ConnectionsPerHost contains the maximum number of open connections for each host on the cluster. + ConnectionsPerHost int `mapstructure:"connections_per_host"` + // ReconnectInterval contains the regular interval after which the driver tries to connect to + // nodes that are down. + ReconnectInterval time.Duration `mapstructure:"reconnect_interval"` + // SocketKeepAlive contains the keep alive period for the default dialer to the cluster. + SocketKeepAlive time.Duration `mapstructure:"socket_keep_alive"` + // TLS contains the TLS configuration for the connection to the cluster. + TLS configtls.ClientConfig `mapstructure:"tls"` + // Timeout contains the maximum time spent to connect to a cluster. + DialTimeout time.Duration `mapstructure:"timeout"` + // MaxIdleConns is the number of connections the pool will keep idle. Default value is 5 + MaxIdleConns int + // MaxOpenConns is the maximum number of active connections to the database at any time. + // Default value is MaxIdleConns + 5 + MaxOpenConns int + // ConnMaxLifetime is the maximum lifetime of a connection in the pool. Default value is 1 hour + // After that connection is stopped and new connection is made + ConnMaxLifetime time.Duration + //ConnOpenStrategy determines how the list of node addresses should be consumed and used + // to open connections. Refer to: https://clickhouse.com/docs/en/integrations/go#connection-settings + ConnOpenStrategy ConnOpenStrategy + // Authenticator contains the details of the authentication mechanism that is used for + // connecting to a cluster. + Authenticator Authenticator `mapstructure:"auth"` + // ProtoVersion contains the version of the native protocol to use when connecting to a cluster. + ProtoVersion int `mapstructure:"proto_version"` + // Compression method used by server + // Takes only 2 values: LZ4 or ZSTD + Compression string `mapstructure:"compression"` +} + +// Authenticator holds the authentication properties needed to connect to a Clickhouse cluster. +type Authenticator struct { + Basic BasicAuthenticator `mapstructure:"basic"` +} + +// BasicAuthenticator holds the username and password for a password authenticator for a Clickhouse cluster. +type BasicAuthenticator struct { + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` +} + +type ConnOpenStrategy uint8 + + +func DefaultConfig () *Configuration { + + return &Configuration{ + + } +} \ No newline at end of file From e9d5ad19cf8aa786a33987edf03c6dc13aadf86f Mon Sep 17 00:00:00 2001 From: adityachopra29 Date: Mon, 27 Jan 2025 22:46:12 +0530 Subject: [PATCH 3/5] create query struct Signed-off-by: adityachopra29 --- plugin/storage/clickhouse/config.go | 39 +++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/plugin/storage/clickhouse/config.go b/plugin/storage/clickhouse/config.go index 1a0ea885682..44b3891308b 100644 --- a/plugin/storage/clickhouse/config.go +++ b/plugin/storage/clickhouse/config.go @@ -1,3 +1,6 @@ +// Copyright (c) 2025 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + package clickhouse import( @@ -6,16 +9,16 @@ import( "go.opentelemetry.io/collector/config/configtls" ) -const ( - -) - // Configuration is clickhouse's internal configuration data type Configuration struct{ Connection Connection `mapstructure:"connection"` - + Schema Schema `mapstructure:"schema"` + Query Query `mapstructure:"query"` } +type Schema struct { + // TODO:Make the schema config +} type Connection struct { // Servers contains a list of hosts that are used to connect to the cluster. Servers []string `mapstructure:"servers" valid:"required,url"` @@ -59,6 +62,18 @@ type Connection struct { Compression string `mapstructure:"compression"` } +type Query struct { + // Timeout contains the maximum time spent executing a query. + Timeout time.Duration `mapstructure:"timeout"` + // MaxRetryAttempts indicates the maximum number of times a query will be retried for execution. + MaxRetryAttempts int `mapstructure:"max_retry_attempts"` + // DistributedRetries specifies how many times a distributed query should be retried on failure. + DistributedRetries int `mapstructure:"distributed_retries"` + // UseCompression specifies if query results should be compressed. + UseCompression bool `mapstructure:"use_compression"` +} + + // Authenticator holds the authentication properties needed to connect to a Clickhouse cluster. type Authenticator struct { Basic BasicAuthenticator `mapstructure:"basic"` @@ -73,9 +88,17 @@ type BasicAuthenticator struct { type ConnOpenStrategy uint8 -func DefaultConfig () *Configuration { - +func DefaultConfiguration () *Configuration { return &Configuration{ - + Connection: Connection{ + Servers: []string{"127.0.0.1"}, + Port: 9042, + ProtoVersion: 4, + ConnectionsPerHost: 2, + ReconnectInterval: 60 * time.Second, + }, + Query: Query{ + MaxRetryAttempts: 3, + }, } } \ No newline at end of file From c16960cdf9142f3cdd91e6c041bbc8a10d816544 Mon Sep 17 00:00:00 2001 From: adityachopra29 Date: Mon, 27 Jan 2025 22:58:19 +0530 Subject: [PATCH 4/5] fix lint Signed-off-by: adityachopra29 --- plugin/storage/clickhouse/config.go | 20 +++++++++----------- plugin/storage/clickhouse/config_test.go | 5 ++++- plugin/storage/clickhouse/options.go | 5 ++++- plugin/storage/clickhouse/options_test.go | 5 ++++- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/plugin/storage/clickhouse/config.go b/plugin/storage/clickhouse/config.go index 44b3891308b..58c9ec9e3e8 100644 --- a/plugin/storage/clickhouse/config.go +++ b/plugin/storage/clickhouse/config.go @@ -3,17 +3,17 @@ package clickhouse -import( +import ( "time" "go.opentelemetry.io/collector/config/configtls" ) // Configuration is clickhouse's internal configuration data -type Configuration struct{ +type Configuration struct { Connection Connection `mapstructure:"connection"` - Schema Schema `mapstructure:"schema"` - Query Query `mapstructure:"query"` + Schema Schema `mapstructure:"schema"` + Query Query `mapstructure:"query"` } type Schema struct { @@ -49,7 +49,7 @@ type Connection struct { // ConnMaxLifetime is the maximum lifetime of a connection in the pool. Default value is 1 hour // After that connection is stopped and new connection is made ConnMaxLifetime time.Duration - //ConnOpenStrategy determines how the list of node addresses should be consumed and used + // ConnOpenStrategy determines how the list of node addresses should be consumed and used // to open connections. Refer to: https://clickhouse.com/docs/en/integrations/go#connection-settings ConnOpenStrategy ConnOpenStrategy // Authenticator contains the details of the authentication mechanism that is used for @@ -73,7 +73,6 @@ type Query struct { UseCompression bool `mapstructure:"use_compression"` } - // Authenticator holds the authentication properties needed to connect to a Clickhouse cluster. type Authenticator struct { Basic BasicAuthenticator `mapstructure:"basic"` @@ -81,14 +80,13 @@ type Authenticator struct { // BasicAuthenticator holds the username and password for a password authenticator for a Clickhouse cluster. type BasicAuthenticator struct { - Username string `mapstructure:"username"` - Password string `mapstructure:"password"` + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` } type ConnOpenStrategy uint8 - -func DefaultConfiguration () *Configuration { +func DefaultConfiguration() *Configuration { return &Configuration{ Connection: Connection{ Servers: []string{"127.0.0.1"}, @@ -101,4 +99,4 @@ func DefaultConfiguration () *Configuration { MaxRetryAttempts: 3, }, } -} \ No newline at end of file +} diff --git a/plugin/storage/clickhouse/config_test.go b/plugin/storage/clickhouse/config_test.go index dc864de3954..0d735662d52 100644 --- a/plugin/storage/clickhouse/config_test.go +++ b/plugin/storage/clickhouse/config_test.go @@ -1 +1,4 @@ -package clickhouse \ No newline at end of file +// Copyright (c) 2025 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse diff --git a/plugin/storage/clickhouse/options.go b/plugin/storage/clickhouse/options.go index dc864de3954..0d735662d52 100644 --- a/plugin/storage/clickhouse/options.go +++ b/plugin/storage/clickhouse/options.go @@ -1 +1,4 @@ -package clickhouse \ No newline at end of file +// Copyright (c) 2025 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse diff --git a/plugin/storage/clickhouse/options_test.go b/plugin/storage/clickhouse/options_test.go index dc864de3954..0d735662d52 100644 --- a/plugin/storage/clickhouse/options_test.go +++ b/plugin/storage/clickhouse/options_test.go @@ -1 +1,4 @@ -package clickhouse \ No newline at end of file +// Copyright (c) 2025 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse From 15369836a2ca7e0594864b30a3a3dcde753c6a8f Mon Sep 17 00:00:00 2001 From: adityachopra29 Date: Tue, 28 Jan 2025 23:20:15 +0530 Subject: [PATCH 5/5] remove extra config, move config to pkg/ Signed-off-by: adityachopra29 --- pkg/clickhouse/config/config.go | 41 +++++++ .../clickhouse/config}/config_test.go | 0 plugin/storage/clickhouse/config.go | 102 ------------------ plugin/storage/clickhouse/options.go | 4 - plugin/storage/clickhouse/options_test.go | 4 - 5 files changed, 41 insertions(+), 110 deletions(-) create mode 100644 pkg/clickhouse/config/config.go rename {plugin/storage/clickhouse => pkg/clickhouse/config}/config_test.go (100%) delete mode 100644 plugin/storage/clickhouse/config.go delete mode 100644 plugin/storage/clickhouse/options.go delete mode 100644 plugin/storage/clickhouse/options_test.go diff --git a/pkg/clickhouse/config/config.go b/pkg/clickhouse/config/config.go new file mode 100644 index 00000000000..e4ebb13f672 --- /dev/null +++ b/pkg/clickhouse/config/config.go @@ -0,0 +1,41 @@ +// Copyright (c) 2025 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse + +// Configuration is clickhouse's internal configuration data +type Configuration struct { + Connection Connection `mapstructure:"connection"` +} + +type Connection struct { + // Servers contains a list of hosts that are used to connect to the cluster. + Servers []string `mapstructure:"servers" valid:"required,url"` + // Database is the database name for Jaeger service on the server + Database string `mapstructure:"database_name"` + // The port used when dialing to a cluster. + Port int `mapstructure:"port"` + // Authenticator contains the details of the authentication mechanism that is used for + // connecting to a cluster. + Authenticator Authenticator `mapstructure:"auth"` +} + +// Authenticator holds the authentication properties needed to connect to a Clickhouse cluster. +type Authenticator struct { + Basic BasicAuthenticator `mapstructure:"basic"` +} + +// BasicAuthenticator holds the username and password for a password authenticator for a Clickhouse cluster. +type BasicAuthenticator struct { + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` +} + +func DefaultConfiguration() *Configuration { + return &Configuration{ + Connection: Connection{ + Servers: []string{"127.0.0.1"}, + Port: 9000, + }, + } +} diff --git a/plugin/storage/clickhouse/config_test.go b/pkg/clickhouse/config/config_test.go similarity index 100% rename from plugin/storage/clickhouse/config_test.go rename to pkg/clickhouse/config/config_test.go diff --git a/plugin/storage/clickhouse/config.go b/plugin/storage/clickhouse/config.go deleted file mode 100644 index 58c9ec9e3e8..00000000000 --- a/plugin/storage/clickhouse/config.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) 2025 The Jaeger Authors. -// SPDX-License-Identifier: Apache-2.0 - -package clickhouse - -import ( - "time" - - "go.opentelemetry.io/collector/config/configtls" -) - -// Configuration is clickhouse's internal configuration data -type Configuration struct { - Connection Connection `mapstructure:"connection"` - Schema Schema `mapstructure:"schema"` - Query Query `mapstructure:"query"` -} - -type Schema struct { - // TODO:Make the schema config -} -type Connection struct { - // Servers contains a list of hosts that are used to connect to the cluster. - Servers []string `mapstructure:"servers" valid:"required,url"` - // LocalDC contains the name of the local Data Center (DC) for DC-aware host selection - LocalDC string `mapstructure:"local_dc"` - // Database is the database name for Jaeger service on the server - Database string `mapstructure:"database_name"` - // The port used when dialing to a cluster. - Port int `mapstructure:"port"` - // DisableAutoDiscovery, if set to true, will disable the cluster's auto-discovery features. - DisableAutoDiscovery bool `mapstructure:"disable_auto_discovery"` - // ConnectionsPerHost contains the maximum number of open connections for each host on the cluster. - ConnectionsPerHost int `mapstructure:"connections_per_host"` - // ReconnectInterval contains the regular interval after which the driver tries to connect to - // nodes that are down. - ReconnectInterval time.Duration `mapstructure:"reconnect_interval"` - // SocketKeepAlive contains the keep alive period for the default dialer to the cluster. - SocketKeepAlive time.Duration `mapstructure:"socket_keep_alive"` - // TLS contains the TLS configuration for the connection to the cluster. - TLS configtls.ClientConfig `mapstructure:"tls"` - // Timeout contains the maximum time spent to connect to a cluster. - DialTimeout time.Duration `mapstructure:"timeout"` - // MaxIdleConns is the number of connections the pool will keep idle. Default value is 5 - MaxIdleConns int - // MaxOpenConns is the maximum number of active connections to the database at any time. - // Default value is MaxIdleConns + 5 - MaxOpenConns int - // ConnMaxLifetime is the maximum lifetime of a connection in the pool. Default value is 1 hour - // After that connection is stopped and new connection is made - ConnMaxLifetime time.Duration - // ConnOpenStrategy determines how the list of node addresses should be consumed and used - // to open connections. Refer to: https://clickhouse.com/docs/en/integrations/go#connection-settings - ConnOpenStrategy ConnOpenStrategy - // Authenticator contains the details of the authentication mechanism that is used for - // connecting to a cluster. - Authenticator Authenticator `mapstructure:"auth"` - // ProtoVersion contains the version of the native protocol to use when connecting to a cluster. - ProtoVersion int `mapstructure:"proto_version"` - // Compression method used by server - // Takes only 2 values: LZ4 or ZSTD - Compression string `mapstructure:"compression"` -} - -type Query struct { - // Timeout contains the maximum time spent executing a query. - Timeout time.Duration `mapstructure:"timeout"` - // MaxRetryAttempts indicates the maximum number of times a query will be retried for execution. - MaxRetryAttempts int `mapstructure:"max_retry_attempts"` - // DistributedRetries specifies how many times a distributed query should be retried on failure. - DistributedRetries int `mapstructure:"distributed_retries"` - // UseCompression specifies if query results should be compressed. - UseCompression bool `mapstructure:"use_compression"` -} - -// Authenticator holds the authentication properties needed to connect to a Clickhouse cluster. -type Authenticator struct { - Basic BasicAuthenticator `mapstructure:"basic"` -} - -// BasicAuthenticator holds the username and password for a password authenticator for a Clickhouse cluster. -type BasicAuthenticator struct { - Username string `mapstructure:"username"` - Password string `mapstructure:"password"` -} - -type ConnOpenStrategy uint8 - -func DefaultConfiguration() *Configuration { - return &Configuration{ - Connection: Connection{ - Servers: []string{"127.0.0.1"}, - Port: 9042, - ProtoVersion: 4, - ConnectionsPerHost: 2, - ReconnectInterval: 60 * time.Second, - }, - Query: Query{ - MaxRetryAttempts: 3, - }, - } -} diff --git a/plugin/storage/clickhouse/options.go b/plugin/storage/clickhouse/options.go deleted file mode 100644 index 0d735662d52..00000000000 --- a/plugin/storage/clickhouse/options.go +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Jaeger Authors. -// SPDX-License-Identifier: Apache-2.0 - -package clickhouse diff --git a/plugin/storage/clickhouse/options_test.go b/plugin/storage/clickhouse/options_test.go deleted file mode 100644 index 0d735662d52..00000000000 --- a/plugin/storage/clickhouse/options_test.go +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Jaeger Authors. -// SPDX-License-Identifier: Apache-2.0 - -package clickhouse