Skip to content

Commit

Permalink
[exporter/clickhouse]: Add persistent queue support (#28579)
Browse files Browse the repository at this point in the history
Addresses #27653.

**Description:**
Added persistent storage queue support by leveraging default
`exporthelper.QueueSettings` config structure.

**NOTE** This does end up being a **breaking** change to the API.
  • Loading branch information
fredthomsen authored Oct 29, 2023
1 parent f8cbcc2 commit 3d94380
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 24 deletions.
27 changes: 27 additions & 0 deletions .chloggen/clickhouseexporter-persistentqueue-support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

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

# 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: Add persistent storage support to clickhouse exporter

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

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

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

# 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: Replace `Config.QueueSettings` field with `exporterhelper.QueueSettings` and remove `QueueSettings` struct

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

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
18 changes: 1 addition & 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 @@ -74,14 +66,6 @@ func (cfg *Config) Validate() (err error) {
return err
}

func (cfg *Config) enforcedQueueSettings() exporterhelper.QueueSettings {
return exporterhelper.QueueSettings{
Enabled: true,
NumConsumers: 1,
QueueSize: cfg.QueueSettings.QueueSize,
}
}

func (cfg *Config) buildDSN(database string) (string, error) {
dsnURL, err := url.Parse(cfg.Endpoint)
if err != nil {
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: 1,
QueueSize: 100,
StorageID: &storageID,
},
},
},
Expand Down
11 changes: 7 additions & 4 deletions exporter/clickhouseexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ func NewFactory() exporter.Factory {
}

func createDefaultConfig() component.Config {
queueSettings := exporterhelper.NewDefaultQueueSettings()
queueSettings.NumConsumers = 1

return &Config{
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
QueueSettings: QueueSettings{QueueSize: exporterhelper.NewDefaultQueueSettings().QueueSize},
QueueSettings: queueSettings,
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
ConnectionParams: map[string]string{},
Database: defaultDatabase,
Expand Down Expand Up @@ -62,7 +65,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 +91,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 +115,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),
)
}
3 changes: 2 additions & 1 deletion exporter/clickhouseexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ clickhouse/full:
max_elapsed_time: 300s
sending_queue:
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 3d94380

Please sign in to comment.