Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ff7a946
refactor checkpoint
SpencerTorres May 29, 2025
cd1a250
use fully qualified names for table creation/insertion
SpencerTorres May 30, 2025
068cfe3
remove comment
SpencerTorres May 30, 2025
53579ed
update func call
SpencerTorres May 30, 2025
c453e43
move connection init to Start function, fix some unit tests
SpencerTorres May 30, 2025
200fe05
use new batch.Close func
SpencerTorres Jun 6, 2025
b83af98
createSchema todo
SpencerTorres Jun 6, 2025
44c14d7
fix summary table ddl
SpencerTorres Jun 6, 2025
99d3edc
convert exporter tests to proper integration tests
SpencerTorres Jun 6, 2025
27cb389
remove duplicate tests, add integration build flags, goleak check
SpencerTorres Jun 6, 2025
61540ce
fix lint
SpencerTorres Jun 6, 2025
c4ff013
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
SpencerTorres Jun 6, 2025
3b1a708
remove default_ddl, use sqltemplates folder
SpencerTorres Jun 6, 2025
8d81900
rename file to original generated
SpencerTorres Jun 6, 2025
63278cd
remove test build tag
SpencerTorres Jun 6, 2025
26a044c
package test, rename context
SpencerTorres Jun 6, 2025
339c0c3
add tests
SpencerTorres Jun 7, 2025
64079aa
run goporto
SpencerTorres Jun 7, 2025
d77e451
run generate
SpencerTorres Jun 7, 2025
d592be3
revert lifecylce tests
SpencerTorres Jun 7, 2025
452578c
remove TestMain dependency for integration tests
SpencerTorres Jun 8, 2025
5b36389
make fmt
SpencerTorres Jun 8, 2025
48d8428
re-use existing scope variable
SpencerTorres Jun 8, 2025
8d4a4e5
collapse if
SpencerTorres Jun 8, 2025
57edec2
export json logs
SpencerTorres Jun 8, 2025
c1640ea
traces json
SpencerTorres Jun 9, 2025
2295904
json integration tests
SpencerTorres Jun 9, 2025
91106bd
add tests, changelog, fmt/lint
SpencerTorres Jun 9, 2025
a702d61
readme
SpencerTorres Jun 9, 2025
099c236
changelog
SpencerTorres Jun 9, 2025
a72fa02
run goporto
SpencerTorres Jun 9, 2025
33003d8
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
SpencerTorres Jun 9, 2025
268a4b1
go tidy
SpencerTorres Jun 9, 2025
b629b1c
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
SpencerTorres Jun 10, 2025
9188e11
go mod
SpencerTorres Jun 10, 2025
4a79876
err is always nil
SpencerTorres Jun 10, 2025
eb39b0f
Merge branch 'clickhouse_full_reorganize' of github.com:SpencerTorres…
SpencerTorres Jun 10, 2025
a9a8569
go mod
SpencerTorres Jun 10, 2025
3759309
Update clickhouse-go to enable HTTP, add HTTP integration tests
SpencerTorres Jun 16, 2025
8830b46
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
SpencerTorres Jun 16, 2025
2c5e009
go mod
SpencerTorres Jun 16, 2025
a908280
Merge branch 'clickhouse_full_reorganize' of github.com:SpencerTorres…
SpencerTorres Jun 16, 2025
f2365e4
Update JSON integration tests with HTTP+Native
SpencerTorres Jun 16, 2025
04297e3
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
SpencerTorres Jun 16, 2025
4f6ed55
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
SpencerTorres Jun 17, 2025
74e21c3
update integration tests to be concurrent, update driver for critical…
SpencerTorres Jun 17, 2025
cc3f4ac
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
SpencerTorres Jun 17, 2025
5ed29bf
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
SpencerTorres Jun 19, 2025
89237a8
compression for JSON column DDL
SpencerTorres Jun 19, 2025
178de0a
remove custom encoder, use std json.Marshal
SpencerTorres Jun 22, 2025
6a88339
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
SpencerTorres Jun 22, 2025
49c779f
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
SpencerTorres Jun 25, 2025
5cdcfd0
make gotidy
SpencerTorres Jun 25, 2025
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
Prev Previous commit
Next Next commit
add tests, changelog, fmt/lint
  • Loading branch information
