Skip to content

stats: add an adapter sink that forwards to Envoy stats sinks - #1626

Open
bpalermo wants to merge 1 commit into
envoyproxy:mainfrom
bpalermo:up/envoy-sink-adapter
Open

bpalermo wants to merge 1 commit into
envoyproxy:mainfrom
bpalermo:up/envoy-sink-adapter

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Description

Adds nighthawk.envoy_stats_sink_adapter, a Nighthawk stats sink plugin that forwards to a stats sink implemented as an Envoy extension, such as envoy.stat_sinks.statsd or envoy.stat_sinks.dog_statsd.

What is new:

  • The plugin (source/stats_sink/) and its config proto (api/stats_sink/), which nests an ordinary Envoy StatsSink config.
  • A createStatsSink(config, context) overload on NighthawkStatsSinkFactory. Envoy's sink factories need the sink configuration and a server factory context, and the existing method receives neither.

What stays the same:

  • statistic_impl.cc and statistic_test.cc are not touched.
  • The new overload's default implementation calls the existing method, so existing stats sink plugins behave as before. process_test, which runs a Nighthawk sink through ProcessImpl, passes unchanged.

The adapter forwards flushes unchanged. Nighthawk records latency samples in nanoseconds with no unit declared; the adapter forwards them as microseconds with that unit, named cluster.<worker>.<statistic>, so sinks that scale by unit report them correctly.

This PR is related to #1616 and #1617, which it replaces.

Notes for Reviewers

  • Tests: //test/stats_sink:envoy_stats_sink_adapter_test (unit, with a fake Envoy sink) and test/integration/test_stats_sinks.py, which runs Envoy's real statsd and DogStatsD sinks through the adapter and checks the datagrams received on a UDP socket.
  • Limitation: Nighthawk's latency statistics are not in the flush snapshot, so Envoy sinks that only read histograms from the snapshot (OpenTelemetry, metrics service) export counters and gauges but not latencies. Documented in docs/root/statistics.md.

Adds the nighthawk.envoy_stats_sink_adapter stats sink plugin. It is
configured with an Envoy stats sink configuration, creates that sink through
Envoy's own factory, and forwards flushes and histogram samples to it, so
Envoy's sinks can be used without a Nighthawk implementation of each.

Samples of Nighthawk's latency statistics are recorded in nanoseconds with no
unit declared. The adapter presents each as a Microseconds histogram named
after its worker and converts the sample, so sinks that scale by unit report
it correctly.

Envoy's sink factories need the sink configuration and a server factory
context, so NighthawkStatsSinkFactory gains a createStatsSink() overload that
receives both. Its default implementation calls the existing method; existing
stats sink plugins and the statistics code are unchanged.

Signed-off-by: Bruno Palermo <b@palermo.dev>
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