Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid allocations when using delay_serialization #295

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/datadog/statsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def send_stats(stat, delta, type, opts = EMPTY_OPTIONS)
if sample_rate == 1 || opts[:pre_sampled] || rand <= sample_rate
full_stat =
if @delay_serialization
[[stat, delta, type], {tags: opts[:tags], sample_rate: sample_rate}]
[stat, delta, type, opts[:tags], sample_rate]
else
serializer.to_stat(stat, delta, type, tags: opts[:tags], sample_rate: sample_rate)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/datadog/statsd/message_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def add(message)
# Serializes the message if it hasn't been already. Part of the
# delay_serialization feature.
if message.is_a?(Array)
message = @serializer.to_stat(*message[0], **message[1])
stat, delta, type, tags, sample_rate = message
message = @serializer.to_stat(stat, delta, type, tags: tags, sample_rate: sample_rate)
end

message_size = message.bytesize
Expand Down
2 changes: 1 addition & 1 deletion spec/integrations/delay_serialization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# expects an Array is passed and not a String
expect(buffer)
.to receive(:add)
.with([["boo", 1, "c"], {tags: nil, sample_rate: 1}])
.with(["boo", 1, "c", nil, 1])
# and then expect no more adds!
expect(buffer).to receive(:add).exactly(0).times
expect(buffer)
Expand Down
Loading