Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip create table #311

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exporter/clickhouseexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ Connection options:
- `ttl` (default = 0): The data time-to-live example 30m, 48h. Also, 0 means no ttl.
- `database` (default = otel): The database name.
- `connection_params` (default = {}). Params is the extra connection parameters with map format.
- `create_db_and_tables` (default = false). On startup, create the otel database and tables

ClickHouse tables:

Expand Down
3 changes: 2 additions & 1 deletion exporter/clickhouseexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type Config struct {
// Deprecated: Use 'ttl' instead
TTLDays uint `mapstructure:"ttl_days"`
// TTL is The data time-to-live example 30m, 48h. 0 means no ttl.
TTL time.Duration `mapstructure:"ttl"`
TTL time.Duration `mapstructure:"ttl"`
CreateDBAndTables bool `mapstructure:"create_db_and_tables"`
}

const defaultDatabase = "default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ processors:
# action: upsert
exporters:
clickhouse:
create_db_and_tables: true
endpoint: http://clickhouse:8123
database: otel
logs_table_name: otel_logs_1
traces_table_name: otel_traces
connection_params:
async_insert: 1
wait_for_async_insert: 0
ttl_days: 12h
ttl_days: 1
timeout: 10s
sending_queue:
queue_size: 100
Expand Down
11 changes: 7 additions & 4 deletions exporter/clickhouseexporter/exporter_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ func newLogsExporter(logger *zap.Logger, cfg *Config) (*logsExporter, error) {
}

func (e *logsExporter) start(ctx context.Context, _ component.Host) error {
if err := createDatabase(ctx, e.cfg); err != nil {
return err
}
if e.cfg.CreateDBAndTables {
if err := createDatabase(ctx, e.cfg); err != nil {
return err
}

return createLogsTable(ctx, e.cfg, e.client)
return createLogsTable(ctx, e.cfg, e.client)
}
return nil
}

// shutdown will shut down the exporter.
Expand Down
11 changes: 8 additions & 3 deletions exporter/clickhouseexporter/exporter_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ func newMetricsExporter(logger *zap.Logger, cfg *Config) (*metricsExporter, erro
}

func (e *metricsExporter) start(ctx context.Context, _ component.Host) error {
if err := createDatabase(ctx, e.cfg); err != nil {
return err
if e.cfg.CreateDBAndTables {
if err := createDatabase(ctx, e.cfg); err != nil {
return err
}
}

internal.SetLogger(e.logger)

ttlExpr := generateTTLExpr(e.cfg.TTLDays, e.cfg.TTL)
return internal.NewMetricsTable(ctx, e.cfg.MetricsTableName, ttlExpr, e.client)
if e.cfg.CreateDBAndTables {
return internal.NewMetricsTable(ctx, e.cfg.MetricsTableName, ttlExpr, e.client)
}
return nil
}

// shutdown will shut down the exporter.
Expand Down
10 changes: 6 additions & 4 deletions exporter/clickhouseexporter/exporter_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ func newTracesExporter(logger *zap.Logger, cfg *Config) (*tracesExporter, error)
}

func (e *tracesExporter) start(ctx context.Context, _ component.Host) error {
if err := createDatabase(ctx, e.cfg); err != nil {
return err
if e.cfg.CreateDBAndTables {
if err := createDatabase(ctx, e.cfg); err != nil {
return err
}
return createTracesTable(ctx, e.cfg, e.client)
}

return createTracesTable(ctx, e.cfg, e.client)
return nil
}

// shutdown will shut down the exporter.
Expand Down
Loading