Skip to content

Commit a16370b

Browse files
committed
fix
Signed-off-by: zzzk1 <[email protected]>
1 parent f61ee43 commit a16370b

File tree

5 files changed

+85
-28
lines changed

5 files changed

+85
-28
lines changed

pkg/clickhouse/config/config_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212
"go.uber.org/zap"
13+
14+
"github.com/jaegertracing/jaeger/pkg/testutils"
1315
)
1416

17+
func TestDefaultConfig(t *testing.T) {
18+
cfg := DefaultConfiguration()
19+
assert.NotEmpty(t, cfg)
20+
assert.NotEmpty(t, cfg.ClientConfig)
21+
assert.NotEmpty(t, cfg.ConnectionPoolConfig)
22+
}
23+
1524
func TestNewClientWithDefaults(t *testing.T) {
1625
cfg := DefaultConfiguration()
1726
logger := zap.NewNop()
@@ -25,3 +34,7 @@ func TestNewClientWithDefaults(t *testing.T) {
2534
assert.NotEmpty(t, client)
2635
defer client.Close()
2736
}
37+
38+
func TestMain(m *testing.M) {
39+
testutils.VerifyGoLeaks(m)
40+
}

pkg/clickhouse/config/package_test.go

-14
This file was deleted.

pkg/clickhouse/internal/empty_test.go

-14
This file was deleted.
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2025 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package internal
5+
6+
import (
7+
"testing"
8+
"time"
9+
10+
"github.com/stretchr/testify/assert"
11+
"go.opentelemetry.io/collector/pdata/pcommon"
12+
"go.opentelemetry.io/collector/pdata/ptrace"
13+
conventions "go.opentelemetry.io/collector/semconv/v1.27.0"
14+
15+
"github.com/jaegertracing/jaeger/pkg/testutils"
16+
)
17+
18+
var expected = "INSERT INTO \"otel_traces\" (\"Timestamp\",\"traceId\",\"SpanId\",\"ParentSpanId\",\"TraceState\"," +
19+
"\"SpanName\",\"SpanKind\",\"ServiceName\",\"ResourceAttributes.keys\",\"ResourceAttributes.values\",\"ScopeName\"," +
20+
"\"ScopeVersion\",\"SpanAttributes.keys\",\"SpanAttributes.values\",\"Duration\",\"StatusCode\",\"StatusMessage\"," +
21+
"\"Events.Timestamp\",\"Events.Name\",\"Events.Attributes\",\"Links.traceId\",\"Links.SpanId\",\"Links.TraceState\"," +
22+
"\"Links.Attributes\") VALUES"
23+
24+
func TestInput(t *testing.T) {
25+
td := simpleTraces(2)
26+
actual := Input(td)
27+
assert.Equal(t, expected, actual.Into("otel_traces"))
28+
}
29+
30+
func TestMain(m *testing.M) {
31+
testutils.VerifyGoLeaks(m)
32+
}
33+
34+
func simpleTraces(count int) ptrace.Traces {
35+
traces := ptrace.NewTraces()
36+
rs := traces.ResourceSpans().AppendEmpty()
37+
rs.SetSchemaUrl("https://opentelemetry.io/schemas/1.4.0")
38+
rs.Resource().SetDroppedAttributesCount(10)
39+
rs.Resource().Attributes().PutStr("service.name", "test-service")
40+
ss := rs.ScopeSpans().AppendEmpty()
41+
ss.Scope().SetName("io.opentelemetry.contrib.clickhouse")
42+
ss.Scope().SetVersion("1.0.0")
43+
ss.SetSchemaUrl("https://opentelemetry.io/schemas/1.7.0")
44+
ss.Scope().SetDroppedAttributesCount(20)
45+
ss.Scope().Attributes().PutStr("lib", "clickhouse")
46+
timestamp := time.Unix(1703498029, 0)
47+
for i := 0; i < count; i++ {
48+
s := ss.Spans().AppendEmpty()
49+
s.SetTraceID([16]byte{1, 2, 3, byte(i)})
50+
s.SetSpanID([8]byte{1, 2, 3, byte(i)})
51+
s.TraceState().FromRaw("trace state")
52+
s.SetParentSpanID([8]byte{1, 2, 4, byte(i)})
53+
s.SetName("call db")
54+
s.SetKind(ptrace.SpanKindInternal)
55+
s.SetStartTimestamp(pcommon.NewTimestampFromTime(timestamp))
56+
s.SetEndTimestamp(pcommon.NewTimestampFromTime(timestamp.Add(time.Minute)))
57+
s.Attributes().PutStr(conventions.AttributeServiceName, "v")
58+
s.Status().SetMessage("error")
59+
s.Status().SetCode(ptrace.StatusCodeError)
60+
event := s.Events().AppendEmpty()
61+
event.SetName("event1")
62+
event.SetTimestamp(pcommon.NewTimestampFromTime(timestamp))
63+
event.Attributes().PutStr("level", "info")
64+
link := s.Links().AppendEmpty()
65+
link.SetTraceID([16]byte{1, 2, 5, byte(i)})
66+
link.SetSpanID([8]byte{1, 2, 5, byte(i)})
67+
link.TraceState().FromRaw("error")
68+
link.Attributes().PutStr("k", "v")
69+
}
70+
return traces
71+
}

pkg/clickhouse/wrapper/.nocover

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requires connection to ClickHouse

0 commit comments

Comments
 (0)