From 1281c2f84b3e3027f0a9eb139256321fe410ac37 Mon Sep 17 00:00:00 2001 From: Munir Abdinur Date: Wed, 14 Jun 2023 11:46:28 -0400 Subject: [PATCH] avoid flushing large traces --- tests/integration/test_integration.py | 48 +++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index d08dbc7f5ee..74bbe9a662b 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -326,33 +326,33 @@ def test_metrics_partial_flush_disabled(encoding, monkeypatch): @allencodings def test_single_trace_too_large(encoding, monkeypatch): monkeypatch.setenv("DD_TRACE_API_VERSION", encoding) - # setting writer interval to 5 seconds so that buffer can fit larger traces - monkeypatch.setenv("DD_TRACE_WRITER_INTERVAL_SECONDS", "10.0") t = Tracer() assert t._partial_flush_enabled is True - with mock.patch("ddtrace.internal.writer.writer.log") as log: - key = "a" * 250 - with t.trace("huge"): - for i in range(200000): - with t.trace("operation") as s: - # Need to make the strings unique so that the v0.5 encoding doesn’t compress the data - s.set_tag(key + str(i), key + str(i)) - t.shutdown() - assert ( - mock.call( - "trace buffer (%s traces %db/%db) cannot fit trace of size %db, dropping (writer status: %s)", - AnyInt(), - AnyInt(), - AnyInt(), - AnyInt(), - AnyStr(), - ) - in log.warning.mock_calls - ), log.mock_calls[ - :20 - ] # limits number of logs, this test could generate hundreds of thousands of logs. - log.error.assert_not_called() + # This test asserts that a BufferFull exception is raised. We need to ensure the encoders queue is not flushed + # while trace chunks are being queued. + with mock.patch.object(AgentWriter, "flush_queue", return_value=None): + with mock.patch("ddtrace.internal.writer.writer.log") as log: + key = "a" * 250 + with t.trace("huge"): + for i in range(30000): + with t.trace("operation") as s: + # Need to make the strings unique so that the v0.5 encoding doesn’t compress the data + s.set_tag(key + str(i), key + str(i)) + assert ( + mock.call( + "trace buffer (%s traces %db/%db) cannot fit trace of size %db, dropping (writer status: %s)", + AnyInt(), + AnyInt(), + AnyInt(), + AnyInt(), + AnyStr(), + ) + in log.warning.mock_calls + ), log.mock_calls[ + :20 + ] # limits number of logs, this test could generate hundreds of thousands of logs. + log.error.assert_not_called() @allencodings