-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[exporter/clickhouse] Add integration test #30209
Changes from all commits
c7cf8d6
e6384ac
43ef390
f7ce79a
355376e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# 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: Add integration test for clickhouse exporter | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [29626] | ||
|
||
# (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: | ||
|
||
# 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: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -342,3 +342,7 @@ service: | |
processors: [ batch ] | ||
exporters: [ clickhouse ] | ||
``` | ||
|
||
## Developer tips | ||
|
||
- Make sure integration tests pass after any change of sql | ||
Comment on lines
+345
to
+348
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's useful without instructions on running the integration tests. The integration tests should be run by the CI |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,7 @@ func TestExporter_pushLogsData(t *testing.T) { | |
}) | ||
} | ||
|
||
// nolint:unparam // not need to check this func | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? All the parameters seem to be used... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so why do you need |
||
func newTestLogsExporter(t *testing.T, dsn string, fns ...func(*Config)) *logsExporter { | ||
exporter, err := newLogsExporter(zaptest.NewLogger(t), withTestExporterConfig(fns...)(dsn)) | ||
require.NoError(t, err) | ||
|
@@ -151,10 +152,18 @@ func simpleLogs(count int) plog.Logs { | |
sl.Scope().SetName("io.opentelemetry.contrib.clickhouse") | ||
sl.Scope().SetVersion("1.0.0") | ||
sl.Scope().Attributes().PutStr("lib", "clickhouse") | ||
timestamp := time.Unix(1703498029, 0) | ||
for i := 0; i < count; i++ { | ||
r := sl.LogRecords().AppendEmpty() | ||
r.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
r.Attributes().PutStr(conventions.AttributeServiceName, "v") | ||
r.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
r.SetObservedTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
r.SetSeverityNumber(plog.SeverityNumberError2) | ||
r.SetSeverityText("error") | ||
r.Body().SetStr("error message") | ||
r.Attributes().PutStr(conventions.AttributeServiceNamespace, "default") | ||
r.SetFlags(plog.DefaultLogRecordFlags) | ||
r.SetTraceID([16]byte{1, 2, 3, byte(i)}) | ||
r.SetSpanID([8]byte{1, 2, 3, byte(i)}) | ||
} | ||
return logs | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ func TestExporter_pushMetricsData(t *testing.T) { | |
} | ||
return nil | ||
}) | ||
exporter := newTestMetricsExporter(t) | ||
exporter := newTestMetricsExporter(t, defaultEndpoint) | ||
mustPushMetricsData(t, exporter, simpleMetrics(1)) | ||
|
||
require.Equal(t, int32(15), items.Load()) | ||
|
@@ -41,7 +41,7 @@ func TestExporter_pushMetricsData(t *testing.T) { | |
} | ||
return nil | ||
}) | ||
exporter := newTestMetricsExporter(t) | ||
exporter := newTestMetricsExporter(t, defaultEndpoint) | ||
err := exporter.pushMetricsData(context.TODO(), simpleMetrics(2)) | ||
require.Error(t, err) | ||
}) | ||
|
@@ -93,7 +93,7 @@ func TestExporter_pushMetricsData(t *testing.T) { | |
} | ||
return nil | ||
}) | ||
exporter := newTestMetricsExporter(t) | ||
exporter := newTestMetricsExporter(t, defaultEndpoint) | ||
mustPushMetricsData(t, exporter, simpleMetrics(1)) | ||
|
||
require.Equal(t, int32(15), items.Load()) | ||
|
@@ -118,14 +118,14 @@ func TestExporter_pushMetricsData(t *testing.T) { | |
} | ||
return nil | ||
}) | ||
exporter := newTestMetricsExporter(t) | ||
exporter := newTestMetricsExporter(t, defaultEndpoint) | ||
mustPushMetricsData(t, exporter, simpleMetrics(1)) | ||
}) | ||
} | ||
|
||
func Benchmark_pushMetricsData(b *testing.B) { | ||
pm := simpleMetrics(1) | ||
exporter := newTestMetricsExporter(&testing.T{}) | ||
exporter := newTestMetricsExporter(&testing.T{}, defaultEndpoint) | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for n := 0; n < b.N; n++ { | ||
|
@@ -148,6 +148,7 @@ func simpleMetrics(count int) pmetric.Metrics { | |
sm.Scope().SetDroppedAttributesCount(10) | ||
sm.Scope().SetName("Scope name 1") | ||
sm.Scope().SetVersion("Scope version 1") | ||
timestamp := time.Unix(1703498029, 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this related to the integration test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. integration test will verify the inserted data, so we need a constant timestamp |
||
for i := 0; i < count; i++ { | ||
// gauge | ||
m := sm.Metrics().AppendEmpty() | ||
|
@@ -156,10 +157,12 @@ func simpleMetrics(count int) pmetric.Metrics { | |
m.SetDescription("This is a gauge metrics") | ||
dp := m.SetEmptyGauge().DataPoints().AppendEmpty() | ||
dp.SetIntValue(int64(i)) | ||
dp.SetFlags(pmetric.DefaultDataPointFlags) | ||
dp.Attributes().PutStr("gauge_label_1", "1") | ||
dp.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
dp.SetStartTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
dp.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
exemplars := dp.Exemplars().AppendEmpty() | ||
exemplars.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
exemplars.SetIntValue(54) | ||
exemplars.FilteredAttributes().PutStr("key", "value") | ||
exemplars.FilteredAttributes().PutStr("key2", "value2") | ||
|
@@ -173,10 +176,12 @@ func simpleMetrics(count int) pmetric.Metrics { | |
m.SetDescription("This is a sum metrics") | ||
dp = m.SetEmptySum().DataPoints().AppendEmpty() | ||
dp.SetDoubleValue(11.234) | ||
dp.SetFlags(pmetric.DefaultDataPointFlags) | ||
dp.Attributes().PutStr("sum_label_1", "1") | ||
dp.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
dp.SetStartTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
dp.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
exemplars = dp.Exemplars().AppendEmpty() | ||
exemplars.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
exemplars.SetIntValue(54) | ||
exemplars.FilteredAttributes().PutStr("key", "value") | ||
exemplars.FilteredAttributes().PutStr("key2", "value2") | ||
|
@@ -189,17 +194,18 @@ func simpleMetrics(count int) pmetric.Metrics { | |
m.SetUnit("ms") | ||
m.SetDescription("This is a histogram metrics") | ||
dpHisto := m.SetEmptyHistogram().DataPoints().AppendEmpty() | ||
dpHisto.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
dpHisto.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
dpHisto.SetStartTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
dpHisto.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
dpHisto.SetCount(1) | ||
dpHisto.SetSum(1) | ||
dpHisto.Attributes().PutStr("key", "value") | ||
dpHisto.Attributes().PutStr("key", "value") | ||
dpHisto.Attributes().PutStr("key2", "value") | ||
dpHisto.ExplicitBounds().FromRaw([]float64{0, 0, 0, 0, 0}) | ||
dpHisto.BucketCounts().FromRaw([]uint64{0, 0, 0, 1, 0}) | ||
dpHisto.SetMin(0) | ||
dpHisto.SetMax(1) | ||
exemplars = dpHisto.Exemplars().AppendEmpty() | ||
exemplars.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
exemplars.SetDoubleValue(55.22) | ||
exemplars.FilteredAttributes().PutStr("key", "value") | ||
exemplars.FilteredAttributes().PutStr("key2", "value2") | ||
|
@@ -212,21 +218,22 @@ func simpleMetrics(count int) pmetric.Metrics { | |
m.SetUnit("ms") | ||
m.SetDescription("This is a exp histogram metrics") | ||
dpExpHisto := m.SetEmptyExponentialHistogram().DataPoints().AppendEmpty() | ||
dpExpHisto.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
dpExpHisto.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
dpExpHisto.SetStartTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
dpExpHisto.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
dpExpHisto.SetSum(1) | ||
dpExpHisto.SetMin(0) | ||
dpExpHisto.SetMax(1) | ||
dpExpHisto.SetZeroCount(0) | ||
dpExpHisto.SetCount(1) | ||
dpExpHisto.Attributes().PutStr("key", "value") | ||
dpExpHisto.Attributes().PutStr("key", "value") | ||
dpExpHisto.Attributes().PutStr("key2", "value") | ||
dpExpHisto.Negative().SetOffset(1) | ||
dpExpHisto.Negative().BucketCounts().FromRaw([]uint64{0, 0, 0, 1, 0}) | ||
dpExpHisto.Positive().SetOffset(1) | ||
dpExpHisto.Positive().BucketCounts().FromRaw([]uint64{0, 0, 0, 1, 0}) | ||
|
||
exemplars = dpExpHisto.Exemplars().AppendEmpty() | ||
exemplars.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
exemplars.SetIntValue(54) | ||
exemplars.FilteredAttributes().PutStr("key", "value") | ||
exemplars.FilteredAttributes().PutStr("key2", "value2") | ||
|
@@ -239,10 +246,10 @@ func simpleMetrics(count int) pmetric.Metrics { | |
m.SetUnit("ms") | ||
m.SetDescription("This is a summary metrics") | ||
summary := m.SetEmptySummary().DataPoints().AppendEmpty() | ||
summary.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
summary.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
summary.SetStartTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
summary.SetTimestamp(pcommon.NewTimestampFromTime(timestamp)) | ||
summary.Attributes().PutStr("key", "value") | ||
summary.Attributes().PutStr("key2", "value2") | ||
summary.Attributes().PutStr("key2", "value") | ||
summary.SetCount(1) | ||
summary.SetSum(1) | ||
quantileValues := summary.QuantileValues().AppendEmpty() | ||
|
@@ -475,8 +482,9 @@ func mustPushMetricsData(t *testing.T, exporter *metricsExporter, md pmetric.Met | |
require.NoError(t, err) | ||
} | ||
|
||
func newTestMetricsExporter(t *testing.T) *metricsExporter { | ||
exporter, err := newMetricsExporter(zaptest.NewLogger(t), withTestExporterConfig()(defaultEndpoint)) | ||
// nolint:unparam // not need to check this func | ||
func newTestMetricsExporter(t *testing.T, dsn string, fns ...func(*Config)) *metricsExporter { | ||
exporter, err := newMetricsExporter(zaptest.NewLogger(t), withTestExporterConfig(fns...)(dsn)) | ||
require.NoError(t, err) | ||
require.NoError(t, exporter.start(context.TODO(), nil)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need changelogs for improving test coverage. It's not a user-facing or API change