-
Notifications
You must be signed in to change notification settings - Fork 1
/
common_actions.go
83 lines (67 loc) · 1.75 KB
/
common_actions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package compiled
import (
"fmt"
otlpcommon "go.opentelemetry.io/proto/otlp/common/v1"
)
type AttributesRenameAction map[string]string
func (at AttributesRenameAction) Apply(attrs []*otlpcommon.KeyValue, changes *ChangeLog) error {
var err error
seenAttrs := newFastMap(len(attrs))
var changeLog attrsModifyLog
for _, attr := range attrs {
if seenAttrs.exists(attr.Key) {
err = fmt.Errorf("attribute %s conflicts", attr.Key)
break
}
seenAttrs.set(attr.Key, attr.Value)
if convertTo, exists := at[attr.Key]; exists {
if seenAttrs.exists(convertTo) {
err = fmt.Errorf("attribute %s conflicts", attr.Key)
break
}
seenAttrs.set(convertTo, attr.Value)
if changes.Enabled && changeLog.savedAttrs == nil {
changeLog.origAttrs = attrs
changeLog.savedAttrs = make([]otlpcommon.KeyValue, len(attrs))
for j, attr := range attrs {
changeLog.savedAttrs[j] = *attr
}
}
attr.Key = convertTo
}
}
if len(changeLog.savedAttrs) > 0 {
changes.Append(&changeLog)
}
return err
}
type attrsModifyLog struct {
origAttrs []*otlpcommon.KeyValue
savedAttrs []otlpcommon.KeyValue
}
func (r *attrsModifyLog) Rollback() {
for i := 0; i < len(r.savedAttrs); i++ {
*r.origAttrs[i] = r.savedAttrs[i]
}
}
/*func (at AttributesRenameAction) Apply(attrs pdata.AttributeMap) error {
var err error
newAttrs := pdata.NewAttributeMap()
newAttrs.InitEmptyWithCapacity(attrs.Len())
converted := false
attrs.ForEach(func(k string, v pdata.AttributeValue) {
if convertTo, exists := at[k]; exists {
k = convertTo
converted = true
}
if _, exists := newAttrs.Get(k); exists {
err = fmt.Errorf("label %s conflicts", k)
}
newAttrs.Insert(k, v)
})
if converted && err == nil {
newAttrs.CopyTo(attrs)
}
return err
}
*/