Skip to content

Commit fd9c731

Browse files
committed
Implement spans exporting in ClickHouse storage
Signed-off-by: haanhvu <[email protected]>
1 parent d489e3a commit fd9c731

File tree

14 files changed

+599
-10
lines changed

14 files changed

+599
-10
lines changed

cmd/jaeger/internal/exporters/storageexporter/exporter.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ import (
1414
"go.uber.org/zap"
1515

1616
"github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage"
17+
ch "github.com/jaegertracing/jaeger/plugin/storage/clickhouse"
1718
"github.com/jaegertracing/jaeger/storage/spanstore"
1819
)
1920

2021
type storageExporter struct {
2122
config *Config
2223
logger *zap.Logger
2324
spanWriter spanstore.Writer
25+
clickhouse bool
26+
// Separate traces exporting function for ClickHouse storage.
27+
// This is temporary until we have v2 storage API.
28+
chExportTraces func(ctx context.Context, td ptrace.Traces) error
2429
}
2530

2631
func newExporter(config *Config, otel component.TelemetrySettings) *storageExporter {
@@ -30,14 +35,22 @@ func newExporter(config *Config, otel component.TelemetrySettings) *storageExpor
3035
}
3136
}
3237

33-
func (exp *storageExporter) start(_ context.Context, host component.Host) error {
38+
func (exp *storageExporter) start(ctx context.Context, host component.Host) error {
3439
f, err := jaegerstorage.GetStorageFactory(exp.config.TraceStorage, host)
3540
if err != nil {
3641
return fmt.Errorf("cannot find storage factory: %w", err)
3742
}
3843

39-
if exp.spanWriter, err = f.CreateSpanWriter(); err != nil {
40-
return fmt.Errorf("cannot create span writer: %w", err)
44+
switch t := f.(type) {
45+
case *ch.Factory:
46+
exp.clickhouse = true
47+
t.CreateSpansTable(ctx)
48+
exp.chExportTraces = t.ExportSpans
49+
default:
50+
exp.clickhouse = false
51+
if exp.spanWriter, err = f.CreateSpanWriter(); err != nil {
52+
return fmt.Errorf("cannot create span writer: %w", err)
53+
}
4154
}
4255

4356
return nil
@@ -49,6 +62,10 @@ func (exp *storageExporter) close(_ context.Context) error {
4962
}
5063

5164
func (exp *storageExporter) pushTraces(ctx context.Context, td ptrace.Traces) error {
65+
if exp.clickhouse {
66+
return exp.chExportTraces(ctx, td)
67+
}
68+
5269
batches, err := otlp2jaeger.ProtoFromTraces(td)
5370
if err != nil {
5471
return fmt.Errorf("cannot transform OTLP traces to Jaeger format: %w", err)

cmd/jaeger/internal/exporters/storageexporter/factory.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func createTracesExporter(ctx context.Context, set exporter.CreateSettings, conf
4040
// Disable Timeout/RetryOnFailure and SendingQueue
4141
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
4242
exporterhelper.WithRetry(exporterhelper.RetrySettings{Enabled: false}),
43-
exporterhelper.WithQueue(exporterhelper.QueueSettings{Enabled: false}),
43+
// Enable queue settings for Clickhouse only
44+
exporterhelper.WithQueue(exporterhelper.QueueSettings{Enabled: ex.clickhouse}),
4445
exporterhelper.WithStart(ex.start),
4546
exporterhelper.WithShutdown(ex.close),
4647
)

cmd/jaeger/internal/extension/jaegerstorage/config.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package jaegerstorage
55

66
import (
77
memoryCfg "github.com/jaegertracing/jaeger/pkg/memory/config"
8+
ch "github.com/jaegertracing/jaeger/plugin/storage/clickhouse"
89
)
910

1011
// Config has the configuration for jaeger-query,
@@ -13,9 +14,6 @@ type Config struct {
1314
// TODO add other storage types here
1415
// TODO how will this work with 3rd party storage implementations?
1516
// Option: instead of looking for specific name, check interface.
16-
}
1717

18-
type MemoryStorage struct {
19-
Name string `mapstructure:"name"`
20-
memoryCfg.Configuration
18+
ClickHouse map[string]ch.Config `mapstructure:"clickhouse"`
2119
}

cmd/jaeger/internal/extension/jaegerstorage/extension.go

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"go.uber.org/zap"
1515

1616
"github.com/jaegertracing/jaeger/pkg/metrics"
17+
"github.com/jaegertracing/jaeger/plugin/storage/clickhouse"
1718
"github.com/jaegertracing/jaeger/plugin/storage/memory"
1819
"github.com/jaegertracing/jaeger/storage"
1920
)
@@ -71,6 +72,14 @@ func (s *storageExt) Start(ctx context.Context, host component.Host) error {
7172
)
7273
}
7374
// TODO add support for other backends
75+
76+
for name, chCfg := range s.config.ClickHouse {
77+
if _, ok := s.factories[name]; ok {
78+
return fmt.Errorf("duplicate clickhouse storage name %s", name)
79+
}
80+
s.factories[name] = clickhouse.NewFactory(ctx, chCfg, s.logger.With(zap.String("storage_name", name)))
81+
}
82+
7483
return nil
7584
}
7685

config.yaml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
service:
2+
extensions: [jaeger_storage, jaeger_query]
3+
pipelines:
4+
traces:
5+
receivers: [otlp, jaeger, zipkin]
6+
processors: [batch]
7+
exporters: [jaeger_storage_exporter]
8+
9+
extensions:
10+
# health_check:
11+
# pprof:
12+
# endpoint: 0.0.0.0:1777
13+
# zpages:
14+
# endpoint: 0.0.0.0:55679
15+
16+
jaeger_query:
17+
trace_storage: ch_store
18+
ui_config: ./cmd/jaeger/config-ui.json
19+
20+
jaeger_storage:
21+
memory:
22+
memstore:
23+
max_traces: 100000
24+
memstore_archive:
25+
max_traces: 100000
26+
clickhouse:
27+
ch_store:
28+
endpoint: tcp://127.0.0.1:9000?dial_timeout=10s&compress=lz4
29+
spans_table_name: jaeger_spans
30+
31+
receivers:
32+
otlp:
33+
protocols:
34+
grpc:
35+
http:
36+
37+
jaeger:
38+
protocols:
39+
grpc:
40+
thrift_binary:
41+
thrift_compact:
42+
thrift_http:
43+
44+
zipkin:
45+
46+
processors:
47+
batch:
48+
49+
exporters:
50+
jaeger_storage_exporter:
51+
trace_storage: ch_store

go.mod

+9-1
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ require (
8383

8484
require (
8585
contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect
86+
github.com/ClickHouse/ch-go v0.58.2 // indirect
87+
github.com/ClickHouse/clickhouse-go/v2 v2.15.0 // indirect
8688
github.com/IBM/sarama v1.42.1 // indirect
8789
github.com/VividCortex/gohistogram v1.0.0 // indirect
90+
github.com/andybalholm/brotli v1.0.6 // indirect
8891
github.com/aws/aws-sdk-go v1.48.14 // indirect
8992
github.com/beorn7/perks v1.0.1 // indirect
9093
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
@@ -93,13 +96,15 @@ require (
9396
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
9497
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
9598
github.com/dgraph-io/ristretto v0.1.1 // indirect
96-
github.com/dustin/go-humanize v1.0.0 // indirect
99+
github.com/dustin/go-humanize v1.0.1 // indirect
97100
github.com/eapache/go-resiliency v1.4.0 // indirect
98101
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
99102
github.com/eapache/queue v1.1.0 // indirect
100103
github.com/elastic/elastic-transport-go/v8 v8.3.0 // indirect
101104
github.com/fatih/color v1.14.1 // indirect
102105
github.com/felixge/httpsnoop v1.0.4 // indirect
106+
github.com/go-faster/city v1.0.1 // indirect
107+
github.com/go-faster/errors v0.6.1 // indirect
103108
github.com/go-kit/log v0.2.1 // indirect
104109
github.com/go-logfmt/logfmt v0.5.1 // indirect
105110
github.com/go-logr/logr v1.3.0 // indirect
@@ -157,6 +162,7 @@ require (
157162
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.91.0 // indirect
158163
github.com/opentracing/opentracing-go v1.2.0 // indirect
159164
github.com/openzipkin/zipkin-go v0.4.2 // indirect
165+
github.com/paulmach/orb v0.10.0 // indirect
160166
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
161167
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
162168
github.com/pierrec/lz4/v4 v4.1.18 // indirect
@@ -172,8 +178,10 @@ require (
172178
github.com/russross/blackfriday/v2 v2.1.0 // indirect
173179
github.com/sagikazarmark/locafero v0.4.0 // indirect
174180
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
181+
github.com/segmentio/asm v1.2.0 // indirect
175182
github.com/shirou/gopsutil/v3 v3.23.11 // indirect
176183
github.com/shoenig/go-m1cpu v0.1.6 // indirect
184+
github.com/shopspring/decimal v1.3.1 // indirect
177185
github.com/sourcegraph/conc v0.3.0 // indirect
178186
github.com/spf13/afero v1.11.0 // indirect
179187
github.com/spf13/cast v1.6.0 // indirect

0 commit comments

Comments
 (0)