Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Sortable #4734

Merged
merged 9 commits into from
Mar 11, 2024
Merged
Changes from 1 commit
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
Next Next commit
Deprecate Sortable
ash2k committed Mar 6, 2024
commit 0c0e007e537837639f71030afcc369d4ed297d0a
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -12,6 +12,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Drop support for [Go 1.20]. (#4967)

### Deprecated

- Deprecate `go.opentelemetry.io/otel/attribute.Sortable` and methods that use it. (#4734)
ash2k marked this conversation as resolved.
Show resolved Hide resolved

## [1.24.0/0.46.0/0.0.1-alpha] 2024-02-23

This release is the last to support [Go 1.20].
40 changes: 15 additions & 25 deletions attribute/set.go
Original file line number Diff line number Diff line change
@@ -4,10 +4,11 @@
package attribute // import "go.opentelemetry.io/otel/attribute"

import (
"cmp"
"encoding/json"
"reflect"
"slices"
"sort"
"sync"
)

type (
@@ -28,10 +29,9 @@
iface interface{}
}

// Sortable implements sort.Interface, used for sorting KeyValue. This is
// an exported type to support a memory optimization. A pointer to one of
// these is needed for the call to sort.Stable(), which the caller may
// provide in order to avoid an allocation. See NewSetWithSortable().
// Sortable implements sort.Interface, used for sorting KeyValue.
//
// Deprecated: no longer needed.
ash2k marked this conversation as resolved.
Show resolved Hide resolved
Sortable []KeyValue
)

@@ -45,12 +45,6 @@
iface: [0]KeyValue{},
},
}

// sortables is a pool of Sortables used to create Sets with a user does
// not provide one.
sortables = sync.Pool{
New: func() interface{} { return new(Sortable) },
}
)

// EmptySet returns a reference to a Set with no elements.
@@ -180,22 +174,21 @@
if len(kvs) == 0 {
return empty()
}
srt := sortables.Get().(*Sortable)
s, _ := NewSetWithSortableFiltered(kvs, srt, nil)
sortables.Put(srt)
s, _ := NewSetWithSortableFiltered(kvs, nil, nil)
return s
}

// NewSetWithSortable returns a new Set. See the documentation for
// NewSetWithSortableFiltered for more details.
//
// This call includes a Sortable option as a memory optimization.
func NewSetWithSortable(kvs []KeyValue, tmp *Sortable) Set {
// Deprecated: NewSet.
ash2k marked this conversation as resolved.
Show resolved Hide resolved
func NewSetWithSortable(kvs []KeyValue, _ *Sortable) Set {

Check warning on line 186 in attribute/set.go

Codecov / codecov/patch

attribute/set.go#L186

Added line #L186 was not covered by tests
// Check for empty set.
if len(kvs) == 0 {
return empty()
}
s, _ := NewSetWithSortableFiltered(kvs, tmp, nil)
s, _ := NewSetWithSortableFiltered(kvs, nil, nil)

Check warning on line 191 in attribute/set.go

Codecov / codecov/patch

attribute/set.go#L191

Added line #L191 was not covered by tests
return s
}

@@ -209,9 +202,7 @@
if len(kvs) == 0 {
return empty(), nil
}
srt := sortables.Get().(*Sortable)
s, filtered := NewSetWithSortableFiltered(kvs, srt, filter)
sortables.Put(srt)
s, filtered := NewSetWithSortableFiltered(kvs, nil, filter)
return s, filtered
}

@@ -238,19 +229,18 @@
//
// The second []KeyValue return value is a list of attributes that were
// excluded by the Filter (if non-nil).
func NewSetWithSortableFiltered(kvs []KeyValue, tmp *Sortable, filter Filter) (Set, []KeyValue) {
// Deprecated: use NewSetWithFiltered.
func NewSetWithSortableFiltered(kvs []KeyValue, _ *Sortable, filter Filter) (Set, []KeyValue) {
// Check for empty set.
if len(kvs) == 0 {
return empty(), nil
}

*tmp = kvs

// Stable sort so the following de-duplication can implement
// last-value-wins semantics.
sort.Stable(tmp)

*tmp = nil
slices.SortStableFunc(kvs, func(a, b KeyValue) int {
return cmp.Compare(a.Key, b.Key)
})

position := len(kvs) - 1
offset := position - 1