Skip to content

Commit

Permalink
Add MoveTo all the top pdata structs, consistency with other generate…
Browse files Browse the repository at this point in the history
…d structs (#4930)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Mar 2, 2022
1 parent 02d0fe5 commit 0698727
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions model/pdata/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func (ld Logs) InternalRep() internal.LogsWrapper {
return internal.LogsFromOtlp(ld.orig)
}

// MoveTo moves all properties from the current struct to dest
// resetting the current instance to its zero value.
func (ld Logs) MoveTo(dest Logs) {
*dest.orig = *ld.orig
*ld.orig = otlplogs.LogsData{}
}

// Clone returns a copy of Logs.
func (ld Logs) Clone() Logs {
cloneLd := NewLogs()
Expand Down
9 changes: 9 additions & 0 deletions model/pdata/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ func TestResourceLogsWireCompatibility(t *testing.T) {
assert.EqualValues(t, logs.orig, &gogoprotoRS2)
}

func TestLogsMoveTo(t *testing.T) {
logs := NewLogs()
fillTestResourceLogsSlice(logs.ResourceLogs())
dest := NewLogs()
logs.MoveTo(dest)
assert.EqualValues(t, NewLogs(), logs)
assert.EqualValues(t, generateTestResourceLogsSlice(), dest.ResourceLogs())
}

func TestLogsClone(t *testing.T) {
logs := NewLogs()
fillTestResourceLogsSlice(logs.ResourceLogs())
Expand Down
7 changes: 7 additions & 0 deletions model/pdata/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ func (md Metrics) Clone() Metrics {
return cloneMd
}

// MoveTo moves all properties from the current struct to dest
// resetting the current instance to its zero value.
func (md Metrics) MoveTo(dest Metrics) {
*dest.orig = *md.orig
*md.orig = otlpmetrics.MetricsData{}
}

// ResourceMetrics returns the ResourceMetricsSlice associated with this Metrics.
func (md Metrics) ResourceMetrics() ResourceMetricsSlice {
return newResourceMetricsSlice(&md.orig.ResourceMetrics)
Expand Down
9 changes: 9 additions & 0 deletions model/pdata/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ func TestDataPointCountWithNilDataPoints(t *testing.T) {
assert.EqualValues(t, 0, metrics.DataPointCount())
}

func TestMetricsMoveTo(t *testing.T) {
metrics := NewMetrics()
fillTestResourceMetricsSlice(metrics.ResourceMetrics())
dest := NewMetrics()
metrics.MoveTo(dest)
assert.EqualValues(t, NewMetrics(), metrics)
assert.EqualValues(t, generateTestResourceMetricsSlice(), dest.ResourceMetrics())
}

func TestOtlpToInternalReadOnly(t *testing.T) {
md := Metrics{orig: &otlpmetrics.MetricsData{
ResourceMetrics: []*otlpmetrics.ResourceMetrics{
Expand Down
7 changes: 7 additions & 0 deletions model/pdata/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ func (td Traces) InternalRep() internal.TracesWrapper {
return internal.TracesFromOtlp(td.orig)
}

// MoveTo moves all properties from the current struct to dest
// resetting the current instance to its zero value.
func (td Traces) MoveTo(dest Traces) {
*dest.orig = *td.orig
*td.orig = otlptrace.TracesData{}
}

// Clone returns a copy of Traces.
func (td Traces) Clone() Traces {
cloneTd := NewTraces()
Expand Down
9 changes: 9 additions & 0 deletions model/pdata/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ func TestResourceSpansWireCompatibility(t *testing.T) {
assert.EqualValues(t, traces.orig, &gogoprotoRS2)
}

func TestTracesMoveTo(t *testing.T) {
traces := NewTraces()
fillTestResourceSpansSlice(traces.ResourceSpans())
dest := NewTraces()
traces.MoveTo(dest)
assert.EqualValues(t, NewTraces(), traces)
assert.EqualValues(t, generateTestResourceSpansSlice(), dest.ResourceSpans())
}

func TestTracesClone(t *testing.T) {
traces := NewTraces()
fillTestResourceSpansSlice(traces.ResourceSpans())
Expand Down

0 comments on commit 0698727

Please sign in to comment.