Skip to content

Commit 7d40f52

Browse files
SpencerTorresmx-psi
authored andcommitted
[exporter/clickhouse] Add compress option to config, enabled by default (open-telemetry#34365)
**Description:** This change adds a new `compress` option to the config and sets it to `lz4` by default. In the current version of the exporter, users must know to provide `compress` in the DSN URL to gain the network performance benefits of compression. The only way they would have known this before is if they copied the sample from the README, but this is likely replaced when they paste their server address. ClickHouse has excellent compression for storage and network. It is recommended to enable it for clients such as the OTel exporter to improve performance. In summary: - Added `compress` field to config - `endpoint` (DSN URL) and `connection_params` takes priority - If left empty from all sources, will default to `lz4` - Valid options are based on the underlying `clickhouse-go` driver: `none` (disabled), `zstd`, `lz4` (default), `gzip`, `deflate`, `br`, `true` (lz4). The `true` option comes from an older version of `clickhouse-go` and is an alias for `lz4`. To prevent unexpected changes in behavior, I have manually re-added this check to the config parser instead of assuming the driver will still interpret it as `lz4`. **Testing:** - Updated unit tests for DSN + config parsing - Ran integration tests locally **Documentation:** - Updated README config options list + sample - Added changelog --------- Co-authored-by: Pablo Baeyens <[email protected]>
1 parent a1c47eb commit 7d40f52

File tree

4 files changed

+96
-22
lines changed

4 files changed

+96
-22
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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: "Add `compress` option to ClickHouse exporter, with default value of `lz4`"
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: [34365]
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+
This change adds a new `compress` option to the config field and enables it by default.
20+
Prior to this change, compression was not enabled by default.
21+
The only way to enable compression prior to this change was via the DSN URL.
22+
With this change, `lz4` compression will be enabled by default.
23+
The list of valid options is provided by the underlying `clickhouse-go` driver.
24+
While this change is marked as breaking, there should be no effect to existing deployments by enabling compression.
25+
Compression should improve network performance on most deployments that have a remote ClickHouse server.
26+
27+
# If your change doesn't affect end users or the exported elements of any package,
28+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
29+
# Optional: The change log or logs in which this entry should be included.
30+
# e.g. '[user]' or '[user, api]'
31+
# Include 'user' if the change is relevant to end users.
32+
# Include 'api' if there is a change to a library API.
33+
# Default: '[user]'
34+
change_logs: []

exporter/clickhouseexporter/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ Connection options:
287287
- `database` (default = default): The database name. Overrides the database defined in `endpoint` when this setting is not equal to `default`.
288288
- `connection_params` (default = {}). Params is the extra connection parameters with map format. Query parameters provided in `endpoint` will be individually overwritten if present in this map.
289289
- `create_schema` (default = true): When set to true, will run DDL to create the database and tables. (See [schema management](#schema-management))
290+
- `compress` (default = lz4): Controls the compression algorithm. Valid options: `none` (disabled), `zstd`, `lz4` (default), `gzip`, `deflate`, `br`, `true` (lz4). Ignored if `compress` is set in the `endpoint` or `connection_params`.
290291
- `async_insert` (default = true): Enables [async inserts](https://clickhouse.com/docs/en/optimize/asynchronous-inserts). Ignored if async inserts are configured in the `endpoint` or `connection_params`. Async inserts may still be overridden server-side.
291292

292293
ClickHouse tables:
@@ -356,10 +357,11 @@ processors:
356357
send_batch_size: 100000
357358
exporters:
358359
clickhouse:
359-
endpoint: tcp://127.0.0.1:9000?dial_timeout=10s&compress=lz4
360+
endpoint: tcp://127.0.0.1:9000?dial_timeout=10s
360361
database: otel
361362
async_insert: true
362363
ttl: 72h
364+
compress: lz4
363365
create_schema: true
364366
logs_table_name: otel_logs
365367
traces_table_name: otel_traces

exporter/clickhouseexporter/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type Config struct {
4646
ClusterName string `mapstructure:"cluster_name"`
4747
// CreateSchema if set to true will run the DDL for creating the database and tables. default is true.
4848
CreateSchema bool `mapstructure:"create_schema"`
49+
// Compress controls the compression algorithm. Valid options: `none` (disabled), `zstd`, `lz4` (default), `gzip`, `deflate`, `br`, `true` (lz4).
50+
Compress string `mapstructure:"compress"`
4951
// AsyncInsert if true will enable async inserts. Default is `true`.
5052
// Ignored if async inserts are configured in the `endpoint` or `connection_params`.
5153
// Async inserts may still be overridden server-side.
@@ -108,6 +110,12 @@ func (cfg *Config) buildDSN() (string, error) {
108110
queryParams.Set("async_insert", fmt.Sprintf("%t", cfg.AsyncInsert))
109111
}
110112

113+
if !queryParams.Has("compress") && (cfg.Compress == "" || cfg.Compress == "true") {
114+
queryParams.Set("compress", "lz4")
115+
} else if !queryParams.Has("compress") {
116+
queryParams.Set("compress", cfg.Compress)
117+
}
118+
111119
// Use database from config if not specified in path, or if config is not default.
112120
if dsnURL.Path == "" || cfg.Database != defaultDatabase {
113121
dsnURL.Path = cfg.Database

exporter/clickhouseexporter/config_test.go

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func TestConfig_buildDSN(t *testing.T) {
108108
Username string
109109
Password string
110110
Database string
111+
Compress string
111112
ConnectionParams map[string]string
112113
AsyncInsert *bool
113114
}
@@ -127,6 +128,9 @@ func TestConfig_buildDSN(t *testing.T) {
127128
if fields.ConnectionParams != nil {
128129
cfg.ConnectionParams = fields.ConnectionParams
129130
}
131+
if fields.Compress != "" {
132+
cfg.Compress = fields.Compress
133+
}
130134
if fields.AsyncInsert != nil {
131135
cfg.AsyncInsert = *fields.AsyncInsert
132136
}
@@ -155,7 +159,7 @@ func TestConfig_buildDSN(t *testing.T) {
155159
wantChOptions: ChOptions{
156160
Secure: false,
157161
},
158-
want: "clickhouse://127.0.0.1:9000/default?async_insert=true",
162+
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&compress=lz4",
159163
},
160164
{
161165
name: "Support tcp scheme",
@@ -165,7 +169,7 @@ func TestConfig_buildDSN(t *testing.T) {
165169
wantChOptions: ChOptions{
166170
Secure: false,
167171
},
168-
want: "tcp://127.0.0.1:9000/default?async_insert=true",
172+
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4",
169173
},
170174
{
171175
name: "prefers database name from config over from DSN",
@@ -178,7 +182,7 @@ func TestConfig_buildDSN(t *testing.T) {
178182
wantChOptions: ChOptions{
179183
Secure: false,
180184
},
181-
want: "clickhouse://foo:[email protected]:9000/otel?async_insert=true",
185+
want: "clickhouse://foo:[email protected]:9000/otel?async_insert=true&compress=lz4",
182186
},
183187
{
184188
name: "use database name from DSN if not set in config",
@@ -190,7 +194,7 @@ func TestConfig_buildDSN(t *testing.T) {
190194
wantChOptions: ChOptions{
191195
Secure: false,
192196
},
193-
want: "clickhouse://foo:[email protected]:9000/otel?async_insert=true",
197+
want: "clickhouse://foo:[email protected]:9000/otel?async_insert=true&compress=lz4",
194198
},
195199
{
196200
name: "invalid config",
@@ -210,29 +214,29 @@ func TestConfig_buildDSN(t *testing.T) {
210214
wantChOptions: ChOptions{
211215
Secure: true,
212216
},
213-
want: "https://127.0.0.1:9000/default?async_insert=true&secure=true",
217+
want: "https://127.0.0.1:9000/default?async_insert=true&compress=lz4&secure=true",
214218
},
215219
{
216220
name: "Preserve query parameters",
217221
fields: fields{
218-
Endpoint: "clickhouse://127.0.0.1:9000?secure=true&foo=bar",
222+
Endpoint: "clickhouse://127.0.0.1:9000?secure=true&compress=lz4&foo=bar",
219223
},
220224
wantChOptions: ChOptions{
221225
Secure: true,
222226
},
223-
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&foo=bar&secure=true",
227+
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&compress=lz4&foo=bar&secure=true",
224228
},
225229
{
226230
name: "Parse clickhouse settings",
227231
fields: fields{
228-
Endpoint: "https://127.0.0.1:9000?secure=true&dial_timeout=30s&compress=lz4",
232+
Endpoint: "https://127.0.0.1:9000?secure=true&dial_timeout=30s&compress=br",
229233
},
230234
wantChOptions: ChOptions{
231235
Secure: true,
232236
DialTimeout: 30 * time.Second,
233-
Compress: clickhouse.CompressionLZ4,
237+
Compress: clickhouse.CompressionBrotli,
234238
},
235-
want: "https://127.0.0.1:9000/default?async_insert=true&compress=lz4&dial_timeout=30s&secure=true",
239+
want: "https://127.0.0.1:9000/default?async_insert=true&compress=br&dial_timeout=30s&secure=true",
236240
},
237241
{
238242
name: "Should respect connection parameters",
@@ -243,29 +247,29 @@ func TestConfig_buildDSN(t *testing.T) {
243247
wantChOptions: ChOptions{
244248
Secure: true,
245249
},
246-
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&foo=bar&secure=true",
250+
want: "clickhouse://127.0.0.1:9000/default?async_insert=true&compress=lz4&foo=bar&secure=true",
247251
},
248252
{
249253
name: "support replace database in DSN with config to override database",
250254
fields: fields{
251255
Endpoint: "tcp://127.0.0.1:9000/otel",
252256
Database: "override",
253257
},
254-
want: "tcp://127.0.0.1:9000/override?async_insert=true",
258+
want: "tcp://127.0.0.1:9000/override?async_insert=true&compress=lz4",
255259
},
256260
{
257261
name: "when config option is missing, preserve async_insert false in DSN",
258262
fields: fields{
259263
Endpoint: "tcp://127.0.0.1:9000?async_insert=false",
260264
},
261-
want: "tcp://127.0.0.1:9000/default?async_insert=false",
265+
want: "tcp://127.0.0.1:9000/default?async_insert=false&compress=lz4",
262266
},
263267
{
264268
name: "when config option is missing, preserve async_insert true in DSN",
265269
fields: fields{
266270
Endpoint: "tcp://127.0.0.1:9000?async_insert=true",
267271
},
268-
want: "tcp://127.0.0.1:9000/default?async_insert=true",
272+
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4",
269273
},
270274
{
271275
name: "ignore config option when async_insert is present in connection params as false",
@@ -275,7 +279,7 @@ func TestConfig_buildDSN(t *testing.T) {
275279
AsyncInsert: &configTrue,
276280
},
277281

278-
want: "tcp://127.0.0.1:9000/default?async_insert=false",
282+
want: "tcp://127.0.0.1:9000/default?async_insert=false&compress=lz4",
279283
},
280284
{
281285
name: "ignore config option when async_insert is present in connection params as true",
@@ -285,7 +289,7 @@ func TestConfig_buildDSN(t *testing.T) {
285289
AsyncInsert: &configFalse,
286290
},
287291

288-
want: "tcp://127.0.0.1:9000/default?async_insert=true",
292+
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4",
289293
},
290294
{
291295
name: "ignore config option when async_insert is present in DSN as false",
@@ -294,7 +298,7 @@ func TestConfig_buildDSN(t *testing.T) {
294298
AsyncInsert: &configTrue,
295299
},
296300

297-
want: "tcp://127.0.0.1:9000/default?async_insert=false",
301+
want: "tcp://127.0.0.1:9000/default?async_insert=false&compress=lz4",
298302
},
299303
{
300304
name: "use async_insert true config option when it is not present in DSN",
@@ -303,7 +307,7 @@ func TestConfig_buildDSN(t *testing.T) {
303307
AsyncInsert: &configTrue,
304308
},
305309

306-
want: "tcp://127.0.0.1:9000/default?async_insert=true",
310+
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4",
307311
},
308312
{
309313
name: "use async_insert false config option when it is not present in DSN",
@@ -312,15 +316,15 @@ func TestConfig_buildDSN(t *testing.T) {
312316
AsyncInsert: &configFalse,
313317
},
314318

315-
want: "tcp://127.0.0.1:9000/default?async_insert=false",
319+
want: "tcp://127.0.0.1:9000/default?async_insert=false&compress=lz4",
316320
},
317321
{
318322
name: "set async_insert to true when not present in config or DSN",
319323
fields: fields{
320324
Endpoint: "tcp://127.0.0.1:9000",
321325
},
322326

323-
want: "tcp://127.0.0.1:9000/default?async_insert=true",
327+
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4",
324328
},
325329
{
326330
name: "connection_params takes priority over endpoint and async_insert option.",
@@ -330,7 +334,33 @@ func TestConfig_buildDSN(t *testing.T) {
330334
AsyncInsert: &configFalse,
331335
},
332336

333-
want: "tcp://127.0.0.1:9000/default?async_insert=true",
337+
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4",
338+
},
339+
{
340+
name: "use compress br config option when it is not present in DSN",
341+
fields: fields{
342+
Endpoint: "tcp://127.0.0.1:9000",
343+
Compress: "br",
344+
},
345+
346+
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=br",
347+
},
348+
{
349+
name: "set compress to lz4 when not present in config or DSN",
350+
fields: fields{
351+
Endpoint: "tcp://127.0.0.1:9000",
352+
},
353+
354+
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=lz4",
355+
},
356+
{
357+
name: "connection_params takes priority over endpoint and compress option.",
358+
fields: fields{
359+
Endpoint: "tcp://127.0.0.1:9000?compress=none",
360+
ConnectionParams: map[string]string{"compress": "br"},
361+
Compress: "lz4",
362+
},
363+
want: "tcp://127.0.0.1:9000/default?async_insert=true&compress=br",
334364
},
335365
}
336366
for _, tt := range tests {

0 commit comments

Comments
 (0)