Files
zeekay 2c424150e8 fix(data): revert database names to signoz_* for backward compat
The rebrand renamed ClickHouse databases (signoz_traces → o11y_traces etc.)
but existing production databases still use signoz_* names. Revert to
avoid breaking data access.
2026-03-12 02:29:37 -07:00

78 lines
1.9 KiB
Go

package clickhouselogsexporter
import (
"fmt"
driver "github.com/ClickHouse/clickhouse-go/v2/lib/driver"
"github.com/hanzoai/otel-collector/usage"
"github.com/google/uuid"
"github.com/jellydator/ttlcache/v3"
"go.opentelemetry.io/otel/metric"
"go.uber.org/zap"
)
type LogExporterOption func(*clickhouseLogsExporter)
func WithClickHouseClient(client driver.Conn) LogExporterOption {
return func(e *clickhouseLogsExporter) {
e.db = client
}
}
func WithLogger(logger *zap.Logger) LogExporterOption {
return func(e *clickhouseLogsExporter) {
e.logger = logger
}
}
func WithNewUsageCollector(id uuid.UUID, db driver.Conn) LogExporterOption {
return func(e *clickhouseLogsExporter) {
e.usageCollector = usage.NewUsageCollector(
id,
e.db,
usage.Options{
ReportingInterval: usage.DefaultCollectionInterval,
},
"signoz_logs",
UsageExporter,
e.logger,
)
// TODO: handle error
_ = e.usageCollector.Start()
e.id = id
}
}
func WithMeter(meter metric.Meter) LogExporterOption {
return func(e *clickhouseLogsExporter) {
durationHistogram, err := meter.Float64Histogram(
"exporter_db_write_latency",
metric.WithDescription("Time taken to write data to ClickHouse"),
metric.WithUnit("ms"),
metric.WithExplicitBucketBoundaries(250, 500, 750, 1000, 2000, 2500, 3000, 4000, 5000, 6000, 8000, 10000, 15000, 25000, 30000),
)
if err != nil {
panic(fmt.Errorf("error creating duration histogram: %w", err))
}
e.durationHistogram = durationHistogram
}
}
func WithKeysCache(keysCache *ttlcache.Cache[string, struct{}]) LogExporterOption {
return func(e *clickhouseLogsExporter) {
e.keysCache = keysCache
}
}
func WithRFCache(rfCache *ttlcache.Cache[string, struct{}]) LogExporterOption {
return func(e *clickhouseLogsExporter) {
e.rfCache = rfCache
}
}
func WithConcurrency(concurrency int) LogExporterOption {
return func(e *clickhouseLogsExporter) {
e.limiter = make(chan struct{}, concurrency)
}
}