Skip to content

Commit 30ae652

Browse files
Frapschencparkins
authored andcommitted

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: clickhouseexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix clickhouse exporter insert metrics data bug
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [30210]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

exporter/clickhouseexporter/exporter_metrics_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15+
"github.com/ClickHouse/clickhouse-go/v2"
1516
"github.com/stretchr/testify/require"
1617
"go.opentelemetry.io/collector/pdata/pcommon"
1718
"go.opentelemetry.io/collector/pdata/pmetric"
@@ -97,6 +98,29 @@ func TestExporter_pushMetricsData(t *testing.T) {
9798

9899
require.Equal(t, int32(15), items.Load())
99100
})
101+
t.Run("check traceID and spanID", func(t *testing.T) {
102+
initClickhouseTestServer(t, func(query string, values []driver.Value) error {
103+
if strings.HasPrefix(query, "INSERT INTO otel_metrics_gauge") {
104+
require.Equal(t, clickhouse.ArraySet{"0102030000000000"}, values[18])
105+
require.Equal(t, clickhouse.ArraySet{"01020300000000000000000000000000"}, values[19])
106+
}
107+
if strings.HasPrefix(query, "INSERT INTO otel_metrics_histogram") {
108+
require.Equal(t, clickhouse.ArraySet{"0102030000000000"}, values[20])
109+
require.Equal(t, clickhouse.ArraySet{"01020300000000000000000000000000"}, values[21])
110+
}
111+
if strings.HasPrefix(query, "INSERT INTO otel_metrics_sum ") {
112+
require.Equal(t, clickhouse.ArraySet{"0102030000000000"}, values[18])
113+
require.Equal(t, clickhouse.ArraySet{"01020300000000000000000000000000"}, values[19])
114+
}
115+
if strings.HasPrefix(query, "INSERT INTO otel_metrics_exponential_histogram") {
116+
require.Equal(t, clickhouse.ArraySet{"0102030000000000"}, values[24])
117+
require.Equal(t, clickhouse.ArraySet{"01020300000000000000000000000000"}, values[25])
118+
}
119+
return nil
120+
})
121+
exporter := newTestMetricsExporter(t)
122+
mustPushMetricsData(t, exporter, simpleMetrics(1))
123+
})
100124
}
101125

102126
func Benchmark_pushMetricsData(b *testing.B) {

exporter/clickhouseexporter/internal/exponential_histogram_metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ func (e *expHistogramMetrics) insert(ctx context.Context, db *sql.DB) error {
154154
attrs,
155155
times,
156156
values,
157-
traceIDs,
158157
spanIDs,
158+
traceIDs,
159159
uint32(dp.Flags()),
160160
dp.Min(),
161161
dp.Max(),

exporter/clickhouseexporter/internal/gauge_metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ func (g *gaugeMetrics) insert(ctx context.Context, db *sql.DB) error {
128128
attrs,
129129
times,
130130
values,
131-
traceIDs,
132131
spanIDs,
132+
traceIDs,
133133
)
134134
if err != nil {
135135
return fmt.Errorf("ExecContext:%w", err)

exporter/clickhouseexporter/internal/histogram_metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ func (h *histogramMetrics) insert(ctx context.Context, db *sql.DB) error {
140140
attrs,
141141
times,
142142
values,
143-
traceIDs,
144143
spanIDs,
144+
traceIDs,
145145
uint32(dp.Flags()),
146146
dp.Min(),
147147
dp.Max(),

exporter/clickhouseexporter/internal/sum_metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ func (s *sumMetrics) insert(ctx context.Context, db *sql.DB) error {
132132
attrs,
133133
times,
134134
values,
135-
traceIDs,
136135
spanIDs,
136+
traceIDs,
137137
int32(model.sum.AggregationTemporality()),
138138
model.sum.IsMonotonic(),
139139
)

0 commit comments

Comments
 (0)