-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
46acd87
to
8496397
Compare
reporter/datadog_reporter.go
Outdated
totalSampleCount += len(traceInfo.timestamps) | ||
sample := &pprofile.Sample{} | ||
count := len(traceInfo.timestamps) | ||
r.processSample(sample, profile, &traceKey, traceInfo, fileIDtoMapping, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Code Vulnerability
Potential memory range aliasing. Avoid using the memory reference. (...read more)
Implicit memory aliasing in for loops refers to a scenario in Go programming when two or more pointers reference the same location in memory, creating unexpected side effects. This often results in a common mistake amongst Go programmers due to the 'range' clause.
Consider this example, where a slice of pointers is created in a loop:
data := []int{1, 2, 3}
pointers := make([]*int, 3)
for i, v := range data {
pointers[i] = &v
}
You might expect the 'pointers' slice to hold addresses of elements in 'data' slice, but that's not the case. In each iteration of the loop, variable 'v' gets a new value but its memory address doesn't change because it's a loop variable. As a result, each element in 'pointers' slice points to the same memory location - the address of the loop variable 'v'. The final value of 'v' is '3', and since all pointers point to 'v', dereferencing the pointers would yield '3' regardless of the pointer's index in the slice.
To avoid implicit memory aliasing in for loops in Go, you should address the actual elements in the original data structure, like so:
data := []int{1, 2, 3}
pointers := make([]*int, 3)
for i := range data {
pointers[i] = &data[i]
}
In this example, each pointer in the 'pointers' slice correctly points to the respective element in the 'data' slice.
Learn More
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will silence this if we agree it is not an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not an issue thanks to https://go.dev/blog/loopvar-preview, and since go.mod has 1.22+ as the version https://github.com/DataDog/otel-profiling-agent/blob/main/go.mod#L3 this should be alright
8496397
to
8e2b9f6
Compare
@@ -559,12 +571,11 @@ func createPprofFunctionEntry(funcMap map[funcInfo]*pprofile.Function, | |||
return function | |||
} | |||
|
|||
//nolint:gocritic | |||
func addTraceLabels(labels map[string][]string, k traceAndMetaKey) { | |||
func addTraceLabels(labels map[string][]string, k *traceAndMetaKey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the traceAndMetaKey
to a pointer, highlighting in case there was any thought put into this earlier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially kept it as a variable to avoid having to deal with #55 (comment) since this code is not on the hot path anyway for the copy to be too expensive (only called once per minute). Also wanted to keep the code closer to the upstream OTLP reporter. But this works for me as well, no strong opinions 👍
interpreter/php/decode_arm64.go
Outdated
ah "github.com/elastic/otel-profiling-agent/armhelpers" | ||
"github.com/elastic/otel-profiling-agent/libpf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤓 nitpick: This does not seem to belong to the proposed change.
reporter/datadog_reporter.go
Outdated
if r.timeline { | ||
timestamps = traceInfo.timestamps | ||
} | ||
addTraceLabels(sample.Label, &traceKey, baseExec, timestamps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Code Vulnerability
Potential memory range aliasing. Avoid using the memory reference. (...read more)
Implicit memory aliasing in for loops refers to a scenario in Go programming when two or more pointers reference the same location in memory, creating unexpected side effects. This often results in a common mistake amongst Go programmers due to the 'range' clause.
Consider this example, where a slice of pointers is created in a loop:
data := []int{1, 2, 3}
pointers := make([]*int, 3)
for i, v := range data {
pointers[i] = &v
}
You might expect the 'pointers' slice to hold addresses of elements in 'data' slice, but that's not the case. In each iteration of the loop, variable 'v' gets a new value but its memory address doesn't change because it's a loop variable. As a result, each element in 'pointers' slice points to the same memory location - the address of the loop variable 'v'. The final value of 'v' is '3', and since all pointers point to 'v', dereferencing the pointers would yield '3' regardless of the pointer's index in the slice.
To avoid implicit memory aliasing in for loops in Go, you should address the actual elements in the original data structure, like so:
data := []int{1, 2, 3}
pointers := make([]*int, 3)
for i := range data {
pointers[i] = &data[i]
}
In this example, each pointer in the 'pointers' slice correctly points to the respective element in the 'data' slice.
Learn More
Add the list of timestamps to the sample's labels
Avoid a redundant nil check
00cee87
to
c69b23b
Compare
Description
Allow timestamps to be added to the samples as labels.
Additional information
I added the process name as a label as it makes it easier to de-duplicate, rather than using the frame information.
We can re-visit this idea.