Skip to content

fix: real delivery for streams, webhook templates, email alerts, Pub/Sub health (#41) - #43

Merged
CodingAnarchy merged 4 commits into
masterfrom
fix/real-delivery
Oct 8, 2026
Merged

CodingAnarchy merged 4 commits into
masterfrom
fix/real-delivery

Conversation

@CodingAnarchy

Copy link
Copy Markdown
Owner

Part of #41: the library items. The CLI and web dashboard items are handled separately.

Each of these features reported success but did nothing. They now either deliver, or fail visibly.

Done

  • Streams never sent anything (src/streaming.rs)
    • Batches now go through the stream's StreamProcessor::send_batch.
    • Failed events are retried per StreamRetryPolicy. An event also counts as failed when send_batch errors or returns no result for it.
      • max_attempts is the total number of attempts.
      • Backoff is initial * multiplier^(n-1), capped at max_delay_secs. Optional jitter draws from [d/2, d].
      • Only the events that failed are resent.
    • Retries stop when shutdown(grace) begins: a send already in progress finishes, the backoff sleep is interrupted, and the remaining events are counted as failed with a "shut down" last_error.
    • Stats are built from the per-event results: successes, failures, success_rate, average delivery time, timestamps, and the new last_error.
    • Processors are stored as Arc, so the map lock isn't held during network I/O.
    • Also fixed: Kinesis and Pub/Sub re-encoded every event as JSON and ignored the configured serialization format.
  • Webhook payload_template (src/webhooks.rs)
    • Templates are JSON with {{event.*}} placeholders, handled by the new public PayloadTemplate.
    • A string that is a single placeholder keeps the value's JSON type. Placeholders embedded in text are interpolated.
    • Rendering works on the parsed JSON tree, so event data can't inject JSON.
    • Templates are validated in add_webhook, in update_webhook (before the old webhook is removed) and in HammerworkConfig::from_file. Unknown paths, invalid JSON, an unterminated {{ and placeholders in object keys are rejected with HammerworkError::Config.
  • Email alerts (src/alerting.rs)
    • SMTP delivery uses lettre with tokio and rustls, behind alerting.
    • AlertTarget::Email { recipient, smtp: Option<SmtpConfig> }. SmtpConfig has host, port, from, username, a password given as SecretSource::Environment/Static (redacted in Debug), TLS mode (StartTls is the default and is required; also Implicit and None) and a timeout.
    • A target with no SMTP settings is rejected by AlertingConfig::validate, AlertManager::try_new and HammerworkConfig::from_file.
    • Alert delivery failures are now returned as errors. Previously each failure was logged with warn! and the call returned Ok. The cooldown only starts once some target received the alert.
  • Pub/Sub health_check
    • Calls topic.exists(), bounded by health.check.timeout.ms.
    • Returns true if the topic exists; false if it's missing, Pub/Sub is unavailable, or the check times out; and an error for rejected requests such as PERMISSION_DENIED.

API and behaviour changes

  • AlertTarget::Email has a new smtp field, which is breaking for code that constructs or exhaustively matches the variant. AlertingConfig::email() is deprecated in favour of email_via_smtp().
  • StreamStats has a new last_error field, which is breaking for struct literals.
  • check_thresholds, check_queue_depth, check_worker_starvation and send_custom_alert now return Err when a target fails. The worker already logs that error.
  • HammerworkConfig::from_file rejects email targets without SMTP settings and invalid webhook templates.

New dependencies

  • lettre 0.11: optional, alerting feature. MSRV 1.85; rustls with the ring provider is selected explicitly.
  • gcloud-gax 1.4: optional, google-pubsub feature. It was already in the tree.
  • h2, http, bytes: dev-only, for a fake Pub/Sub gRPC endpoint. All were already in the lockfile.
  • cargo audit is clean.

Tests

  • Streaming, using the InMemoryProcessor, which now records what it received and can be scripted to fail:
    • events reach the processor
    • batch errors are retried, then reported as failures
    • a transient error recovers
    • a partial batch failure retries only the events that failed
    • a missing delivery result counts as a failure
    • retries stop on shutdown
    • backoff math
    • the burst test from fix(events): webhooks and streams no longer drop events #34 now asserts that all 100 events reached the processor
  • Pub/Sub health check: against a local fake gRPC server. Covers OK, NOT_FOUND, UNAVAILABLE, no answer (timeout) and PERMISSION_DENIED.
  • Webhooks: rendering and type preservation, interpolation, escaping and injection, invalid templates, add_webhook/update_webhook rejection, and an end-to-end delivery that sends the rendered body.
  • Alerting: against a local fake SMTP server. Covers a sent message with its MAIL, RCPT and Subject, AUTH PLAIN credentials, rejected and unreachable servers returning errors, required STARTTLS not falling back to plain text, a missing password environment variable, configuration validation, the TOML layout and secret redaction.
  • Config: from_file rejects undeliverable targets.

Verified locally

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --all-features --locked -D warnings
  • The CI feature matrix, plus postgres,alerting, postgres,kafka and postgres,google-pubsub
  • cargo test --workspace --all-features --lib
  • The Postgres and MySQL integration suites in CI style
  • Doctests
  • cargo +1.91.1 check --workspace --all-features --all-targets --locked
  • cargo audit

🤖 Generated with Claude Code

CodingAnarchy and others added 4 commits October 8, 2026 10:13
lettre 0.11 (no default features; builder, smtp-transport, tokio1-rustls-tls,
hostname) backs SMTP email alerts under the `alerting` feature. gcloud-gax
(already in the tree via gcloud-pubsub) is needed by the `google-pubsub`
health check for its retry settings and status codes. h2, http and bytes
are dev-dependencies for a fake Pub/Sub gRPC endpoint in tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StreamManager::process_event_batch recorded every batch as delivered
without calling the processor, so Kafka, Kinesis and Pub/Sub streams
dropped all events while reporting success.

Batches are now sent with StreamProcessor::send_batch. Failed events (or
events without a delivery result) are retried per StreamRetryPolicy with
capped exponential backoff and optional jitter; retries stop once
shutdown begins, including during the backoff sleep. Stats are updated
from the per-event results and gain `last_error`.

Also: Kinesis and Pub/Sub now send the stream's serialized bytes instead
of always re-encoding JSON, and the Pub/Sub health check fetches the
topic instead of returning true.

Part of #41.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Webhook payload_template was ignored. It is now a JSON template with
{{event.*}} placeholders, rendered on the parsed tree so event data
cannot inject JSON, and validated in add_webhook/update_webhook and
HammerworkConfig::from_file.

Email alert targets only logged. They now send through SMTP (lettre,
rustls) using per-target SmtpConfig; a target without SMTP settings is a
configuration error. Alert delivery failures are returned instead of
logged and swallowed, and the cooldown only starts once a target was
reached.

Part of #41.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CodingAnarchy
CodingAnarchy merged commit 5d7d93e into master Oct 8, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant