-
Notifications
You must be signed in to change notification settings - Fork 399
DEBUG-3558 DI: chunk snapshot payloads #5086
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
Open
p-datadog
wants to merge
10
commits into
master
Choose a base branch
from
di-chunk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+187
−9
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fb72ef4
DI: chunk snapshot payloads
p 68587e2
Update sig/datadog/di/transport/input.rbs
p-datadog 3a25f2e
use correct limits, drop snapshots prior to chunking
p f1b3d51
types
p 18a7aa5
cannot use compact
p 59db88c
add Ruby version note
p 37f1252
Merge branch 'master' into di-chunk
p d0ce8ab
Merge branch 'master' into di-chunk
p-datadog ca985cf
Update lib/datadog/core/utils/array.rb
p-datadog 228785a
Revert "Update lib/datadog/core/utils/array.rb"
p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,24 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Datadog | ||
| module Core | ||
| module Utils | ||
| # Common array-related utility functions. | ||
| module Array | ||
| def self.filter_map(array, &block) | ||
| if array.respond_to?(:filter_map) | ||
| # DEV Supported since Ruby 2.7, saves an intermediate object creation | ||
| array.filter_map(&block) | ||
| else | ||
| # You would think that .compact would work here, but it does not: | ||
| # the result of .map could be an Enumerator::Lazy instance which | ||
| # does not implement #compact on Ruby 2.5/2.6. | ||
| array.map(&block).reject do |item| | ||
| item.nil? | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,9 @@ | ||
| module Datadog | ||
| module Core | ||
| module Utils | ||
| module Array | ||
| def self.filter_map: (::Array[any] array) { (any) -> any } -> ::Array[any] | ||
Strech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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,78 @@ | ||
| require "datadog/di/spec_helper" | ||
| require 'datadog/di/transport/http' | ||
|
|
||
| RSpec.describe Datadog::DI::Transport::Input::Transport do | ||
| di_test | ||
|
|
||
| let(:transport) do | ||
| Datadog::DI::Transport::HTTP.input(agent_settings: agent_settings, logger: logger) | ||
| end | ||
|
|
||
| let(:agent_settings) { Datadog::Core::Configuration::AgentSettingsResolver.call(settings, logger: nil) } | ||
|
|
||
| let(:settings) do | ||
| Datadog::Core::Configuration::Settings.new | ||
| end | ||
|
|
||
| let(:logger) do | ||
| instance_double(Logger) | ||
| end | ||
|
|
||
| let(:tags) { [] } | ||
|
|
||
| context 'when the combined size of snapshots serialized exceeds intake max' do | ||
| before do | ||
| # Reduce limits to make the test run faster and not require a lot of memory | ||
| stub_const('Datadog::DI::Transport::Input::Transport::DEFAULT_CHUNK_SIZE', 100_000) | ||
| stub_const('Datadog::DI::Transport::Input::Transport::MAX_CHUNK_SIZE', 200_000) | ||
| end | ||
|
|
||
| let(:snapshot) do | ||
| # It doesn't matter what the payload is, generate a fake one here. | ||
| # This payload serializes to 9781 bytes of JSON. | ||
| 1000.times.map do |i| | ||
| [i, i] | ||
| end.to_h | ||
| end | ||
|
|
||
| let(:snapshots) do | ||
| # This serializes to 978201 bytes of JSON - just under 1 MB. | ||
| [snapshot] * 100 | ||
| end | ||
|
|
||
| it 'chunks snapshots' do | ||
| # Just under 1 MB payload, default chunk size ~100 KB, we expect 10 chunks | ||
| expect(transport).to receive(:send_input_chunk).exactly(10).times do |chunked_payload, serialized_tags| | ||
| expect(chunked_payload.length).to be < 100_000 | ||
| expect(chunked_payload.length).to be > 90_000 | ||
| end | ||
| transport.send_input(snapshots, tags) | ||
| end | ||
|
|
||
| context 'when individual snapshot exceeds intake max' do | ||
| before do | ||
| # Reduce limits even more to force a reasonably-sized snapshot to be dropped | ||
| stub_const('Datadog::DI::Transport::Input::Transport::MAX_SERIALIZED_SNAPSHOT_SIZE', 2_000) | ||
| end | ||
|
|
||
| let(:small_snapshot) do | ||
| 20.times.map do |i| | ||
| [i, i] | ||
| end.to_h | ||
| end | ||
|
|
||
| let(:snapshots) do | ||
| [small_snapshot, snapshot] | ||
| end | ||
|
|
||
| it 'drops snapshot that is too big' do | ||
| expect(transport).to receive(:send_input_chunk).once do |chunked_payload, serialized_tags| | ||
| expect(chunked_payload.length).to be < 1_000 | ||
| expect(chunked_payload.length).to be > 100 | ||
| end | ||
| expect_lazy_log(logger, :debug, 'di: dropping too big snapshot') | ||
| transport.send_input(snapshots, tags) | ||
| end | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.