mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
Right now, when merging profiles, we switch dictionary entries when they are used. For example, for each sample, we do: * Run `switchDictionary` for that sample. * Switch all the sample indices dictionaries. * Run `switchDictionary` for the stack associated with that sample. * Update the sample's stack ID with the one provided by the new dictionary. This has a pretty big issue, as when stacks are associated to multiple samples (which is very common in production workloads, but was missed in tests), we will try switching the stack's dictionary multiple times. * Switch the stack's dictionary, works fine. * Switch it again. Now, we try assigning indices from the source dictionary when they have meaning in the destination one. Instead, we now do the following: * Run `switchDictionary` for the stacks. * Loop through samples, and run `switchDictionary` for each of them. * Retrieve the stack. Because we already switched its dictionary, we get a stack already pointing at the new dictionary. * Update the sample's stack ID with the one provided by the new dictionary. <sub>This investigation and PR were proudly done **without** the use of any LLM.</sub> --------- Signed-off-by: Florian Lehner <[email protected]> Co-authored-by: Florian Lehner <[email protected]>
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"
|
|
|
|
import "fmt"
|
|
|
|
// switchDictionary updates the Sample, switching its indices from one
|
|
// dictionary to another.
|
|
func (ms Sample) switchDictionary(src, dst ProfilesDictionary) error {
|
|
for i, v := range ms.AttributeIndices().All() {
|
|
if src.AttributeTable().Len() <= int(v) {
|
|
return fmt.Errorf("invalid attribute index %d", v)
|
|
}
|
|
|
|
attr := src.AttributeTable().At(int(v))
|
|
idx, err := SetAttribute(dst.AttributeTable(), attr)
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't set attribute %d: %w", i, err)
|
|
}
|
|
ms.AttributeIndices().SetAt(i, idx)
|
|
}
|
|
|
|
if ms.LinkIndex() > 0 {
|
|
if src.LinkTable().Len() <= int(ms.LinkIndex()) {
|
|
return fmt.Errorf("invalid link index %d", ms.LinkIndex())
|
|
}
|
|
|
|
idx, err := SetLink(dst.LinkTable(), src.LinkTable().At(int(ms.LinkIndex())))
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't set link: %w", err)
|
|
}
|
|
ms.SetLinkIndex(idx)
|
|
}
|
|
|
|
if ms.StackIndex() > 0 {
|
|
if src.StackTable().Len() <= int(ms.StackIndex()) {
|
|
return fmt.Errorf("invalid stack index %d", ms.StackIndex())
|
|
}
|
|
|
|
stack := src.StackTable().At(int(ms.StackIndex()))
|
|
idx, err := SetStack(dst.StackTable(), stack)
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't set stack: %w", err)
|
|
}
|
|
ms.SetStackIndex(idx)
|
|
}
|
|
|
|
return nil
|
|
}
|