Skip to content

Commit 7b8c6d2

Browse files
authored
build(dev): Enable basic optimizations for dev builds (#5450)
1 parent cd0af14 commit 7b8c6d2

File tree

9 files changed

+78
-34
lines changed

9 files changed

+78
-34
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ jobs:
176176
key: ${{ github.job }}
177177

178178
- name: Run Cargo Tests
179-
run: cargo test --workspace
179+
env:
180+
# Faster compilation on slower CI runners.
181+
CARGO_PROFILE_DEV_OPT_LEVEL: 0
182+
run: |
183+
cargo test --workspace
180184
181185
test_all:
182186
needs: build-setup
@@ -233,6 +237,9 @@ jobs:
233237
key: ${{ github.job }}
234238

235239
- name: Run Cargo Tests
240+
env:
241+
# Faster compilation on slower CI runners.
242+
CARGO_PROFILE_DEV_OPT_LEVEL: 0
236243
run: cargo test --workspace --all-features
237244

238245
test_py:

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ resolver = "2"
77
# Debug information slows down the build and increases caches in the
88
# target folder, but we don't require stack traces in most cases.
99
debug = false
10+
opt-level = 1
1011

1112
[profile.dev-debug]
1213
# A version of the dev profile with debug information enabled, for e.g. local
1314
# debugging.
1415
inherits = "dev"
1516
debug = true
17+
opt-level = 0
1618

1719
[profile.release]
1820
# In release, however, we do want full debug information to report

relay-event-normalization/src/normalize/span/description/sql/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ mod tests {
884884
}
885885

886886
#[test]
887+
#[cfg(not(target_os = "windows"))] // Causes a `STATUS_STACK_OVERFLOW` when compiled with opt-level=1 on windows
887888
fn visit_deep_expression() {
888889
struct TestVisitor;
889890
impl Visitor for TestVisitor {

tests/integration/asserts/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Any, Callable
2-
from .time import time_after, time_within, time_within_delta
2+
from .time import time_after, time_within, time_within_delta, time_is
33
from .protocol import only_items
44

55
__all__ = [
66
"matches",
77
"only_items",
88
"time_after",
9+
"time_is",
910
"time_within",
1011
"time_within_delta",
1112
]

tests/integration/asserts/time.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ def _truncate(dt, resolution=None):
5252
}[resolution](dt)
5353

5454

55+
def _resolution_to_timedelta(resolution):
56+
if resolution is None:
57+
return timedelta(microseconds=1)
58+
59+
return {
60+
Resolution.Seconds: timedelta(seconds=1),
61+
Resolution.MilliSeconds: timedelta(milliseconds=1),
62+
Resolution.MicroSeconds: timedelta(microseconds=1),
63+
# Resolution of the Python datetime itself is just in microseconds
64+
Resolution.NanoSeconds: timedelta(microseconds=1),
65+
}[resolution]
66+
67+
5568
def _format_resolution(dt: datetime, resolution):
5669
match resolution:
5770
case Resolution.Seconds:
@@ -75,7 +88,9 @@ def __init__(
7588
precision=None,
7689
):
7790
self._lower_bound = _truncate(lower_bound, precision)
78-
self._upper_bound = _truncate(upper_bound, precision)
91+
self._upper_bound = _truncate(
92+
upper_bound, precision
93+
) + _resolution_to_timedelta(precision)
7994
self._expect_resolution = expect_resolution
8095

8196
def __eq__(self, other):
@@ -94,22 +109,40 @@ def __repr__(self) -> str:
94109
return str(self)
95110

96111

112+
def time_is(time, **kwargs):
113+
"""
114+
Assertion helper which compares the actual time against the expected time.
115+
"""
116+
return time_within(time, time, **kwargs)
117+
118+
97119
def time_after(lower_bound, **kwargs):
120+
"""
121+
Assertion helper which ensures the actual time is after the specified time.
122+
"""
98123
upper_bound = datetime.now(tz=timezone.utc)
99124
return time_within(lower_bound, upper_bound, **kwargs)
100125

101126

102127
def time_within(lower_bound, upper_bound=None, **kwargs):
128+
"""
129+
Assertion helper which ensures the actual time is between the specified lower and upper bound.
130+
131+
If no upper bound is specified, the current time is used as an upper bound.
132+
"""
103133
lower_bound = _to_datetime(lower_bound)
104134
upper_bound = (
105135
_to_datetime(upper_bound)
106136
if upper_bound is not None
107137
else datetime.now(tz=timezone.utc)
108138
)
109-
assert lower_bound <= upper_bound
139+
assert lower_bound <= upper_bound, f"{lower_bound} <= {upper_bound}"
110140
return _WithinBounds(lower_bound, upper_bound, **kwargs)
111141

112142

113143
def time_within_delta(time=None, delta=timedelta(seconds=30), **kwargs):
144+
"""
145+
Assertion helper which ensures the actual time is between the specified time and a delta.
146+
"""
114147
time = _to_datetime(time) if time is not None else datetime.now(tz=timezone.utc)
115148
return _WithinBounds(time - delta, time + delta, **kwargs)

tests/integration/test_attachments.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import uuid
33
import json
44

5+
from unittest import mock
56
from requests.exceptions import HTTPError
67
from sentry_sdk.envelope import Envelope, Item, PayloadRef
78
from objectstore_client import Client, Usecase
@@ -153,10 +154,10 @@ def test_attachments_with_objectstore(
153154
)
154155
assert objectstore_session.get(objectstore_key).payload.read() == chunked_contents
155156

156-
assert attachment["attachment"].pop("id")
157157
assert attachment == {
158158
"type": "attachment",
159159
"attachment": {
160+
"id": mock.ANY,
160161
"name": "foo.txt",
161162
"rate_limited": False,
162163
"attachment_type": "event.attachment",
@@ -170,11 +171,10 @@ def test_attachments_with_objectstore(
170171

171172
# An empty attachment
172173
attachment = attachments_consumer.get_individual_attachment()
173-
assert attachment["attachment"].pop("id")
174-
175174
assert attachment == {
176175
"type": "attachment",
177176
"attachment": {
177+
"id": mock.ANY,
178178
"name": "foobar.txt",
179179
"rate_limited": False,
180180
"attachment_type": "event.attachment",

tests/integration/test_attachmentsv2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sentry_relay.consts import DataCategory
44
from unittest import mock
55

6-
from .asserts import time_within_delta, time_within
6+
from .asserts import time_within_delta, time_is
77
from .test_spansv2 import envelope_with_spans
88

99
from .test_dynamic_sampling import _add_sampling_config
@@ -215,8 +215,8 @@ def test_attachment_with_matching_span(mini_sentry, relay):
215215
"name": "test span",
216216
"status": "ok",
217217
"is_segment": True,
218-
"start_timestamp": time_within(ts),
219-
"end_timestamp": time_within(ts.timestamp() + 0.5),
218+
"start_timestamp": time_is(ts),
219+
"end_timestamp": time_is(ts.timestamp() + 0.5),
220220
"attributes": mock.ANY,
221221
}
222222
]
@@ -304,8 +304,8 @@ def test_two_attachments_mapping_to_same_span(mini_sentry, relay):
304304
"name": "test span",
305305
"status": "ok",
306306
"is_segment": True,
307-
"start_timestamp": time_within(ts),
308-
"end_timestamp": time_within(ts.timestamp() + 0.5),
307+
"start_timestamp": time_is(ts),
308+
"end_timestamp": time_is(ts.timestamp() + 0.5),
309309
"attributes": mock.ANY,
310310
}
311311
]

tests/integration/test_spans_standalone.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def test_lcp_span(
187187
"transaction": "/insights/projects/",
188188
},
189189
"retention_days": 90,
190-
"received_at": time_within(ts),
190+
"received_at": time_within(ts, precision="s"),
191191
},
192192
{
193193
"org_id": 1,
@@ -198,7 +198,7 @@ def test_lcp_span(
198198
"timestamp": time_within_delta(ts),
199199
"tags": {},
200200
"retention_days": 90,
201-
"received_at": time_within(ts),
201+
"received_at": time_within(ts, precision="s"),
202202
},
203203
# No metric extraction in the SpanV2 pipeline.
204204
*(
@@ -218,7 +218,7 @@ def test_lcp_span(
218218
"transaction": "/insights/projects/",
219219
},
220220
"retention_days": 90,
221-
"received_at": time_within(ts),
221+
"received_at": time_within(ts, precision="s"),
222222
}
223223
]
224224
if mode == "legacy"
@@ -362,7 +362,7 @@ def test_cls_span(
362362
"transaction": "/insights/projects/",
363363
},
364364
"retention_days": 90,
365-
"received_at": time_within(ts),
365+
"received_at": time_within(ts, precision="s"),
366366
},
367367
{
368368
"org_id": 1,
@@ -373,7 +373,7 @@ def test_cls_span(
373373
"timestamp": time_within_delta(ts),
374374
"tags": {},
375375
"retention_days": 90,
376-
"received_at": time_within(ts),
376+
"received_at": time_within(ts, precision="s"),
377377
},
378378
# No metric extraction in the SpanV2 pipeline.
379379
*(
@@ -393,7 +393,7 @@ def test_cls_span(
393393
"transaction": "/insights/projects/",
394394
},
395395
"retention_days": 90,
396-
"received_at": time_within(ts),
396+
"received_at": time_within(ts, precision="s"),
397397
}
398398
]
399399
if mode == "legacy"
@@ -521,7 +521,7 @@ def test_inp_span(
521521
"transaction": "/insights/projects/",
522522
},
523523
"retention_days": 90,
524-
"received_at": time_within(ts),
524+
"received_at": time_within(ts, precision="s"),
525525
},
526526
{
527527
"org_id": 1,
@@ -532,7 +532,7 @@ def test_inp_span(
532532
"timestamp": time_within_delta(ts),
533533
"tags": {},
534534
"retention_days": 90,
535-
"received_at": time_within(ts),
535+
"received_at": time_within(ts, precision="s"),
536536
},
537537
# No metric extraction in the SpanV2 pipeline.
538538
*(
@@ -552,7 +552,7 @@ def test_inp_span(
552552
"transaction": "/insights/projects/",
553553
},
554554
"retention_days": 90,
555-
"received_at": time_within(ts),
555+
"received_at": time_within(ts, precision="s"),
556556
}
557557
]
558558
if mode == "legacy"

