Deleting an issue answers 202, but its events stay in Discover when the delete replacement cannot be published to Kafka

Aperta
#4,606 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
18/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
clickhouse, docker, docker-compose, kafka, python

Direzione di ricerca

Start in the Sentry source at src/sentry/deletions/tasks/nodestore.py, where delete_events_from_eventstore calls start_delete_groups and end_delete_groups, then follow them into src/sentry/eventstream/snuba.py and src/sentry/eventstream/kafka/backend.py, where _send swallows publish errors. Done means a failed replacement publish makes the task raise and retry, and reproducing the steps with the Kafka write ACL denied leaves no events in Discover or ClickHouse.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Waiting for: Product Owner
Self-Hosted Version

26.10.1

CPU Architecture

x86_64

Docker Version

29.1.3

Docker Compose Version

5.6.1

Machine Specification
  • My system meets the minimum system requirements of Sentry
Installation Type

Fresh install of 26.10.1 on Ubuntu 24.04, with COMPOSE_PROFILES=errors-only in .env.custom.

Steps to Reproduce

With writes to the events Kafka topic denied, DELETE /api/0/issues/{id}/ answers 202 and the issue is gone, but its events stay in Discover and in ClickHouse, and nothing retries the Snuba replacement that would remove them.

  1. In the self-hosted checkout, stop the stack if it is running, enable the Kafka authorizer from a compose override (no source file changes) and start everything:
docker compose stop
cat > docker-compose.override.yml <<'EOF'
services:
  kafka:
    environment:
      KAFKA_AUTHORIZER_CLASS_NAME: "org.apache.kafka.metadata.authorizer.StandardAuthorizer"
      KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true"
EOF
docker compose up -d --wait
  1. Create a project and a personal token with the scopes event:admin, event:read, org:read and project:read. Set ORG (organization slug), PID (project id), KEY (the key in the DSN) and TOKEN. Send three events that group into one issue and count them in Discover:
B=http://localhost:9000
H="Authorization: Bearer $TOKEN"
for i in 1 2 3
do
  curl -s -o /dev/null -X POST "$B/api/$PID/store/?sentry_key=$KEY&sentry_version=7" -H 'Content-Type: application/json' -d '{"message":"delete-repro","level":"error"}'
done
sleep 20
GID=$(curl -s -H "$H" "$B/api/0/organizations/$ORG/issues/?project=$PID&query=delete-repro&statsPeriod=1h" | grep -o '"id":"[0-9]*"' | head -1 | tr -dc 0-9)
Q="$B/api/0/organizations/$ORG/events/?dataset=errors&field=id&field=issue.id&query=issue.id:$GID&project=$PID&statsPeriod=24h"
curl -s -H "$H" "$Q" | grep -o '"id":"[0-9a-f]\{32\}"' | wc -l    # 3
  1. Deny writes to events, delete the issue and read the taskworker log:
docker compose exec -T kafka kafka-acls --bootstrap-server localhost:29092 --add --deny-principal User:ANONYMOUS --operation Write --topic events
curl -s -o /dev/null -w '%{http_code}\n' -X DELETE -H "$H" "$B/api/0/issues/$GID/"    # 202
sleep 30
docker compose logs --since 2m taskworker | grep -E 'Could not (publish|wait)'
  1. Remove the ACL, then check the issue, Discover and ClickHouse:
docker compose exec -T kafka kafka-acls --bootstrap-server localhost:29092 --remove --deny-principal User:ANONYMOUS --operation Write --topic events --force
curl -s -o /dev/null -w '%{http_code}\n' -H "$H" "$B/api/0/issues/$GID/"    # 404
sleep 60
curl -s -H "$H" "$Q" | grep -o '"id":"[0-9a-f]\{32\}"' | wc -l    # 3
docker compose exec -T clickhouse clickhouse-client --query "SELECT count() FROM errors_local FINAL WHERE project_id = $PID AND group_id = $GID AND deleted = 0"    # 3
Expected Result

A delete that answers 202 should leave no events behind in Discover or ClickHouse. If the Snuba replacement cannot be published, the task should fail and be retried until it can, instead of finishing after the payloads and the group row are already gone.

Actual Result

The DELETE answers 202 and the issue answers 404, but Discover and ClickHouse still hold all 3 events after the ACL is removed. In three runs of three deletes each, all nine issues kept all three events. Reading them again after the ACL was removed, after a wait of more than five minutes, and after restarting snuba-replacer, taskworker and web listed every event each time (27 of 27 reads). Nine deletes with the topic writable removed theirs within a minute.

The grep in step 3 prints:

taskworker-1  | 08:39:05 [ERROR] sentry.eventstream.kafka.backend: Could not publish message (error: KafkaError{code=TOPIC_AUTHORIZATION_FAILED,val=29,str="Broker: Topic authorization failed"})
taskworker-1  | 08:39:05 [ERROR] sentry.eventstream.kafka.backend: Could not wait for message delivery: KafkaError{code=TOPIC_AUTHORIZATION_FAILED,val=29,str="Broker: Topic authorization failed"}
taskworker-1  | 08:39:05 [ERROR] sentry.eventstream.kafka.backend: Could not publish message: KafkaError{code=TOPIC_AUTHORIZATION_FAILED,val=29,str="Unable to produce message: Broker: Topic authorization failed"}

After the payloads are deleted from nodestore, delete_events_from_eventstore calls start_delete_groups and end_delete_groups (nodestore.py#L276-L277). Both go through KafkaEventStream._send(..., asynchronous=False) (snuba.py#L272, snuba.py#L279-L284), which catches produce and delivery errors, logs them and returns:

https://github.com/getsentry/sentry/blob/75be212fba6d4a1c43fc98030fc5e56edcdf176a/src/sentry/eventstream/kafka/backend.py#L264-L272

The task finishes normally, so its Retry(on=(Exception,), ...) (nodestore.py#L57-L62) never applies. The Snuba replacer sets deleted = 1 only when it receives end_delete_groups (errors_replacer.py#L374-L439), so the rows stay until retention removes them. The merge, unmerge and delete-tag replacements go through the same _send (snuba.py#L286-L365). These files are unchanged on master (sentry 063a6cb, snuba df59725).

The ACL is only the simplest way to make the publish fail on demand, and I did not test other causes. A single try with the broker stopped instead did not reproduce it: the deletion task is dispatched through the same Kafka, so it waited and the delete completed once the broker was back.

The eventstream has a future-tracking producer behind tasks.producer.eventstream.rollout (default 0.0, getsentry/sentry#121671), and taskworker.skip.awaiting.futures defaults to true (getsentry/sentry#118462) (defaults.py#L4578-L4593). A fresh install uses both defaults. getsentry/sentry#129327 (open) re-raises exceptions in this task so that its retry applies, but _send catches publish errors, so none reaches the task.

A possible fix: let _send raise for these two messages and let the task re-raise it as RetryTask, as the TODO at nodestore.py#L188 asks, so that the existing retry applies.

Event ID

No response

Lingua principale
Shell
Stelle
9.7k
Fork
2k
Merge medio
3g 2h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/self-hosted

Tutte le issue di getsentry/self-hosted

Issue simili

Altre issue su Shell/Bash

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.