Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug 1909875: improve CrashIdsFailedToPublish information #6775

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions socorro/external/pubsub/crashqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from google.cloud.pubsub_v1 import PublisherClient, SubscriberClient
from google.cloud.pubsub_v1.types import BatchSettings, PublisherOptions
from more_itertools import chunked
import sentry_sdk

from socorro.external.crashqueue_base import CrashQueueBase

Expand Down Expand Up @@ -260,15 +261,14 @@ def publish(self, queue, crash_ids):
for i, future in enumerate(futures):
try:
future.result()
except Exception:
except Exception as exc:
sentry_sdk.capture_exception(exc)
logger.exception(
"Crashid failed to publish: %s %s",
"crashid failed to publish: %s %s",
queue,
batch[i],
)
failed.append(batch[i])
failed.append((repr(exc), batch[i]))

if failed:
raise CrashIdsFailedToPublish(
f"Crashids failed to publish: {','.join(failed)}"
)
raise CrashIdsFailedToPublish(f"Crashids failed to publish: {failed!r}")
31 changes: 30 additions & 1 deletion socorro/tests/external/pubsub/test_crashqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

import pytest

from socorro import settings
from socorro.external.pubsub.crashqueue import CrashIdsFailedToPublish
from socorro.libclass import build_instance_from_settings
from socorro.lib.libooid import create_new_ooid
from socorro import settings


# Amount of time to sleep between publish and pull so messages are available
PUBSUB_DELAY_PULL = 0.5
Expand Down Expand Up @@ -108,3 +110,30 @@ def test_publish_many(self, pubsub_helper, queue):

published_crash_ids = pubsub_helper.get_published_crashids(queue)
assert set(published_crash_ids) == {crash_id_1, crash_id_2, crash_id_3}

def test_publish_with_error(self, pubsub_helper, sentry_helper):
queue = "reprocessing"
crash_id = create_new_ooid()

crashqueue = build_instance_from_settings(settings.QUEUE_PUBSUB)

# Run teardown_queues in the helper so there's no queue. That will cause an
# error to get thrown by PubSub.
pubsub_helper.teardown_queues()

with sentry_helper.init() as sentry_client:
try:
crashqueue.publish(queue, [crash_id])
except CrashIdsFailedToPublish as exc:
print(exc)

# wait for published messages to become available before pulling
time.sleep(PUBSUB_DELAY_PULL)

(envelope,) = sentry_client.envelope_payloads
errors = [
f"{error['type']} {error['value']}"
for error in envelope["exception"]["values"]
]

assert "NotFound Topic not found" in errors