-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
delay_serialization: implement feature
Add the `delay_serialization` option, allowing users to delay expensive serialization until a more convenient time, such as after an HTTP request has completed. In multi-threaded mode, it causes serialization to happen inside the sender thread. Also, support the `sender_queue_size` in `single_thread` mode, so that it can benefit from the new `delay_serialization` option. Messages are now queued (possibly unserialized) until `sender_queue_size` is reached or `#flush` is called. It may be set to `Float::INFINITY`, so that messages are indefinitely queued until an explicit `#flush`. Fix #271 Co-Authored-By: Blake Williams <[email protected]>
- Loading branch information
1 parent
9b3ae2d
commit 378d519
Showing
12 changed files
with
170 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
|
||
module Datadog | ||
class Statsd | ||
VERSION = '5.5.0' | ||
VERSION = '5.6.0' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "spec_helper" | ||
|
||
describe "Delayed serialization mode" do | ||
it "defers serialization to message buffer" do | ||
buffer = double(Datadog::Statsd::MessageBuffer) | ||
# expects an Array is passed and not a String | ||
expect(buffer) | ||
.to receive(:add) | ||
.with([["boo", 1, "c"], {tags: nil, sample_rate: 1}]) | ||
# and then expect no more adds! | ||
expect(buffer).to receive(:add).exactly(0).times | ||
expect(buffer) | ||
.to receive(:flush) | ||
|
||
allow(Datadog::Statsd::MessageBuffer).to receive(:new).and_return(buffer) | ||
dogstats = Datadog::Statsd.new("localhost", 1234, delay_serialization: true) | ||
|
||
dogstats.increment("boo") | ||
dogstats.flush(sync: true) | ||
end | ||
|
||
it "serializes messages normally" do | ||
socket = FakeUDPSocket.new(copy_message: true) | ||
allow(UDPSocket).to receive(:new).and_return(socket) | ||
dogstats = Datadog::Statsd.new("localhost", 1234, delay_serialization: true) | ||
|
||
dogstats.increment("boo") | ||
dogstats.increment("oob", tags: {tag1: "val1"}) | ||
dogstats.increment("pow", tags: {tag1: "val1"}, sample_rate: 2) | ||
dogstats.flush(sync: true) | ||
|
||
expect(socket.recv[0]).to eq([ | ||
"boo:1|c", | ||
"oob:1|c|#tag1:val1", | ||
"pow:1|c|@2|#tag1:val1" | ||
].join("\n")) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.