tests/integration/test_spansv2.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from sentry_sdk.envelope import Envelope, Item, PayloadRef
55
from sentry_relay.consts import DataCategory
66

7-
from .asserts import time_within_delta, time_within
7+
from .asserts import time_within_delta, time_within, time_is
88

99
from .test_dynamic_sampling import _add_sampling_config
1010

@@ -125,8 +125,8 @@ def test_spansv2_basic(
125125
},
126126
"name": "some op",
127127
"received": time_within(ts),
128-
"start_timestamp": time_within(ts),
129-
"end_timestamp": time_within(ts.timestamp() + 0.5),
128+
"start_timestamp": time_is(ts),
129+
"end_timestamp": time_is(ts.timestamp() + 0.5),
130130
"is_segment": True,
131131
"status": "ok",
132132
"retention_days": 42,
@@ -141,7 +141,7 @@ def test_spansv2_basic(
141141
"name": "c:spans/count_per_root_project@none",
142142
"org_id": 1,
143143
"project_id": 42,
144-
"received_at": time_within_delta(),
144+
"received_at": time_within(ts, precision="s"),
145145
"retention_days": 90,
146146
"tags": {
147147
"decision": "keep",
@@ -156,7 +156,7 @@ def test_spansv2_basic(
156156
"name": "c:spans/usage@none",
157157
"org_id": 1,
158158
"project_id": 42,
159-
"received_at": time_within_delta(),
159+
"received_at": time_within(ts, precision="s"),
160160
"retention_days": 90,
161161
"tags": {},
162162
"timestamp": time_within_delta(),
@@ -329,7 +329,7 @@ def test_spansv2_ds_sampled(
329329
"name": "c:spans/count_per_root_project@none",
330330
"org_id": 1,
331331
"project_id": 43,
332-
"received_at": time_within_delta(),
332+
"received_at": time_within(ts, precision="s"),
333333
"retention_days": 90,
334334
"tags": {
335335
"decision": "keep",
@@ -344,7 +344,7 @@ def test_spansv2_ds_sampled(
344344
"name": "c:spans/usage@none",
345345
"org_id": 1,
346346
"project_id": 42,
347-
"received_at": time_within_delta(),
347+
"received_at": time_within(ts, precision="s"),
348348
"retention_days": 90,
349349
"tags": {},
350350
"timestamp": time_within_delta(),
@@ -425,7 +425,7 @@ def test_spansv2_ds_root_in_different_org(
425425
"name": "c:spans/count_per_root_project@none",
426426
"org_id": 1,
427427
"project_id": 42,
428-
"received_at": time_within_delta(),
428+
"received_at": time_within(ts, precision="s"),
429429
"retention_days": 90,
430430
"tags": {"decision": "drop", "target_project_id": "42"},
431431
"timestamp": time_within_delta(),
@@ -436,7 +436,7 @@ def test_spansv2_ds_root_in_different_org(
436436
"name": "c:spans/usage@none",
437437
"org_id": 1,
438438
"project_id": 42,
439-
"received_at": time_within_delta(),
439+
"received_at": time_within(ts, precision="s"),
440440
"retention_days": 90,
441441
"tags": {},
442442
"timestamp": time_within_delta(),
@@ -815,8 +815,8 @@ def test_spanv2_with_string_pii_scrubbing(
815815
},
816816
},
817817
"name": "Test span",
818-
"start_timestamp": time_within(ts),
819-
"end_timestamp": time_within(ts.timestamp() + 0.5),
818+
"start_timestamp": time_is(ts),
819+
"end_timestamp": time_is(ts.timestamp() + 0.5),
820820
"is_segment": False,
821821
"status": "ok",
822822
}
@@ -974,8 +974,8 @@ def test_spansv2_attribute_normalization(
974974
},
975975
"name": "some op",
976976
"received": time_within(ts),
977-
"start_timestamp": time_within(ts),
978-
"end_timestamp": time_within(ts.timestamp() + 0.5),
977+
"start_timestamp": time_is(ts),
978+
"end_timestamp": time_is(ts.timestamp() + 0.5),
979979
"is_segment": True,
980980
"status": "ok",
981981
"retention_days": 42,

0 commit comments

Comments
 (0)