Skip to content

Commit b1ef3b5

Browse files
authored
fix(crons): Fix bug where processing error data growth is not capped. (#72867)
This fixes a bug where we don't delete the body of a processing error after evicting it from the set of data for that monitor. This occurred when we started storing the bodies of the errors in a separate key and we forgot to delete it.
1 parent 3bf1cdf commit b1ef3b5

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/sentry/monitors/processing_errors/__init__.py

Whitespace-only changes.

src/sentry/monitors/processing_errors/manager.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,17 @@ def store_error(error: CheckinProcessingError, monitor: Monitor | None):
131131
pipeline = redis_client.pipeline(transaction=False)
132132
pipeline.zadd(error_set_key, {error.id.hex: error.checkin.ts.timestamp()})
133133
pipeline.set(error_key, serialized_error, ex=MONITOR_ERRORS_LIFETIME)
134-
# Cap the error list to the `MAX_ERRORS_PER_SET` most recent errors
135-
pipeline.zremrangebyrank(error_set_key, 0, -(MAX_ERRORS_PER_SET + 1))
136134
pipeline.expire(error_set_key, MONITOR_ERRORS_LIFETIME)
137-
pipeline.execute()
135+
pipeline.zrange(error_set_key, 0, -(MAX_ERRORS_PER_SET + 1))
136+
processing_errors_to_remove = pipeline.execute()[-1]
137+
# Cap the error list to the `MAX_ERRORS_PER_SET` most recent errors
138+
if processing_errors_to_remove:
139+
pipeline = redis_client.pipeline(transaction=False)
140+
pipeline.delete(
141+
*[build_error_identifier(uuid.UUID(result)) for result in processing_errors_to_remove]
142+
)
143+
pipeline.zrem(error_set_key, *processing_errors_to_remove)
144+
pipeline.execute()
138145

139146

140147
def delete_error(project: Project, uuid: uuid.UUID):

tests/sentry/monitors/processing_errors/test_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ def test_store_max(self):
8686
assert len(retrieved_errors) == 2
8787
assert_processing_errors_equal(processing_errors[2], retrieved_errors[0])
8888
assert_processing_errors_equal(processing_errors[1], retrieved_errors[1])
89+
redis_client = _get_cluster()
90+
assert not redis_client.exists(build_error_identifier(processing_errors[0].id))
91+
assert redis_client.exists(build_error_identifier(processing_errors[1].id))
92+
assert redis_client.exists(build_error_identifier(processing_errors[2].id))
8993

9094
def test_get_for_monitor_empty(self):
9195
monitor = self.create_monitor()

0 commit comments

Comments
 (0)