Skip to content

Commit 1b2ec1c

Browse files
chore(profiling): remove stack_v2_enabled=False tests [backport 2.20] (#12188)
Co-authored-by: Taegyun Kim <[email protected]>
1 parent 22f7d47 commit 1b2ec1c

File tree

5 files changed

+35
-114
lines changed

5 files changed

+35
-114
lines changed

tests/profiling_v2/collector/test_stack.py

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
env=dict(
3030
DD_PROFILING_MAX_FRAMES="5",
3131
DD_PROFILING_OUTPUT_PPROF="/tmp/test_collect_truncate",
32-
DD_PROFILING_STACK_V2_ENABLED="1",
3332
)
3433
)
3534
@pytest.mark.skipif(sys.version_info[:2] == (3, 7), reason="stack_v2 is not supported on Python 3.7")
@@ -61,9 +60,8 @@ def test_collect_truncate():
6160
assert len(sample.location_id) <= max_nframes + 2, len(sample.location_id)
6261

6362

64-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
65-
def test_stack_locations(stack_v2_enabled, tmp_path):
66-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
63+
def test_stack_locations(tmp_path):
64+
if sys.version_info[:2] == (3, 7):
6765
pytest.skip("stack_v2 is not supported on Python 3.7")
6866

6967
test_name = "test_stack_locations"
@@ -83,7 +81,7 @@ def bar():
8381
def foo():
8482
bar()
8583

86-
with stack.StackCollector(None, _stack_collector_v2_enabled=stack_v2_enabled):
84+
with stack.StackCollector(None, _stack_collector_v2_enabled=True):
8785
for _ in range(10):
8886
foo()
8987
ddup.upload()
@@ -117,9 +115,8 @@ def foo():
117115
pprof_utils.assert_profile_has_sample(profile, samples=samples, expected_sample=expected_sample)
118116

119117

120-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
121-
def test_push_span(stack_v2_enabled, tmp_path, tracer):
122-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
118+
def test_push_span(tmp_path, tracer):
119+
if sys.version_info[:2] == (3, 7):
123120
pytest.skip("stack_v2 is not supported on Python 3.7")
124121

125122
test_name = "test_push_span"
@@ -140,7 +137,7 @@ def test_push_span(stack_v2_enabled, tmp_path, tracer):
140137
tracer=tracer,
141138
endpoint_collection_enabled=True,
142139
ignore_profiler=True, # this is not necessary, but it's here to trim samples
143-
_stack_collector_v2_enabled=stack_v2_enabled,
140+
_stack_collector_v2_enabled=True,
144141
):
145142
with tracer.trace("foobar", resource=resource, span_type=span_type) as span:
146143
span_id = span.span_id
@@ -221,9 +218,8 @@ def target_fun():
221218
unregister_thread.assert_called_with(thread_id)
222219

223220

224-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
225-
def test_push_non_web_span(stack_v2_enabled, tmp_path, tracer):
226-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
221+
def test_push_non_web_span(tmp_path, tracer):
222+
if sys.version_info[:2] == (3, 7):
227223
pytest.skip("stack_v2 is not supported on Python 3.7")
228224

229225
tracer._endpoint_call_counter_span_processor.enable()
@@ -244,7 +240,7 @@ def test_push_non_web_span(stack_v2_enabled, tmp_path, tracer):
244240
tracer=tracer,
245241
endpoint_collection_enabled=True,
246242
ignore_profiler=True, # this is not necessary, but it's here to trim samples
247-
_stack_collector_v2_enabled=stack_v2_enabled,
243+
_stack_collector_v2_enabled=True,
248244
):
249245
with tracer.trace("foobar", resource=resource, span_type=span_type) as span:
250246
span_id = span.span_id
@@ -269,10 +265,9 @@ def test_push_non_web_span(stack_v2_enabled, tmp_path, tracer):
269265
)
270266

271267

