Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/stack-equal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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. otlpreceiver)
component: pdata/pprofile

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Introduce `Equal` method on the `Stack` type

# One or more tracking issues or pull requests related to the change
issues: [13952]

# (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:

# 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: [api]
19 changes: 19 additions & 0 deletions pdata/pprofile/stack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"

// Equal checks equality with another Stack
func (ms Stack) Equal(val Stack) bool {
if ms.LocationIndices().Len() != val.LocationIndices().Len() {
return false
}

for i := range ms.LocationIndices().Len() {
if ms.LocationIndices().At(i) != val.LocationIndices().At(i) {
return false
}
}

return true
}
72 changes: 72 additions & 0 deletions pdata/pprofile/stack_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package pprofile

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestStackEqual(t *testing.T) {
for _, tt := range []struct {
name string
orig Stack
dest Stack
want bool
}{
{
name: "with empty stacks",
orig: NewStack(),
dest: NewStack(),
want: true,
},
{
name: "with non-empty equal stacks",
orig: func() Stack {
s := NewStack()
s.LocationIndices().Append(1)
return s
}(),
dest: func() Stack {
s := NewStack()
s.LocationIndices().Append(1)
return s
}(),
want: true,
},
{
name: "with different location indices lengths",
orig: func() Stack {
s := NewStack()
s.LocationIndices().Append(1)
return s
}(),
dest: NewStack(),
want: false,
},
{
name: "with non-equal location indices",
orig: func() Stack {
s := NewStack()
s.LocationIndices().Append(2)
return s
}(),
dest: func() Stack {
s := NewStack()
s.LocationIndices().Append(1)
return s
}(),
want: false,
},
} {
t.Run(tt.name, func(t *testing.T) {
if tt.want {
assert.True(t, tt.orig.Equal(tt.dest))
} else {
assert.False(t, tt.orig.Equal(tt.dest))
}
})
}
}