Skip to content

Commit 3d94380

Browse files
authored
[exporter/clickhouse]: Add persistent queue support (open-telemetry#28579)
Addresses open-telemetry#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.
1 parent f8cbcc2 commit 3d94380

File tree

6 files changed

+71
-24
lines changed

6 files changed

+71
-24
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: clickhouseexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add persistent storage support to clickhouse exporter
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [27653]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: clickhouseexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Replace `Config.QueueSettings` field with `exporterhelper.QueueSettings` and remove `QueueSettings` struct
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [27653]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [api]

exporter/clickhouseexporter/config.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import (
1818
type Config struct {
1919
exporterhelper.TimeoutSettings `mapstructure:",squash"`
2020
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
21-
// QueueSettings is a subset of exporterhelper.QueueSettings,
22-
// because only QueueSize is user-settable.
23-
QueueSettings QueueSettings `mapstructure:"sending_queue"`
21+
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
2422

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

45-
// QueueSettings is a subset of exporterhelper.QueueSettings.
46-
type QueueSettings struct {
47-
// QueueSize set the length of the sending queue
48-
QueueSize int `mapstructure:"queue_size"`
49-
}
50-
5143
const defaultDatabase = "default"
5244

5345
var (
@@ -74,14 +66,6 @@ func (cfg *Config) Validate() (err error) {
7466
return err
7567
}
7668

77-
func (cfg *Config) enforcedQueueSettings() exporterhelper.QueueSettings {
78-
return exporterhelper.QueueSettings{
79-
Enabled: true,
80-
NumConsumers: 1,
81-
QueueSize: cfg.QueueSettings.QueueSize,
82-
}
83-
}
84-
8569
func (cfg *Config) buildDSN(database string) (string, error) {
8670
dsnURL, err := url.Parse(cfg.Endpoint)
8771
if err != nil {

exporter/clickhouseexporter/config_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func TestLoadConfig(t *testing.T) {
3131
defaultCfg := createDefaultConfig()
3232
defaultCfg.(*Config).Endpoint = defaultEndpoint
3333

34+
storageID := component.NewIDWithName(component.Type("file_storage"), "clickhouse")
35+
3436
tests := []struct {
3537
id component.ID
3638
expected component.Config
@@ -63,8 +65,11 @@ func TestLoadConfig(t *testing.T) {
6365
Multiplier: backoff.DefaultMultiplier,
6466
},
6567
ConnectionParams: map[string]string{},
66-
QueueSettings: QueueSettings{
67-
QueueSize: 100,
68+
QueueSettings: exporterhelper.QueueSettings{
69+
Enabled: true,
70+
NumConsumers: 1,
71+
QueueSize: 100,
72+
StorageID: &storageID,
6873
},
6974
},
7075
},

exporter/clickhouseexporter/factory.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ func NewFactory() exporter.Factory {
2828
}
2929

3030
func createDefaultConfig() component.Config {
31+
queueSettings := exporterhelper.NewDefaultQueueSettings()
32+
queueSettings.NumConsumers = 1
33+
3134
return &Config{
3235
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
33-
QueueSettings: QueueSettings{QueueSize: exporterhelper.NewDefaultQueueSettings().QueueSize},
36+
QueueSettings: queueSettings,
3437
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
3538
ConnectionParams: map[string]string{},
3639
Database: defaultDatabase,
@@ -62,7 +65,7 @@ func createLogsExporter(
6265
exporterhelper.WithStart(exporter.start),
6366
exporterhelper.WithShutdown(exporter.shutdown),
6467
exporterhelper.WithTimeout(c.TimeoutSettings),
65-
exporterhelper.WithQueue(c.enforcedQueueSettings()),
68+
exporterhelper.WithQueue(c.QueueSettings),
6669
exporterhelper.WithRetry(c.RetrySettings),
6770
)
6871
}
@@ -88,7 +91,7 @@ func createTracesExporter(
8891
exporterhelper.WithStart(exporter.start),
8992
exporterhelper.WithShutdown(exporter.shutdown),
9093
exporterhelper.WithTimeout(c.TimeoutSettings),
91-
exporterhelper.WithQueue(c.enforcedQueueSettings()),
94+
exporterhelper.WithQueue(c.QueueSettings),
9295
exporterhelper.WithRetry(c.RetrySettings),
9396
)
9497
}
@@ -112,7 +115,7 @@ func createMetricExporter(
112115
exporterhelper.WithStart(exporter.start),
113116
exporterhelper.WithShutdown(exporter.shutdown),
114117
exporterhelper.WithTimeout(c.TimeoutSettings),
115-
exporterhelper.WithQueue(c.enforcedQueueSettings()),
118+
exporterhelper.WithQueue(c.QueueSettings),
116119
exporterhelper.WithRetry(c.RetrySettings),
117120
)
118121
}

exporter/clickhouseexporter/testdata/config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ clickhouse/full:
1616
max_elapsed_time: 300s
1717
sending_queue:
1818
queue_size: 100
19+
storage: file_storage/clickhouse
1920
clickhouse/invalid-endpoint:
20-
endpoint: 127.0.0.1:9000
21+
endpoint: 127.0.0.1:9000

0 commit comments

Comments
 (0)