272-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
273-
def test_push_span_none_span_type(stack_v2_enabled, tmp_path, tracer):
268+
def test_push_span_none_span_type(tmp_path, tracer):
274269
# Test for https://github.com/DataDog/dd-trace-py/issues/11141
275-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
270+
if sys.version_info[:2] == (3, 7):
276271
pytest.skip("stack_v2 is not supported on Python 3.7")
277272

278273
test_name = "test_push_span_none_span_type"
@@ -292,7 +287,7 @@ def test_push_span_none_span_type(stack_v2_enabled, tmp_path, tracer):
292287
tracer=tracer,
293288
endpoint_collection_enabled=True,
294289
ignore_profiler=True, # this is not necessary, but it's here to trim samples
295-
_stack_collector_v2_enabled=stack_v2_enabled,
290+
_stack_collector_v2_enabled=True,
296291
):
297292
# Explicitly set None span_type as the default could change in the
298293
# future.
@@ -484,9 +479,8 @@ def test_exception_collection_trace(stack_v2_enabled, tmp_path, tracer):
484479
)
485480

486481

487-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
488-
def test_collect_once_with_class(stack_v2_enabled, tmp_path):
489-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
482+
def test_collect_once_with_class(tmp_path):
483+
if sys.version_info[:2] == (3, 7):
490484
pytest.skip("stack_v2 is not supported on Python 3.7")
491485

492486
class SomeClass(object):
@@ -506,7 +500,7 @@ def sleep_instance(self):
506500
ddup.config(env="test", service=test_name, version="my_version", output_filename=pprof_prefix)
507501
ddup.start()
508502

509-
with stack.StackCollector(None, ignore_profiler=True, _stack_collector_v2_enabled=stack_v2_enabled):
503+
with stack.StackCollector(None, ignore_profiler=True, _stack_collector_v2_enabled=True):
510504
SomeClass.sleep_class()
511505

512506
ddup.upload()
@@ -521,7 +515,6 @@ def sleep_instance(self):
521515
expected_sample=pprof_utils.StackEvent(
522516
thread_id=_thread.get_ident(),
523517
thread_name="MainThread",
524-
class_name="SomeClass" if not stack_v2_enabled else None,
525518
locations=[
526519
pprof_utils.StackLocation(
527520
function_name="sleep_instance",
@@ -536,16 +529,15 @@ def sleep_instance(self):
536529
pprof_utils.StackLocation(
537530
function_name="test_collect_once_with_class",
538531
filename="test_stack.py",
539-
line_no=test_collect_once_with_class.__code__.co_firstlineno + 23,
532+
line_no=test_collect_once_with_class.__code__.co_firstlineno + 22,
540533
),
541534
],
542535
),
543536
)
544537

545538

546-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
547-
def test_collect_once_with_class_not_right_type(stack_v2_enabled, tmp_path):
548-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
539+
def test_collect_once_with_class_not_right_type(tmp_path):
540+
if sys.version_info[:2] == (3, 7):
549541
pytest.skip("stack_v2 is not supported on Python 3.7")
550542

551543
class SomeClass(object):
@@ -565,7 +557,7 @@ def sleep_instance(foobar, self):
565557
ddup.config(env="test", service=test_name, version="my_version", output_filename=pprof_prefix)
566558
ddup.start()
567559

568-
with stack.StackCollector(None, ignore_profiler=True, _stack_collector_v2_enabled=stack_v2_enabled):
560+
with stack.StackCollector(None, ignore_profiler=True, _stack_collector_v2_enabled=True):
569561
SomeClass.sleep_class(123)
570562

