feat: add HTTP and NATS output sinks#18
Merged
Merged
Conversation
Extend Helr's output beyond stdout/file with two new EventSink implementations, selectable via URL scheme on the existing --output flag: - HttpSink: POST batched NDJSON to an HTTP endpoint (reqwest). Batches by count or timeout, retries on 5xx/timeout with exponential backoff. Configurable via global.output.http (batch_size, headers, retries). - NatsSink: publish each NDJSON line to a NATS subject via core publish (async-nats, behind --features nats). Subject parsed from URL or overridden via global.output.nats.subject. Both use a tokio channel + spawned async worker to bridge the sync EventSink trait, and slot into the existing BackpressureSink wrapper without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HttpSink-- POST batched NDJSON lines to a remote HTTP endpoint using reqwest. Lines are batched by count (batch_size, default 100) or time (batch_timeout_ms, default 500ms) and sent as a single NDJSON body. Retries on 5xx/timeout with exponential backoff (max_retries, default 3). Custom headers configurable in YAML (e.g.Authorization).NatsSink-- publish each NDJSON line to a NATS subject via core publish (fire-and-forget) usingasync-nats. Behind thenatsfeature flag to keep the dependency optional. Subject parsed from the URL path (nats://host:port/subject) or overridden viaglobal.output.nats.subject.--outputCLI flag:--output http://...for HTTP,--output nats://...for NATS, plain paths remain file output, absent remains stdout.EventSinktrait using a tokio channel + spawned async worker, and slot into the existingBackpressureSinkwrapper without changes.global.outputwithhttpandnatssub-blocks for optional tuning.Files changed
Cargo.tomlasync-natsoptional dep,natsfeature flagsrc/config/global.rsOutputConfig,HttpOutputConfig,NatsOutputConfigsrc/output.rsHttpSink,NatsSink,parse_nats_url(), testssrc/main.rsREADME.mdTest plan
parse_nats_url(4 cases: with subject, nested subject, no subject, trailing slash)HttpSinkbasic POST (wiremock mock server, verifies batch delivery)HttpSinkretry on 503 (wiremock, verifies 3 attempts before success)cargo clippyclean (default features and--features nats)cargo testpasses (all 139 tests)