Skip to content

Commit 6f108e5

Browse files
rockdabootDylan-M
authored andcommitted
[exporter/elasticsearch] Profiling: Duplicate events if count > 1 (open-telemetry#40947)
#### Description Due to nanosecond timestamp resolution, the probability of events having a Stacktrace.count value > 1 is very low. For the rare cases where it is, we can write multiple identical events. The compression in Elasticsearch will handle this very well. On the read/query side, things would be come less complex, and random sampling could be applied (requirement is that every event has the same "weight" aka count). Random sampling can reduce latency for queries. #### Link to tracking issue Fixes open-telemetry#40946
1 parent c66a3c5 commit 6f108e5

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: elasticsearchexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Duplicate profiling events with count values larger than 1
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [40946]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: Having all events with count=1 enables random sampling on the read path.
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

exporter/elasticsearchexporter/internal/serializer/otelserializer/serializeprofiles/transform.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,11 @@ func stackPayloads(dic pprofile.ProfilesDictionary, resource pcommon.Resource, s
140140
t := sample.TimestampsUnixNano().At(j)
141141
event.TimeStamp = newUnixTime64(t)
142142

143+
count := 1
143144
if j < sample.Value().Len() {
144-
event.Count = uint16(sample.Value().At(j))
145-
} else {
146-
event.Count = 1 // restore default
145+
count = int(sample.Value().At(j))
147146
}
148-
if event.Count > 0 {
147+
for range count {
149148
stackPayload = append(stackPayload, StackPayload{
150149
StackTraceEvent: event,
151150
})
@@ -221,7 +220,7 @@ func stackTraceEvent(dic pprofile.ProfilesDictionary, traceID string, sample ppr
221220
EcsVersion: EcsVersion{V: EcsVersionString},
222221
HostID: hostMetadata[string(semconv.HostIDKey)],
223222
StackTraceID: traceID,
224-
Count: 1, // TODO: Check whether count can be dropped with nanosecond timestamps
223+
Count: 1, // Elasticsearch v9.2+ doesn't read the count value any more.
225224
Frequency: frequency,
226225
}
227226

exporter/elasticsearchexporter/internal/serializer/otelserializer/serializeprofiles/transform_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,16 @@ func TestStackPayloads(t *testing.T) {
509509
TimeStamp: 1000000000,
510510
StackTraceID: wantedTraceID,
511511
Frequency: 20,
512-
Count: 2,
512+
Count: 1,
513+
},
514+
},
515+
{
516+
StackTraceEvent: StackTraceEvent{
517+
EcsVersion: EcsVersion{V: EcsVersionString},
518+
TimeStamp: 1000000000,
519+
StackTraceID: wantedTraceID,
520+
Frequency: 20,
521+
Count: 1,
513522
},
514523
},
515524
},

0 commit comments

Comments
 (0)