Skip to content

Commit 0fb17f2

Browse files
[clickhouse/exporter] Update create schema config option (#33694)
#### EXTRACTED FROM #33614 #### DEPENDS ON #33693 **Description:** A follow-up to #32282 that changes `create_schema` from `*bool` to `bool`, while also properly using the default config / factory. **Testing:** - Updated tests --------- Co-authored-by: Dmitrii Anoshin <[email protected]>
1 parent 8ac86f8 commit 0fb17f2

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
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: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: exporter/clickhouse
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Change internal config type for `create_schema` to use a `bool` instead of `*bool`"
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: [33694]
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: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Config struct {
4545
// ClusterName if set will append `ON CLUSTER` with the provided name when creating tables.
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.
48-
CreateSchema *bool `mapstructure:"create_schema"`
48+
CreateSchema bool `mapstructure:"create_schema"`
4949
}
5050

5151
// TableEngine defines the ENGINE string value when creating the table.
@@ -133,11 +133,7 @@ func (cfg *Config) buildDB() (*sql.DB, error) {
133133

134134
// shouldCreateSchema returns true if the exporter should run the DDL for creating database/tables.
135135
func (cfg *Config) shouldCreateSchema() bool {
136-
if cfg.CreateSchema == nil {
137-
return true // default to true
138-
}
139-
140-
return *cfg.CreateSchema
136+
return cfg.CreateSchema
141137
}
142138

143139
// tableEngineString generates the ENGINE string.

exporter/clickhouseexporter/config_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestLoadConfig(t *testing.T) {
3333
defaultCfg := createDefaultConfig()
3434
defaultCfg.(*Config).Endpoint = defaultEndpoint
3535

36-
createSchema := true
3736
storageID := component.MustNewIDWithName("file_storage", "clickhouse")
3837

3938
tests := []struct {
@@ -56,7 +55,7 @@ func TestLoadConfig(t *testing.T) {
5655
LogsTableName: "otel_logs",
5756
TracesTableName: "otel_traces",
5857
MetricsTableName: "otel_metrics",
59-
CreateSchema: &createSchema,
58+
CreateSchema: true,
6059
TimeoutSettings: exporterhelper.TimeoutSettings{
6160
Timeout: 5 * time.Second,
6261
},
@@ -275,14 +274,11 @@ func TestConfig_buildDSN(t *testing.T) {
275274
func TestShouldCreateSchema(t *testing.T) {
276275
t.Parallel()
277276

278-
createSchemaTrue := true
279-
createSchemaFalse := false
280-
281277
caseDefault := createDefaultConfig().(*Config)
282278
caseCreateSchemaTrue := createDefaultConfig().(*Config)
283-
caseCreateSchemaTrue.CreateSchema = &createSchemaTrue
279+
caseCreateSchemaTrue.CreateSchema = true
284280
caseCreateSchemaFalse := createDefaultConfig().(*Config)
285-
caseCreateSchemaFalse.CreateSchema = &createSchemaFalse
281+
caseCreateSchemaFalse.CreateSchema = false
286282

287283
tests := []struct {
288284
name string

exporter/clickhouseexporter/factory.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func NewFactory() exporter.Factory {
3232
func createDefaultConfig() component.Config {
3333
queueSettings := exporterhelper.NewDefaultQueueSettings()
3434
queueSettings.NumConsumers = 1
35-
defaultCreateSchema := true
3635

3736
return &Config{
3837
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
@@ -44,7 +43,7 @@ func createDefaultConfig() component.Config {
4443
TracesTableName: "otel_traces",
4544
MetricsTableName: "otel_metrics",
4645
TTL: 0,
47-
CreateSchema: &defaultCreateSchema,
46+
CreateSchema: true,
4847
}
4948
}
5049

0 commit comments

Comments
 (0)