stats: add UDP statsd / DogStatsD stats sinks and --stats-sink-tag - #1600
Open
bpalermo wants to merge 1 commit into
Open
stats: add UDP statsd / DogStatsD stats sinks and --stats-sink-tag#1600bpalermo wants to merge 1 commit into
bpalermo wants to merge 1 commit into
Conversation
bpalermo
force-pushed
the
up/statsd-sink
branch
from
September 7, 2026 12:41
4aef084 to
2ab18af
Compare
--stats-sinks has been documented (with a statsd example) but no NighthawkStatsSinkFactory implementation was ever linked into the binaries, so any --stats-sinks value aborted at startup with "Didn't find a registered implementation". This adds a sink and registers it under Envoy's names so the documented configs work as written: - envoy.stat_sinks.statsd (envoy.config.metrics.v3.StatsdSink, UDP address form only) and envoy.stat_sinks.dog_statsd (envoy.config.metrics.v3.DogStatsdSink: tags, optional max_bytes_per_datagram batching). - Counters are sent as deltas (|c) on every flush, gauges as values (|g). Nighthawk's sinkable latency statistics record nanoseconds, so each sample is converted and sent as a millisecond timing with microsecond precision (|ms); Envoy histograms are converted per unit. - Per-worker metrics are named worker.<n>.<rest> (both cluster.<n>. and worker.<n>. store scopes), or carry a worker:<n> tag with DogStatsD. - One UDP socket is shared by all threads; with batching, latency samples are packed per recording thread and sent when the batch fills, on the next flush and at shutdown. Envoy's thread-local slots are not usable here because Nighthawk's flush worker thread registers after sinks are created. - New --stats-sink-tag key:value (repeatable, CommandLineOptions stats_sink_tags) adds tags to every message of tag-capable sinks. NighthawkStatsSinkFactory::createStatsSink now receives the translated typed config, a ThreadLocal::SlotAllocator and the configured tags. Signed-off-by: Bruno Palermo <[email protected]>
bpalermo
force-pushed
the
up/statsd-sink
branch
from
September 7, 2026 13:21
2ab18af to
4d6b364
Compare
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.
Description
This PR is related to #1607
--stats-sinksis documented in the README with a statsd example, but noNighthawkStatsSinkFactoryimplementation is linked into the binaries, so any--stats-sinksvalue aborts at startup withDidn't find a registered implementation for 'envoy.stat_sinks.statsd'. This adds a UDP statsd sink and registers it under Envoy's sink names so the documented configs work as written.Behavior:
envoy.stat_sinks.statsd(envoy.config.metrics.v3.StatsdSink, UDPaddressform, IP literal or host name resolved at startup;tcp_cluster_nameis rejected) andenvoy.stat_sinks.dog_statsd(envoy.config.metrics.v3.DogStatsdSink: DogStatsD tags, optionalmax_bytes_per_datagrambatching).|c) on every flush, gauges as values (|g). Nighthawk's sinkable latency statistics record nanoseconds, so every sample is sent as a millisecond timing with microsecond precision (|ms); Envoy histograms are converted per their unit.worker.<n>.<rest>(covering both thecluster.<n>.andworker.<n>.store scopes), or carry aworker:<n>tag with DogStatsD.--stats-sink-tag key:value(repeatable;CommandLineOptions.stats_sink_tags) adds tags to every message of tag-capable sinks, e.g. to identify a run or pod.nighthawk(override withprefix).Notes for Reviewers
UdpStatsdSinkwas not reusable as-is: it keeps a thread-local writer, and Nighthawk's flush worker thread registers with TLS after sinks are created, which trips Envoy'scurrentThreadRegisteredWorkerassert; it also forwards histogram values verbatim as|ms, wrong for Nighthawk's nanosecond statistics. The sink here shares one UDP socket across threads and batches latency samples per recording thread (sent when the batch fills, on the next flush, and at shutdown).NighthawkStatsSinkFactory::createStatsSinknow receives the translated typed config (it previously had no access to it), aThreadLocal::SlotAllocatorand the configured tags;include/is documented as not a public API, and the only in-tree implementation (the test fake) is updated.//test:statsd_sink_test(naming with/without tags, ns to ms conversion, counter deltas and gauges, batching and end-of-run flush against a real loopback UDP receiver, factory registration, host name resolution and config validation);test/integration/test_stats_sinks.py(fullnighthawk_clientruns with each sink, capturing the datagrams);//test:options_test,//test:process_test,//test:factories_test. README usage regenerated;docs/root/statistics.mdand version history updated.