Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Frame struct {
}

type Trace struct {
Comm string
Comm libpf.String
ProcessName string
ExecutablePath string
ContainerID string
Expand All @@ -56,6 +56,6 @@ type Trace struct {
APMTransactionID libpf.APMTransactionID
CPU int
EnvVars map[string]string
CustomLabels map[string]string
CustomLabels map[libpf.String]libpf.String
KernelFrames libpf.Frames
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ func Test_Golabels(t *testing.T) {
}
if len(trace.CustomLabels) > 0 {
hits := 0
for k, v := range trace.CustomLabels {
t.Logf("Received label %v=%v", k, v)
for ks, vs := range trace.CustomLabels {
k := ks.String()
v := vs.String()
if strings.HasPrefix(k, "l1") {
require.Len(t, v, 22)
require.True(t, strings.HasPrefix(v, "label1"))
Expand Down
2 changes: 1 addition & 1 deletion libpf/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ func (frames *Frames) Append(frame *Frame) {
type Trace struct {
Frames Frames
Hash TraceHash
CustomLabels map[string]string
CustomLabels map[String]String
}
6 changes: 3 additions & 3 deletions reporter/internal/pdata/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (p *Pdata) setProfile(
}

attrMgr.AppendOptionalString(sample.AttributeIndices(),
semconv.ThreadNameKey, traceKey.Comm)
semconv.ThreadNameKey, traceKey.Comm.String())

attrMgr.AppendOptionalString(sample.AttributeIndices(),
semconv.ProcessExecutableNameKey, exeName)
Expand All @@ -277,8 +277,8 @@ func (p *Pdata) setProfile(
// reached an agreement, use the actual OTel SemConv attribute.
attrMgr.AppendOptionalString(
sample.AttributeIndices(),
attribute.Key("process.context.label."+key),
value)
attribute.Key("process.context.label."+key.String()),
value.String())
}

if p.ExtraSampleAttrProd != nil {
Expand Down
4 changes: 2 additions & 2 deletions reporter/internal/pdata/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func TestGenerate_SingleContainerSingleOrigin(t *testing.T) {

traceKey := samples.TraceAndMetaKey{
ExecutablePath: filePath,
Comm: "testproc",
Comm: libpf.Intern("testproc"),
Pid: 123,
Tid: 456,
ApmServiceName: "svc",
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestGenerate_NativeFrame(t *testing.T) {

traceKey := samples.TraceAndMetaKey{
ExecutablePath: filePath,
Comm: "native_app",
Comm: libpf.Intern("native_app"),
Pid: 789,
Tid: 1011,
}
Expand Down
13 changes: 7 additions & 6 deletions reporter/samples/attrmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type attributeStruct struct {
}

func TestAttrTableManager(t *testing.T) {
comm1 := libpf.Intern("comm1")
comm2 := libpf.Intern("comm2")
tests := map[string]struct {
k []TraceAndMetaKey
expectedIndices [][]int32
Expand All @@ -31,7 +33,6 @@ func TestAttrTableManager(t *testing.T) {
k: []TraceAndMetaKey{
{
Hash: libpf.TraceHash{},
Comm: "",
ApmServiceName: "",
Pid: 0,
},
Expand All @@ -45,13 +46,13 @@ func TestAttrTableManager(t *testing.T) {
k: []TraceAndMetaKey{
{
Hash: libpf.TraceHash{},
Comm: "comm1",
Comm: comm1,
ApmServiceName: "apmServiceName1",
Pid: 1234,
},
{
Hash: libpf.TraceHash{},
Comm: "comm1",
Comm: comm1,
ApmServiceName: "apmServiceName1",
Pid: 1234,
},
Expand All @@ -67,13 +68,13 @@ func TestAttrTableManager(t *testing.T) {
k: []TraceAndMetaKey{
{
Hash: libpf.TraceHash{},
Comm: "comm1",
Comm: comm1,
ApmServiceName: "apmServiceName1",
Pid: 1234,
},
{
Hash: libpf.TraceHash{},
Comm: "comm2",
Comm: comm2,
ApmServiceName: "apmServiceName2",
Pid: 6789,
},
Expand All @@ -98,7 +99,7 @@ func TestAttrTableManager(t *testing.T) {
indices := make([][]int32, 0)
for _, k := range tc.k {
inner := pcommon.NewInt32Slice()
mgr.AppendOptionalString(inner, semconv.ThreadNameKey, k.Comm)
mgr.AppendOptionalString(inner, semconv.ThreadNameKey, k.Comm.String())
mgr.AppendOptionalString(inner, semconv.ServiceNameKey, k.ApmServiceName)
mgr.AppendInt(inner, semconv.ProcessPIDKey, k.Pid)
indices = append(indices, inner.AsRaw())
Expand Down
6 changes: 3 additions & 3 deletions reporter/samples/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type TraceEventMeta struct {
Timestamp libpf.UnixTime64
Comm string
Comm libpf.String
ProcessName string
ExecutablePath string
APMServiceName string
Expand All @@ -27,7 +27,7 @@ type TraceEvents struct {
Timestamps []uint64 // in nanoseconds
OffTimes []int64 // in nanoseconds
EnvVars map[string]string
Labels map[string]string
Labels map[libpf.String]libpf.String
}

// TraceAndMetaKey is the deduplication key for samples. This **must always**
Expand All @@ -38,7 +38,7 @@ type TraceAndMetaKey struct {
// to not aggregate difference traces.
Hash libpf.TraceHash
// comm and apmServiceName are provided by the eBPF programs
Comm string
Comm libpf.String
ApmServiceName string
Pid int64
Tid int64
Expand Down
7 changes: 4 additions & 3 deletions tracer/ebpf_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ Loop:
case <-timeout.C:
break Loop
case trace := <-traceChan:
require.GreaterOrEqual(t, len(trace.Comm), 4)
require.Equal(t, "\xAA\xBB\xCC", trace.Comm[0:3])
traces[trace.Comm[3]] = trace
comm := trace.Comm.String()
require.GreaterOrEqual(t, len(comm), 4)
require.Equal(t, "\xAA\xBB\xCC", comm[0:3])
traces[comm[3]] = trace
}
}

Expand Down
6 changes: 3 additions & 3 deletions tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ type progLoaderHelper struct {
}

// Convert a C-string to Go string.
func goString(cstr []byte) string {
func goString(cstr []byte) libpf.String {
index := bytes.IndexByte(cstr, byte(0))
if index < 0 {
index = len(cstr)
}
return strings.Clone(pfunsafe.ToString(cstr[:index]))
return libpf.Intern(pfunsafe.ToString(cstr[:index]))
}

// schedProcessFreeHookName returns the name of the tracepoint hook to use.
Expand Down Expand Up @@ -903,7 +903,7 @@ func (t *Tracer) loadBpfTrace(raw []byte, cpu int) *host.Trace {
}

if ptr.Custom_labels.Len > 0 {
trace.CustomLabels = make(map[string]string, int(ptr.Custom_labels.Len))
trace.CustomLabels = make(map[libpf.String]libpf.String, int(ptr.Custom_labels.Len))
for i := 0; i < int(ptr.Custom_labels.Len); i++ {
lbl := ptr.Custom_labels.Labels[i]
key := goString(lbl.Key[:])
Expand Down