Skip to content

Commit

Permalink
[batchprocessor] Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Traian Schiau committed Oct 26, 2021
1 parent 1a2f1a0 commit d6adb62
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
30 changes: 30 additions & 0 deletions processor/batchprocessor/splitlogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,33 @@ func BenchmarkCloneLogs(b *testing.B) {
}
}
}

func TestSplitLogsMultipleILL(t *testing.T) {
td := testdata.GenerateLogsManyLogRecordsSameResource(20)
logs := td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).Logs()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(0, i))
}
// add second index to ILL
td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).
CopyTo(td.ResourceLogs().At(0).InstrumentationLibraryLogs().AppendEmpty())
logs = td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(1).Logs()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(1, i))
}

// add third index to ILL
td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).
CopyTo(td.ResourceLogs().At(0).InstrumentationLibraryLogs().AppendEmpty())
logs = td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(2).Logs()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(2, i))
}

splitSize := 40
split := splitLogs(splitSize, td)
assert.Equal(t, splitSize, split.LogRecordCount())
assert.Equal(t, 20, td.LogRecordCount())
assert.Equal(t, "test-log-int-0-0", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).Logs().At(0).Name())
assert.Equal(t, "test-log-int-0-4", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).Logs().At(4).Name())
}
29 changes: 29 additions & 0 deletions processor/batchprocessor/splitmetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,32 @@ func TestSplitMetricsBatchSizeSmallerThanDataPointCount(t *testing.T) {
assert.Equal(t, 1, md.MetricCount())
assert.Equal(t, "test-metric-int-0-1", split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0).Name())
}

func TestSplitMetricsMultipleILM(t *testing.T) {
md := testdata.GenerateMetricsManyMetricsSameResource(20)
metrics := md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics()
dataPointCount := metricDataPointCount(metrics.At(0))
for i := 0; i < metrics.Len(); i++ {
metrics.At(i).SetName(getTestMetricName(0, i))
assert.Equal(t, dataPointCount, metricDataPointCount(metrics.At(i)))
}
// add second index to ilm
md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).
CopyTo(md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().AppendEmpty())

// add a third index to ilm
md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).
CopyTo(md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().AppendEmpty())
metrics = md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(2).Metrics()
for i := 0; i < metrics.Len(); i++ {
metrics.At(i).SetName(getTestMetricName(2, i))
}

splitMetricCount := 40
splitSize := splitMetricCount * dataPointCount
split := splitMetrics(splitSize, md)
assert.Equal(t, splitMetricCount, split.MetricCount())
assert.Equal(t, 20, md.MetricCount())
assert.Equal(t, "test-metric-int-0-0", split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0).Name())
assert.Equal(t, "test-metric-int-0-4", split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(4).Name())
}
30 changes: 30 additions & 0 deletions processor/batchprocessor/splittraces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,33 @@ func BenchmarkCloneSpans(b *testing.B) {
}
}
}

func TestSplitTracesMultipleILS(t *testing.T) {
td := testdata.GenerateTracesManySpansSameResource(20)
spans := td.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).Spans()
for i := 0; i < spans.Len(); i++ {
spans.At(i).SetName(getTestSpanName(0, i))
}
// add second index to ILS
td.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).
CopyTo(td.ResourceSpans().At(0).InstrumentationLibrarySpans().AppendEmpty())
spans = td.ResourceSpans().At(0).InstrumentationLibrarySpans().At(1).Spans()
for i := 0; i < spans.Len(); i++ {
spans.At(i).SetName(getTestSpanName(1, i))
}

// add third index to ILS
td.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).
CopyTo(td.ResourceSpans().At(0).InstrumentationLibrarySpans().AppendEmpty())
spans = td.ResourceSpans().At(0).InstrumentationLibrarySpans().At(2).Spans()
for i := 0; i < spans.Len(); i++ {
spans.At(i).SetName(getTestSpanName(2, i))
}

splitSize := 40
split := splitTraces(splitSize, td)
assert.Equal(t, splitSize, split.SpanCount())
assert.Equal(t, 20, td.SpanCount())
assert.Equal(t, "test-span-0-0", split.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).Spans().At(0).Name())
assert.Equal(t, "test-span-0-4", split.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).Spans().At(4).Name())
}

0 comments on commit d6adb62

Please sign in to comment.