Skip to content

Commit

Permalink
[exporter/clickhouseexporter]: persistent queue support
Browse files Browse the repository at this point in the history
  • Loading branch information
fredthomsen committed Oct 26, 2023
1 parent 397dbe6 commit 5065081
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
22 changes: 5 additions & 17 deletions exporter/clickhouseexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import (
type Config struct {
exporterhelper.TimeoutSettings `mapstructure:",squash"`
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
// QueueSettings is a subset of exporterhelper.QueueSettings,
// because only QueueSize is user-settable.
QueueSettings QueueSettings `mapstructure:"sending_queue"`
exporterhelper.QueueSettings `mapstructure:"sending_queue"`

// Endpoint is the clickhouse endpoint.
Endpoint string `mapstructure:"endpoint"`
Expand All @@ -42,12 +40,6 @@ type Config struct {
TTLDays uint `mapstructure:"ttl_days"`
}

// QueueSettings is a subset of exporterhelper.QueueSettings.
type QueueSettings struct {
// QueueSize set the length of the sending queue
QueueSize int `mapstructure:"queue_size"`
}

const defaultDatabase = "default"

var (
Expand All @@ -71,15 +63,11 @@ func (cfg *Config) Validate() (err error) {
err = errors.Join(err, e)
}

return err
}

func (cfg *Config) enforcedQueueSettings() exporterhelper.QueueSettings {
return exporterhelper.QueueSettings{
Enabled: true,
NumConsumers: 1,
QueueSize: cfg.QueueSettings.QueueSize,
if err := cfg.QueueSettings.Validate(); err != nil {
err = errors.Join(err, e)
}

return err
}

func (cfg *Config) buildDSN(database string) (string, error) {
Expand Down
9 changes: 7 additions & 2 deletions exporter/clickhouseexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func TestLoadConfig(t *testing.T) {
defaultCfg := createDefaultConfig()
defaultCfg.(*Config).Endpoint = defaultEndpoint

storageID := component.NewIDWithName(component.Type("file_storage"), "clickhouse")

tests := []struct {
id component.ID
expected component.Config
Expand Down Expand Up @@ -63,8 +65,11 @@ func TestLoadConfig(t *testing.T) {
Multiplier: backoff.DefaultMultiplier,
},
ConnectionParams: map[string]string{},
QueueSettings: QueueSettings{
QueueSize: 100,
QueueSettings: exporterhelper.QueueSettings{
Enabled: true,
NumConsumers: 10,
QueueSize: 100,
StorageID: &storageID,
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions exporter/clickhouseexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewFactory() exporter.Factory {
func createDefaultConfig() component.Config {
return &Config{
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
QueueSettings: QueueSettings{QueueSize: exporterhelper.NewDefaultQueueSettings().QueueSize},
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
ConnectionParams: map[string]string{},
Database: defaultDatabase,
Expand Down Expand Up @@ -62,7 +62,7 @@ func createLogsExporter(
exporterhelper.WithStart(exporter.start),
exporterhelper.WithShutdown(exporter.shutdown),
exporterhelper.WithTimeout(c.TimeoutSettings),
exporterhelper.WithQueue(c.enforcedQueueSettings()),
exporterhelper.WithQueue(c.QueueSettings),
exporterhelper.WithRetry(c.RetrySettings),
)
}
Expand All @@ -88,7 +88,7 @@ func createTracesExporter(
exporterhelper.WithStart(exporter.start),
exporterhelper.WithShutdown(exporter.shutdown),
exporterhelper.WithTimeout(c.TimeoutSettings),
exporterhelper.WithQueue(c.enforcedQueueSettings()),
exporterhelper.WithQueue(c.QueueSettings),
exporterhelper.WithRetry(c.RetrySettings),
)
}
Expand All @@ -112,7 +112,7 @@ func createMetricExporter(
exporterhelper.WithStart(exporter.start),
exporterhelper.WithShutdown(exporter.shutdown),
exporterhelper.WithTimeout(c.TimeoutSettings),
exporterhelper.WithQueue(c.enforcedQueueSettings()),
exporterhelper.WithQueue(c.QueueSettings),
exporterhelper.WithRetry(c.RetrySettings),
)
}
4 changes: 3 additions & 1 deletion exporter/clickhouseexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ clickhouse/full:
max_interval: 30s
max_elapsed_time: 300s
sending_queue:
enabled: true
queue_size: 100
storage: file_storage/clickhouse
clickhouse/invalid-endpoint:
endpoint: 127.0.0.1:9000
endpoint: 127.0.0.1:9000

0 comments on commit 5065081

Please sign in to comment.