mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
This PR contains the following updates: | Package | Change | Age | Confidence | |---|---|---|---| | golang.org/x/mod | `v0.28.0` -> `v0.30.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | golang.org/x/sys | `v0.37.0` -> `v0.38.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | golang.org/x/tools | `v0.38.0` -> `v0.39.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/open-telemetry/opentelemetry-collector). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi4xOS45IiwidXBkYXRlZEluVmVyIjoiNDIuMTkuOSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIiwicmVub3ZhdGVib3QiXX0=--> --------- Signed-off-by: alex boten <[email protected]> Co-authored-by: Hanzo Dev <[email protected]> Co-authored-by: Pablo Baeyens <[email protected]> Co-authored-by: Alex Boten <[email protected]> Co-authored-by: Pablo Baeyens <[email protected]>
184 lines
4.2 KiB
Go
184 lines
4.2 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package pprofile
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.opentelemetry.io/collector/internal/testutil"
|
|
"go.opentelemetry.io/collector/pdata/pcommon"
|
|
)
|
|
|
|
func TestFromAttributeIndices(t *testing.T) {
|
|
dic := NewProfilesDictionary()
|
|
dic.StringTable().Append("")
|
|
dic.StringTable().Append("hello")
|
|
dic.StringTable().Append("bonjour")
|
|
|
|
table := NewKeyValueAndUnitSlice()
|
|
att := table.AppendEmpty()
|
|
att.SetKeyStrindex(1)
|
|
att.Value().SetStr("world")
|
|
att2 := table.AppendEmpty()
|
|
att2.SetKeyStrindex(2)
|
|
att2.Value().SetStr("monde")
|
|
|
|
attrs := FromAttributeIndices(table, NewProfile(), dic)
|
|
assert.Equal(t, attrs, pcommon.NewMap())
|
|
|
|
// A Location with a single attribute
|
|
loc := NewLocation()
|
|
loc.AttributeIndices().Append(0)
|
|
|
|
attrs = FromAttributeIndices(table, loc, dic)
|
|
|
|
m := map[string]any{"hello": "world"}
|
|
assert.Equal(t, attrs.AsRaw(), m)
|
|
|
|
// A Mapping with two attributes
|
|
mapp := NewLocation()
|
|
mapp.AttributeIndices().Append(0, 1)
|
|
|
|
attrs = FromAttributeIndices(table, mapp, dic)
|
|
|
|
m = map[string]any{"hello": "world", "bonjour": "monde"}
|
|
assert.Equal(t, attrs.AsRaw(), m)
|
|
}
|
|
|
|
func BenchmarkFromAttributeIndices(b *testing.B) {
|
|
dic := NewProfilesDictionary()
|
|
table := NewKeyValueAndUnitSlice()
|
|
|
|
for i := range 10 {
|
|
dic.StringTable().Append(fmt.Sprintf("key_%d", i))
|
|
|
|
att := table.AppendEmpty()
|
|
att.SetKeyStrindex(int32(dic.StringTable().Len()))
|
|
att.Value().SetStr(fmt.Sprintf("value_%d", i))
|
|
}
|
|
|
|
obj := NewLocation()
|
|
obj.AttributeIndices().Append(1, 3, 7)
|
|
|
|
b.ReportAllocs()
|
|
|
|
for b.Loop() {
|
|
_ = FromAttributeIndices(table, obj, dic)
|
|
}
|
|
}
|
|
|
|
func TestSetAttribute(t *testing.T) {
|
|
table := NewKeyValueAndUnitSlice()
|
|
attr := NewKeyValueAndUnit()
|
|
attr.SetKeyStrindex(1)
|
|
attr.SetUnitStrindex(2)
|
|
require.NoError(t, attr.Value().FromRaw("test"))
|
|
attr2 := NewKeyValueAndUnit()
|
|
attr2.SetKeyStrindex(3)
|
|
attr2.SetUnitStrindex(4)
|
|
require.NoError(t, attr.Value().FromRaw("test2"))
|
|
|
|
// Put a first value
|
|
idx, err := SetAttribute(table, attr)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 1, table.Len())
|
|
assert.Equal(t, int32(0), idx)
|
|
|
|
// Put the same attribute
|
|
// This should be a no-op.
|
|
idx, err = SetAttribute(table, attr)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 1, table.Len())
|
|
assert.Equal(t, int32(0), idx)
|
|
|
|
// Set a new value
|
|
// This sets the index and adds to the table.
|
|
idx, err = SetAttribute(table, attr2)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 2, table.Len())
|
|
assert.Equal(t, int32(table.Len()-1), idx)
|
|
|
|
// Set an existing value
|
|
idx, err = SetAttribute(table, attr)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 2, table.Len())
|
|
assert.Equal(t, int32(0), idx)
|
|
// Set another existing value
|
|
idx, err = SetAttribute(table, attr2)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 2, table.Len())
|
|
assert.Equal(t, int32(table.Len()-1), idx)
|
|
}
|
|
|
|
func BenchmarkSetAttribute(b *testing.B) {
|
|
testutil.SkipMemoryBench(b)
|
|
for _, bb := range []struct {
|
|
name string
|
|
attr KeyValueAndUnit
|
|
|
|
runBefore func(*testing.B, KeyValueAndUnitSlice)
|
|
}{
|
|
{
|
|
name: "with a new attribute",
|
|
attr: NewKeyValueAndUnit(),
|
|
},
|
|
{
|
|
name: "with an existing attribute",
|
|
attr: func() KeyValueAndUnit {
|
|
a := NewKeyValueAndUnit()
|
|
a.SetKeyStrindex(1)
|
|
return a
|
|
}(),
|
|
|
|
runBefore: func(_ *testing.B, table KeyValueAndUnitSlice) {
|
|
a := table.AppendEmpty()
|
|
a.SetKeyStrindex(1)
|
|
},
|
|
},
|
|
{
|
|
name: "with a duplicate attribute",
|
|
attr: NewKeyValueAndUnit(),
|
|
|
|
runBefore: func(_ *testing.B, table KeyValueAndUnitSlice) {
|
|
_, err := SetAttribute(table, NewKeyValueAndUnit())
|
|
require.NoError(b, err)
|
|
},
|
|
},
|
|
{
|
|
name: "with a hundred locations to loop through",
|
|
attr: func() KeyValueAndUnit {
|
|
a := NewKeyValueAndUnit()
|
|
a.SetKeyStrindex(1)
|
|
return a
|
|
}(),
|
|
|
|
runBefore: func(_ *testing.B, table KeyValueAndUnitSlice) {
|
|
for i := range 100 {
|
|
l := table.AppendEmpty()
|
|
l.SetKeyStrindex(int32(i))
|
|
}
|
|
},
|
|
},
|
|
} {
|
|
b.Run(bb.name, func(b *testing.B) {
|
|
table := NewKeyValueAndUnitSlice()
|
|
|
|
if bb.runBefore != nil {
|
|
bb.runBefore(b, table)
|
|
}
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
|
|
for b.Loop() {
|
|
_, _ = SetAttribute(table, bb.attr)
|
|
}
|
|
})
|
|
}
|
|
}
|