SpencerTorres committed Jun 9, 2025
commit 91106bd3174eb2c8e82c7b2daff50ba1d4328e18
32 changes: 32 additions & 0 deletions .chloggen/clickhouse-export-json-type.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: 'clickhouseexporter'

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Update exporter to optionally use the new JSON column type for logs and traces

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: []

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Added a feature gate to enable a JSON pipeline for logs and traces.
This feature gate ID is `clickhouse.json`, and will automatically use the new
DDL and column type on supported server versions.
You may also need to add `enable_json_type=1` to your connection
settings, depending on the server version.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
6 changes: 3 additions & 3 deletions exporter/clickhouseexporter/exporter_logs_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package clickhouseexporter // import "github.com/open-telemetry/opentelemetry-co
import (
"context"
"fmt"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal/chjson"
"time"

"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
Expand All @@ -15,6 +14,7 @@ import (
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal/chjson"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal/sqltemplates"
)

Expand All @@ -31,7 +31,7 @@ type logsJSONExporter struct {
spanHexBufferPool *internal.ExporterStructPool[[]byte]
}

func newLogsJSONExporter(logger *zap.Logger, cfg *Config) (*logsJSONExporter, error) {
func newLogsJSONExporter(logger *zap.Logger, cfg *Config) *logsJSONExporter {
numConsumers := cfg.QueueSettings.NumConsumers

newJSONBuffer := func() (*chjson.JSONBuffer, error) {
Expand All @@ -56,7 +56,7 @@ func newLogsJSONExporter(logger *zap.Logger, cfg *Config) (*logsJSONExporter, er
logAttributesBufferPool: logAttributesBufferPool,
traceHexBufferPool: traceHexBufferPool,
spanHexBufferPool: spanHexBufferPool,
}, nil
}
}

func (e *logsJSONExporter) start(ctx context.Context, _ component.Host) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func testLogsJSONExporter(t *testing.T) {
}

func newTestLogsJSONExporter(t *testing.T, dsn string, fns ...func(*Config)) *logsJSONExporter {
exporter, err := newLogsJSONExporter(zaptest.NewLogger(t), withTestExporterConfig(fns...)(dsn))
require.NoError(t, err)
exporter := newLogsJSONExporter(zaptest.NewLogger(t), withTestExporterConfig(fns...)(dsn))

require.NoError(t, exporter.start(context.Background(), nil))

Expand Down
6 changes: 3 additions & 3 deletions exporter/clickhouseexporter/exporter_traces_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package clickhouseexporter // import "github.com/open-telemetry/opentelemetry-co
import (
"context"
"fmt"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal/chjson"
"time"

"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
Expand All @@ -15,6 +14,7 @@ import (
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal/chjson"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal/sqltemplates"
)

Expand All @@ -34,7 +34,7 @@ type tracesJSONExporter struct {
linksHexBufferPool *internal.ExporterStructPool[[]byte]
}

func newTracesJSONExporter(logger *zap.Logger, cfg *Config) (*tracesJSONExporter, error) {
func newTracesJSONExporter(logger *zap.Logger, cfg *Config) *tracesJSONExporter {
numConsumers := cfg.QueueSettings.NumConsumers

newJSONBuffer := func() (*chjson.JSONBuffer, error) {
Expand Down Expand Up @@ -65,7 +65,7 @@ func newTracesJSONExporter(logger *zap.Logger, cfg *Config) (*tracesJSONExporter
spanHexBufferPool: spanHexBufferPool,
parentSpanHexBufferPool: parentSpanHexBufferPool,
linksHexBufferPool: linksHexBufferPool,
}, nil
}
}

func (e *tracesJSONExporter) start(ctx context.Context, _ component.Host) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func testTracesJSONExporter(t *testing.T) {
}

func newTestTracesJSONExporter(t *testing.T, dsn string, fns ...func(*Config)) *tracesJSONExporter {
exporter, err := newTracesJSONExporter(zaptest.NewLogger(t), withTestExporterConfig(fns...)(dsn))
require.NoError(t, err)
exporter := newTracesJSONExporter(zaptest.NewLogger(t), withTestExporterConfig(fns...)(dsn))

require.NoError(t, exporter.start(context.Background(), nil))

Expand Down
45 changes: 36 additions & 9 deletions exporter/clickhouseexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ package clickhouseexporter // import "github.com/open-telemetry/opentelemetry-co

import (
"context"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/featuregate"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal/metadata"
)

var featureGateJSON = featuregate.GlobalRegistry().MustRegister("clickhouse.json", featuregate.StageAlpha)

// NewFactory creates a factory for the ClickHouse exporter.
func NewFactory() exporter.Factory {
return exporter.NewFactory(
Expand All @@ -34,12 +37,24 @@ func createLogsExporter(
c := cfg.(*Config)
c.collectorVersion = set.BuildInfo.Version

// TODO: branch on feature flag or config
exp, err := newLogsJSONExporter(set.Logger, c)
if err != nil {
return nil, fmt.Errorf("cannot configure clickhouse json logs exporter: %w", err)
if featureGateJSON.IsEnabled() {
exp := newLogsJSONExporter(set.Logger, c)

return exporterhelper.NewLogs(
ctx,
set,
cfg,
exp.pushLogsData,
exporterhelper.WithStart(exp.start),
exporterhelper.WithShutdown(exp.shutdown),
exporterhelper.WithTimeout(c.TimeoutSettings),
exporterhelper.WithQueue(c.QueueSettings),
exporterhelper.WithRetry(c.BackOffConfig),
)
}

exp := newLogsExporter(set.Logger, c)

return exporterhelper.NewLogs(
ctx,
set,
Expand All @@ -61,12 +76,24 @@ func createTracesExporter(
c := cfg.(*Config)
c.collectorVersion = set.BuildInfo.Version

// TODO: branch on feature flag or config
exp, err := newTracesJSONExporter(set.Logger, c)
if err != nil {
return nil, fmt.Errorf("cannot configure clickhouse json traces exporter: %w", err)
if featureGateJSON.IsEnabled() {
exp := newTracesJSONExporter(set.Logger, c)

return exporterhelper.NewTraces(
ctx,
set,
cfg,
exp.pushTraceData,
exporterhelper.WithStart(exp.start),
exporterhelper.WithShutdown(exp.shutdown),
exporterhelper.WithTimeout(c.TimeoutSettings),
exporterhelper.WithQueue(c.QueueSettings),
exporterhelper.WithRetry(c.BackOffConfig),
)
}

exp := newTracesExporter(set.Logger, c)

return exporterhelper.NewTraces(
ctx,
set,
Expand Down
33 changes: 33 additions & 0 deletions exporter/clickhouseexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/featuregate"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal/metadata"
)
Expand All @@ -35,6 +36,22 @@ func TestFactory_CreateLogs(t *testing.T) {
require.NoError(t, exporter.Shutdown(context.Background()))
}

func TestFactory_CreateLogsJSON(t *testing.T) {
factory := NewFactory()
cfg := withDefaultConfig(func(cfg *Config) {
cfg.Endpoint = defaultEndpoint
})
gatePrev := featureGateJSON.IsEnabled()
_ = featuregate.GlobalRegistry().Set(featureGateJSON.ID(), true)
params := exportertest.NewNopSettings(metadata.Type)
exporter, err := factory.CreateLogs(context.Background(), params, cfg)
_ = featuregate.GlobalRegistry().Set(featureGateJSON.ID(), gatePrev)
require.NoError(t, err)
require.NotNil(t, exporter)

require.NoError(t, exporter.Shutdown(context.Background()))
}

func TestFactory_CreateTraces(t *testing.T) {
factory := NewFactory()
cfg := withDefaultConfig(func(cfg *Config) {
Expand All @@ -48,6 +65,22 @@ func TestFactory_CreateTraces(t *testing.T) {
require.NoError(t, exporter.Shutdown(context.Background()))
}

func TestFactory_CreateTracesJSON(t *testing.T) {
factory := NewFactory()
cfg := withDefaultConfig(func(cfg *Config) {
cfg.Endpoint = defaultEndpoint
})
gatePrev := featureGateJSON.IsEnabled()
_ = featuregate.GlobalRegistry().Set(featureGateJSON.ID(), true)
params := exportertest.NewNopSettings(metadata.Type)
exporter, err := factory.CreateTraces(context.Background(), params, cfg)
_ = featuregate.GlobalRegistry().Set(featureGateJSON.ID(), gatePrev)
require.NoError(t, err)
require.NotNil(t, exporter)

require.NoError(t, exporter.Shutdown(context.Background()))
}

func TestFactory_CreateMetrics(t *testing.T) {
factory := NewFactory()
cfg := withDefaultConfig(func(cfg *Config) {
Expand Down
3 changes: 2 additions & 1 deletion exporter/clickhouseexporter/internal/chjson/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package chjson
import (
"encoding/base64"
"encoding/hex"
"go.opentelemetry.io/collector/pdata/pcommon"
"strconv"
"strings"

"go.opentelemetry.io/collector/pdata/pcommon"
)

// AppendSpanIDToHex writes a hex encoded byte slice of SpanID.
Expand Down
11 changes: 6 additions & 5 deletions exporter/clickhouseexporter/internal/chjson/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
package chjson

import (
"testing"

"github.com/ClickHouse/clickhouse-go/v2/lib/column"
"github.com/ClickHouse/clickhouse-go/v2/lib/column/orderedmap"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
"testing"
)

func testMap() pcommon.Map {
Expand Down Expand Up @@ -86,7 +87,7 @@ func TestAttributesToJSON(t *testing.T) {
func TestAppendSpanIDToHex(t *testing.T) {
hexBuf := make([]byte, 0, 128)

var spanID = pcommon.SpanID{
spanID := pcommon.SpanID{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
}

Expand All @@ -102,7 +103,7 @@ func TestAppendSpanIDToHex(t *testing.T) {
func TestAppendTraceIDToHex(t *testing.T) {
hexBuf := make([]byte, 0, 128)

var traceID = pcommon.TraceID{
traceID := pcommon.TraceID{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
}
Expand All @@ -119,7 +120,7 @@ func TestAppendTraceIDToHex(t *testing.T) {
func BenchmarkAppendSpanIDToHex(b *testing.B) {
hexBuf := make([]byte, 0, 128)

var spanID = pcommon.SpanID{
spanID := pcommon.SpanID{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
}

Expand All @@ -133,7 +134,7 @@ func BenchmarkAppendSpanIDToHex(b *testing.B) {
func BenchmarkAppendTraceIDToHex(b *testing.B) {
hexBuf := make([]byte, 0, 128)

var traceID = pcommon.TraceID{
traceID := pcommon.TraceID{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
}
Expand Down
Loading