Skip to content

Commit

Permalink
Remove deprecated pcommon.Map.Sort (open-telemetry#7028)
Browse files Browse the repository at this point in the history
Fixes open-telemetry#6688

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Feb 2, 2023
1 parent c641c05 commit 84c3d00
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 30 deletions.
11 changes: 11 additions & 0 deletions .chloggen/rmsort.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: pcommon

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove deprecated Map.Sort

# One or more tracking issues or pull requests related to the change
issues: [6688]
21 changes: 0 additions & 21 deletions pdata/pcommon/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package pcommon // import "go.opentelemetry.io/collector/pdata/pcommon"

import (
"sort"

"go.uber.org/multierr"

"go.opentelemetry.io/collector/pdata/internal"
Expand Down Expand Up @@ -194,25 +192,6 @@ func (m Map) PutEmptySlice(k string) Slice {
return Slice(internal.NewSlice(&vl.ArrayValue.Values))
}

// Sort sorts the entries in the Map so two instances can be compared.
//
// Deprecated: [1.0.0-rc4] This method will be removed as it leaks the underlying implementation.
// Please use one of the following alternatives depending on your use case:
// - Map.AsRaw() if you need to compare two maps in tests.
// - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest module if you use Sort()
// to prepare other pdata objects for comparison.
// - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil module if you use Sort()
// to create Map identifiers.
//
// If your use case is not covered by the above alternatives, please comment on the issue
// https://github.com/open-telemetry/opentelemetry-collector/issues/6688.
func (m Map) Sort() {
// Intention is to move the nil values at the end.
sort.SliceStable(*m.getOrig(), func(i, j int) bool {
return (*m.getOrig())[i].Key < (*m.getOrig())[j].Key
})
}

// Len returns the length of this map.
//
// Because the Map is represented internally by a slice of pointers, and the data are comping from the wire,
Expand Down
9 changes: 0 additions & 9 deletions pdata/pcommon/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ func TestMap(t *testing.T) {
removeMap := NewMap()
assert.False(t, removeMap.Remove("k"))
assert.EqualValues(t, NewMap(), removeMap)

// Test Sort
sortMap := NewMap()
sortMap.Sort()
assert.EqualValues(t, NewMap(), sortMap)
}

func TestMapPutEmpty(t *testing.T) {
Expand Down Expand Up @@ -262,10 +257,6 @@ func TestMapWithEmpty(t *testing.T) {

_, exist = sm.Get("test_key3")
assert.False(t, exist)

// Test Sort
sm.Sort()
assert.EqualValues(t, newMap(&origWithNil), sm)
}

func TestMapIterationNil(t *testing.T) {
Expand Down

0 comments on commit 84c3d00

Please sign in to comment.