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

68 lines
2.3 KiB
Go

package clickhousetracesexporter
import (
"path"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/zeebo/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configoptional"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/otelcol/otelcoltest"
"github.com/hanzoai/otel-collector/exporter/clickhousetracesexporter/internal/metadata"
)
// TestLoadConfig checks whether yaml configuration can be loaded correctly
func Test_loadConfig(t *testing.T) {
factories, err := otelcoltest.NopFactories()
assert.NoError(t, err)
factory := NewFactory()
factories.Exporters[metadata.Type] = factory
cfg, err := otelcoltest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories)
require.NoError(t, err)
require.NotNil(t, cfg)
// From the default configurations -- checks if a correct exporter is instantiated
e0 := cfg.Exporters[(component.NewID(metadata.Type))]
defaultCfg := factory.CreateDefaultConfig()
defaultCfg.(*Config).Datasource = "tcp://127.0.0.1:9000/?database=signoz_traces&username=admin&password=password"
assert.Equal(t, e0, defaultCfg)
// checks if the correct Config struct can be instantiated from testdata/config.yaml
e1 := cfg.Exporters[component.NewIDWithName(metadata.Type, "2")]
actualCfg := e1.(*Config)
expectedBatch := configoptional.Default(exporterhelper.BatchConfig{
FlushTimeout: 200 * time.Millisecond,
Sizer: exporterhelper.RequestSizerTypeItems,
MinSize: 8192,
})
assert.Equal(t, &Config{
TimeoutConfig: exporterhelper.TimeoutConfig{Timeout: 5 * time.Second},
BackOffConfig: configretry.BackOffConfig{
Enabled: true,
InitialInterval: 5 * time.Second,
MaxInterval: 30 * time.Second,
MaxElapsedTime: 300 * time.Second,
RandomizationFactor: 0.7,
Multiplier: 1.3,
},
QueueBatchConfig: configoptional.Some(exporterhelper.QueueBatchConfig{
Sizer: exporterhelper.RequestSizerTypeRequests,
NumConsumers: 5,
QueueSize: 100,
Batch: expectedBatch,
}),
Datasource: "tcp://127.0.0.1:9000/?database=signoz_traces&username=admin&password=password",
AttributesLimits: AttributesLimits{
FetchKeysInterval: 10 * time.Minute,
MaxDistinctValues: 25000,
},
}, actualCfg)
}