Skip to content

Commit ad74c52

Browse files
authored
Measure compression, and precise sizes for manually emitted usecases (#97670)
This moves the compression step into the measured block, so we measure the storage operation end to end including compression. Also, this will now opt into precise metrics for the places where we manually emit file sizes, like compressed nodestore, debug files and bundles.
1 parent 067f879 commit ad74c52

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

src/sentry/models/debugfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ def create_dif_from_id(
323323
file.size,
324324
tags={"usecase": "debug-files", "compression": "none"},
325325
unit="byte",
326+
precise=True,
326327
)
327328

328329
dif = ProjectDebugFile.objects.create(

src/sentry/models/eventattachment.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,9 @@ def putfile(cls, project_id: int, attachment: CachedAttachment) -> PutfileResult
181181
blob_path = "eventattachments/v1/" + FileBlob.generate_unique_path()
182182

183183
storage = get_storage()
184-
compressed_blob = zstandard.compress(data)
185-
186-
with measure_storage_operation(
187-
"put", "attachments", size, len(compressed_blob), "zstd"
188-
):
184+
with measure_storage_operation("put", "attachments", size) as metric_emitter:
185+
compressed_blob = zstandard.compress(data)
186+
metric_emitter.record_compressed_size(len(compressed_blob), "zstd")
189187
storage.save(blob_path, BytesIO(compressed_blob))
190188

191189
else:

src/sentry/profiles/task.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,10 +1393,11 @@ def _process_vroomrs_transaction_profile(profile: Profile) -> bool:
13931393
if prof.is_sampled():
13941394
with sentry_sdk.start_span(op="gcs.write", name="compress and write"):
13951395
storage = get_profiles_storage()
1396-
compressed_profile = prof.compress()
13971396
with measure_storage_operation(
1398-
"put", "profiling", len(json_profile), len(compressed_profile), "lz4"
1399-
):
1397+
"put", "profiling", len(json_profile)
1398+
) as metric_emitter:
1399+
compressed_profile = prof.compress()
1400+
metric_emitter.record_compressed_size(len(compressed_profile), "lz4")
14001401
storage.save(prof.storage_path(), io.BytesIO(compressed_profile))
14011402
# we only run find_occurrences for sampled profiles, unsampled profiles
14021403
# are skipped
@@ -1456,10 +1457,11 @@ def _process_vroomrs_chunk_profile(profile: Profile) -> bool:
14561457
chunk.normalize()
14571458
with sentry_sdk.start_span(op="gcs.write", name="compress and write"):
14581459
storage = get_profiles_storage()
1459-
compressed_chunk = chunk.compress()
14601460
with measure_storage_operation(
1461-
"put", "profiling", len(json_profile), len(compressed_chunk), "lz4"
1462-
):
1461+
"put", "profiling", len(json_profile)
1462+
) as metric_emitter:
1463+
compressed_chunk = chunk.compress()
1464+
metric_emitter.record_compressed_size(len(compressed_chunk), "lz4")
14631465
storage.save(chunk.storage_path(), io.BytesIO(compressed_chunk))
14641466
with sentry_sdk.start_span(op="processing", name="send chunk to kafka"):
14651467
payload = build_chunk_kafka_message(chunk)

src/sentry/tasks/assemble.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ def _create_or_update_artifact_bundle(
522522
file.size,
523523
tags={"usecase": "artifact-bundles", "compression": "none"},
524524
unit="byte",
525+
precise=True,
525526
)
526527

527528
artifact_bundle = ArtifactBundle.objects.create(

src/sentry/utils/kvstore/bigtable.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def _set(self, key: str, value: bytes, ttl: timedelta | None = None) -> None:
246246
len(value),
247247
tags={"usecase": "nodestore", "compression": self.compression},
248248
unit="byte",
249+
precise=True,
249250
)
250251

251252
# Only need to write the column at all if any flags are enabled. And if

0 commit comments

Comments
 (0)