571563
ddup.upload()
@@ -580,9 +572,6 @@ def sleep_instance(foobar, self):
580572
expected_sample=pprof_utils.StackEvent(
581573
thread_id=_thread.get_ident(),
582574
thread_name="MainThread",
583-
# stack v1 relied on using cls and self to figure out class name
584-
# so we can't find it here.
585-
class_name=None,
586575
locations=[
587576
pprof_utils.StackLocation(
588577
function_name="sleep_instance",
@@ -597,7 +586,7 @@ def sleep_instance(foobar, self):
597586
pprof_utils.StackLocation(
598587
function_name="test_collect_once_with_class_not_right_type",
599588
filename="test_stack.py",
600-
line_no=test_collect_once_with_class_not_right_type.__code__.co_firstlineno + 23,
589+
line_no=test_collect_once_with_class_not_right_type.__code__.co_firstlineno + 22,
601590
),
602591
],
603592
),

tests/profiling_v2/collector/test_stack_asyncio.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
@pytest.mark.subprocess(
88
env=dict(
99
DD_PROFILING_OUTPUT_PPROF="/tmp/test_stack_asyncio",
10-
DD_PROFILING_STACK_V2_ENABLED="true",
1110
),
1211
)
1312
def test_asyncio():

tests/profiling_v2/test_accuracy.py

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,7 @@
44
import pytest
55

66

7-
@pytest.mark.subprocess(
8-
env=dict(DD_PROFILING_MAX_TIME_USAGE_PCT="100", DD_PROFILING_OUTPUT_PPROF="/tmp/test_accuracy_libdd.pprof")
9-
)
10-
def test_accuracy_libdd():
11-
import collections
12-
import os
13-
14-
from ddtrace.profiling import profiler
15-
from tests.profiling.collector import pprof_utils
16-
from tests.profiling.test_accuracy import assert_almost_equal
17-
from tests.profiling.test_accuracy import spend_16
18-
19-
# Set this to 100 so we don't sleep too often and mess with the precision.
20-
p = profiler.Profiler()
21-
p.start()
22-
spend_16()
23-
p.stop()
24-
wall_times = collections.defaultdict(lambda: 0)
25-
cpu_times = collections.defaultdict(lambda: 0)
26-
profile = pprof_utils.parse_profile(os.environ["DD_PROFILING_OUTPUT_PPROF"] + "." + str(os.getpid()))
27-
28-
for sample in profile.sample:
29-
wall_time_index = pprof_utils.get_sample_type_index(profile, "wall-time")
30-
31-
wall_time_spent_ns = sample.value[wall_time_index]
32-
cpu_time_index = pprof_utils.get_sample_type_index(profile, "cpu-time")
33-
cpu_time_spent_ns = sample.value[cpu_time_index]
34-
35-
for location_id in sample.location_id:
36-
location = pprof_utils.get_location_with_id(profile, location_id)
37-
line = location.line[0]
38-
function = pprof_utils.get_function_with_id(profile, line.function_id)
39-
function_name = profile.string_table[function.name]
40-
wall_times[function_name] += wall_time_spent_ns
41-
cpu_times[function_name] += cpu_time_spent_ns
42-
43-
assert_almost_equal(wall_times["spend_3"], 9e9)
44-
assert_almost_equal(wall_times["spend_1"], 2e9)
45-
assert_almost_equal(wall_times["spend_4"], 4e9)
46-
assert_almost_equal(wall_times["spend_16"], 16e9)
47-
assert_almost_equal(wall_times["spend_7"], 7e9)
48-
49-
assert_almost_equal(wall_times["spend_cpu_2"], 2e9, tolerance=0.09)
50-
assert_almost_equal(wall_times["spend_cpu_3"], 3e9, tolerance=0.09)
51-
assert_almost_equal(cpu_times["spend_cpu_2"], 2e9, tolerance=0.09)
52-
assert_almost_equal(cpu_times["spend_cpu_3"], 3e9, tolerance=0.09)
53-
54-
55-
@pytest.mark.subprocess(
56-
env=dict(DD_PROFILING_STACK_V2_ENABLED="1", DD_PROFILING_OUTPUT_PPROF="/tmp/test_accuracy_stack_v2.pprof")
57-
)
7+
@pytest.mark.subprocess(env=dict(DD_PROFILING_OUTPUT_PPROF="/tmp/test_accuracy_stack_v2.pprof"))
588
@pytest.mark.skipif(sys.version_info[:2] == (3, 7), reason="stack_v2 is not supported on Python 3.7")
599
def test_accuracy_stack_v2():
6010
import collections

tests/profiling_v2/test_gunicorn.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ def _run_gunicorn(*args):
5252
def gunicorn(monkeypatch):
5353
monkeypatch.setenv("DD_PROFILING_IGNORE_PROFILER", "1")
5454
monkeypatch.setenv("DD_PROFILING_ENABLED", "1")
55-
# This was needed for the gunicorn process to start and print worker startup
56-
# messages. Without this, the test can't find the worker PIDs.
57-
monkeypatch.setenv("DD_PROFILING_STACK_V2_ENABLED", "1")
5855

5956
yield _run_gunicorn
6057

tests/profiling_v2/test_main.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111
from tests.utils import flaky
1212

1313

14-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
15-
def test_call_script(stack_v2_enabled):
16-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
14+
def test_call_script():
15+
if sys.version_info[:2] == (3, 7):
1716
pytest.skip("stack_v2 is not supported on Python 3.7")
1817
env = os.environ.copy()
1918
env["DD_PROFILING_ENABLED"] = "1"
20-
env["DD_PROFILING_STACK_V2_ENABLED"] = "1" if stack_v2_enabled else "0"
2119
stdout, stderr, exitcode, _ = call_program(
2220
"ddtrace-run", sys.executable, os.path.join(os.path.dirname(__file__), "simple_program.py"), env=env
2321
)
@@ -28,28 +26,25 @@ def test_call_script(stack_v2_enabled):
2826
hello, interval, pid, stack_v2 = list(s.strip() for s in stdout.decode().strip().split("\n"))
2927
assert hello == "hello world", stdout.decode().strip()
3028
assert float(interval) >= 0.01, stdout.decode().strip()
31-
assert stack_v2 == str(stack_v2_enabled)
29+
assert stack_v2 == str(True)
3230

3331

3432
@pytest.mark.skipif(not os.getenv("DD_PROFILE_TEST_GEVENT", False), reason="Not testing gevent")
35-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
36-
def test_call_script_gevent(stack_v2_enabled):
37-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
33+
def test_call_script_gevent():
34+
if sys.version_info[:2] == (3, 7):
3835
pytest.skip("stack_v2 is not supported on Python 3.7")
39-
if sys.version_info[:2] == (3, 8) and stack_v2_enabled:
36+
if sys.version_info[:2] == (3, 8):
4037
pytest.skip("this test is flaky on 3.8 with stack v2")
4138
env = os.environ.copy()
4239
env["DD_PROFILING_ENABLED"] = "1"
43-
env["DD_PROFILING_STACK_V2_ENABLED"] = "1" if stack_v2_enabled else "0"
4440
stdout, stderr, exitcode, pid = call_program(
4541
sys.executable, os.path.join(os.path.dirname(__file__), "simple_program_gevent.py"), env=env
4642
)
4743
assert exitcode == 0, (stdout, stderr)
4844

4945

50-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
51-
def test_call_script_pprof_output(stack_v2_enabled, tmp_path):
52-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
46+
def test_call_script_pprof_output(tmp_path):
47+
if sys.version_info[:2] == (3, 7):
5348
pytest.skip("stack_v2 is not supported on Python 3.7")
5449

5550
"""This checks if the pprof output and atexit register work correctly.
@@ -61,7 +56,6 @@ def test_call_script_pprof_output(stack_v2_enabled, tmp_path):
6156
env["DD_PROFILING_OUTPUT_PPROF"] = filename
6257
env["DD_PROFILING_CAPTURE_PCT"] = "1"
6358
env["DD_PROFILING_ENABLED"] = "1"
64-
env["DD_PROFILING_STACK_V2_ENABLED"] = "1" if stack_v2_enabled else "0"
6559
stdout, stderr, exitcode, _ = call_program(
6660
"ddtrace-run",
6761
sys.executable,
@@ -78,17 +72,15 @@ def test_call_script_pprof_output(stack_v2_enabled, tmp_path):
7872
assert len(samples) > 0
7973

8074

81-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
8275
@pytest.mark.skipif(sys.platform == "win32", reason="fork only available on Unix")
83-
def test_fork(stack_v2_enabled, tmp_path):
84-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
76+
def test_fork(tmp_path):
77+
if sys.version_info[:2] == (3, 7):
8578
pytest.skip("stack_v2 is not supported on Python 3.7")
8679

8780
filename = str(tmp_path / "pprof")
8881
env = os.environ.copy()
8982
env["DD_PROFILING_OUTPUT_PPROF"] = filename
9083
env["DD_PROFILING_CAPTURE_PCT"] = "100"
91-
env["DD_PROFILING_STACK_V2_ENABLED"] = "1" if stack_v2_enabled else "0"
9284
stdout, stderr, exitcode, pid = call_program(
9385
"python", os.path.join(os.path.dirname(__file__), "simple_program_fork.py"), env=env
9486
)
@@ -144,14 +136,12 @@ def test_fork(stack_v2_enabled, tmp_path):
144136
)
145137

146138

147-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
148139
@pytest.mark.skipif(sys.platform == "win32", reason="fork only available on Unix")
149140
@pytest.mark.skipif(not os.getenv("DD_PROFILE_TEST_GEVENT", False), reason="Not testing gevent")
150-
def test_fork_gevent(stack_v2_enabled):
151-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
141+
def test_fork_gevent():
142+
if sys.version_info[:2] == (3, 7):
152143
pytest.skip("stack_v2 is not supported on Python 3.7")
153144
env = os.environ.copy()
154-
env["DD_PROFILING_STACK_V2_ENABLED"] = "1" if stack_v2_enabled else "0"
155145
stdout, stderr, exitcode, pid = call_program(
156146
"python", os.path.join(os.path.dirname(__file__), "../profiling", "gevent_fork.py"), env=env
157147
)
@@ -161,20 +151,18 @@ def test_fork_gevent(stack_v2_enabled):
161151
methods = multiprocessing.get_all_start_methods()
162152

163153

164-
@pytest.mark.parametrize("stack_v2_enabled", [True, False])
165154
@pytest.mark.parametrize(
166155
"method",
167156
set(methods) - {"forkserver", "fork"},
168157
)
169-
def test_multiprocessing(stack_v2_enabled, method, tmp_path):
170-
if sys.version_info[:2] == (3, 7) and stack_v2_enabled:
158+
def test_multiprocessing(method, tmp_path):
159+
if sys.version_info[:2] == (3, 7):
171160
pytest.skip("stack_v2 is not supported on Python 3.7")
172161
filename = str(tmp_path / "pprof")
173162
env = os.environ.copy()
174163
env["DD_PROFILING_OUTPUT_PPROF"] = filename
175164
env["DD_PROFILING_ENABLED"] = "1"
176165
env["DD_PROFILING_CAPTURE_PCT"] = "1"
177-
env["DD_PROFILING_STACK_V2_ENABLED"] = "1" if stack_v2_enabled else "0"
178166
stdout, stderr, exitcode, _ = call_program(
179167
"ddtrace-run",
180168
sys.executable,
@@ -208,8 +196,6 @@ def test_memalloc_no_init_error_on_fork():
208196
os.waitpid(pid, 0)
209197

210198

211-
# Not parametrizing with stack_v2_enabled as subprocess mark doesn't support
212-
# parametrized tests and this only tests our start up code.
213199
@pytest.mark.subprocess(
214200
ddtrace_run=True,
215201
env=dict(

0 commit comments

Comments
 (0)