Skip to content

Commit

Permalink
more clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Boten committed Oct 4, 2022
1 parent 96baaa4 commit 219b241
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
24 changes: 16 additions & 8 deletions pkg/batchperresourceattr/batchperresourceattr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func TestSplitTracesSameResource(t *testing.T) {
fillResourceSpans(inBatch.ResourceSpans().AppendEmpty(), "same_attr_val", "1")
fillResourceSpans(inBatch.ResourceSpans().AppendEmpty(), "same_attr_val", "1")
fillResourceSpans(inBatch.ResourceSpans().AppendEmpty(), "same_attr_val", "1")
expected := inBatch.Clone()
expected := ptrace.NewTraces()
inBatch.CopyTo(expected)

sink := new(consumertest.TracesSink)
bpr := NewBatchPerResourceTraces("same_attr_val", sink)
Expand All @@ -80,7 +81,8 @@ func TestSplitTracesIntoDifferentBatches(t *testing.T) {
fillResourceSpans(inBatch.ResourceSpans().AppendEmpty(), "attr_key", "3")
fillResourceSpans(inBatch.ResourceSpans().AppendEmpty(), "attr_key", "4")
fillResourceSpans(inBatch.ResourceSpans().AppendEmpty(), "diff_attr_key", "1")
expected := inBatch.Clone()
expected := ptrace.NewTraces()
inBatch.CopyTo(expected)

sink := new(consumertest.TracesSink)
bpr := NewBatchPerResourceTraces("attr_key", sink)
Expand All @@ -98,7 +100,8 @@ func TestSplitTracesIntoDifferentBatches(t *testing.T) {
func TestSplitMetricsOneResourceMetrics(t *testing.T) {
inBatch := pmetric.NewMetrics()
fillResourceMetrics(inBatch.ResourceMetrics().AppendEmpty(), "attr_key", "1")
expected := inBatch.Clone()
expected := pmetric.NewMetrics()
inBatch.CopyTo(expected)

sink := new(consumertest.MetricsSink)
bpr := NewBatchPerResourceMetrics("attr_key", sink)
Expand All @@ -124,7 +127,8 @@ func TestSplitMetricsSameResource(t *testing.T) {
fillResourceMetrics(inBatch.ResourceMetrics().AppendEmpty(), "same_attr_val", "1")
fillResourceMetrics(inBatch.ResourceMetrics().AppendEmpty(), "same_attr_val", "1")
fillResourceMetrics(inBatch.ResourceMetrics().AppendEmpty(), "same_attr_val", "1")
expected := inBatch.Clone()
expected := pmetric.NewMetrics()
inBatch.CopyTo(expected)

sink := new(consumertest.MetricsSink)
bpr := NewBatchPerResourceMetrics("same_attr_val", sink)
Expand All @@ -145,7 +149,8 @@ func TestSplitMetricsIntoDifferentBatches(t *testing.T) {
fillResourceMetrics(inBatch.ResourceMetrics().AppendEmpty(), "attr_key", "3")
fillResourceMetrics(inBatch.ResourceMetrics().AppendEmpty(), "attr_key", "4")
fillResourceMetrics(inBatch.ResourceMetrics().AppendEmpty(), "diff_attr_key", "1")
expected := inBatch.Clone()
expected := pmetric.NewMetrics()
inBatch.CopyTo(expected)

sink := new(consumertest.MetricsSink)
bpr := NewBatchPerResourceMetrics("attr_key", sink)
Expand All @@ -163,7 +168,8 @@ func TestSplitMetricsIntoDifferentBatches(t *testing.T) {
func TestSplitLogsOneResourceLogs(t *testing.T) {
inBatch := plog.NewLogs()
fillResourceLogs(inBatch.ResourceLogs().AppendEmpty(), "attr_key", "1")
expected := inBatch.Clone()
expected := plog.NewLogs()
inBatch.CopyTo(expected)

sink := new(consumertest.LogsSink)
bpr := NewBatchPerResourceLogs("attr_key", sink)
Expand All @@ -189,7 +195,8 @@ func TestSplitLogsSameResource(t *testing.T) {
fillResourceLogs(inBatch.ResourceLogs().AppendEmpty(), "same_attr_val", "1")
fillResourceLogs(inBatch.ResourceLogs().AppendEmpty(), "same_attr_val", "1")
fillResourceLogs(inBatch.ResourceLogs().AppendEmpty(), "same_attr_val", "1")
expected := inBatch.Clone()
expected := plog.NewLogs()
inBatch.CopyTo(expected)

sink := new(consumertest.LogsSink)
bpr := NewBatchPerResourceLogs("same_attr_val", sink)
Expand All @@ -210,7 +217,8 @@ func TestSplitLogsIntoDifferentBatches(t *testing.T) {
fillResourceLogs(inBatch.ResourceLogs().AppendEmpty(), "attr_key", "3")
fillResourceLogs(inBatch.ResourceLogs().AppendEmpty(), "attr_key", "4")
fillResourceLogs(inBatch.ResourceLogs().AppendEmpty(), "diff_attr_key", "1")
expected := inBatch.Clone()
expected := plog.NewLogs()
inBatch.CopyTo(expected)

sink := new(consumertest.LogsSink)
bpr := NewBatchPerResourceLogs("attr_key", sink)
Expand Down
6 changes: 4 additions & 2 deletions pkg/translator/opencensus/oc_to_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func TestOCToMetrics(t *testing.T) {

func TestOCToMetrics_ResourceInMetric(t *testing.T) {
internal := testdata.GenerateMetricsOneMetric()
want := internal.Clone()
want := pmetric.NewMetrics()
internal.CopyTo(want)
want.ResourceMetrics().At(0).CopyTo(want.ResourceMetrics().AppendEmpty())
want.ResourceMetrics().At(1).Resource().Attributes().PutString("resource-attr", "another-value")
oc := generateOCTestDataMetricsOneMetric()
Expand All @@ -153,7 +154,8 @@ func TestOCToMetrics_ResourceInMetric(t *testing.T) {

func TestOCToMetrics_ResourceInMetricOnly(t *testing.T) {
internal := testdata.GenerateMetricsOneMetric()
want := internal.Clone()
want := pmetric.NewMetrics()
internal.CopyTo(want)
oc := generateOCTestDataMetricsOneMetric()
// Move resource to metric level.
// We shouldn't have a "combined" resource after conversion
Expand Down

0 comments on commit 219b241

Please sign in to comment.