http2: add keepalive observer hook#44299
Open
roll-no-21 wants to merge 1 commit intoenvoyproxy:mainfrom
Open
Conversation
Expose HTTP/2 keepalive send and ack events through a small observer interface so higher layers can react to codec keepalives without coupling reverse-tunnel logic into the core codec. Signed-off-by: Krishna Sharma <krishnagpl2001@gmail.com>
Contributor
Author
|
cc: @ivpr |
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.
Expose HTTP/2 keepalive send and ack events through a small observer interface so higher layers can react to codec keepalives without coupling reverse-tunnel logic into the core codec.
Commit Message: http2: add keepalive observer hook
Additional Description:
Today, higher-level extensions (e.g. reverse tunnel lifecycle logging) that
need to react to HTTP/2 keepalive events must either parse raw HTTP/2 frames
from network filter buffers or embed extension-specific logic directly in the
codec. Both approaches are undesirable — the first is fragile and works against
Envoy's layered architecture, and the second couples domain logic into core
protocol code.
This PR introduces a lightweight
KeepaliveObserverinterface that the HTTP/2codec queries via connection FilterState on keepalive ping send and ack events.
If no observer is registered, the codec does nothing (null-check only). If an
observer is present, it receives callbacks with the connection's
StreamInfoand the PING opaque data.
New interface (
keepalive_observer.h)KeepaliveObserverextendsStreamInfo::FilterState::Objectand defines:onKeepalivePingSent(StreamInfo::StreamInfo&, uint64_t opaque_data)— calledimmediately after the codec submits an HTTP/2 PING frame via the adapter.
onKeepalivePingAck(StreamInfo::StreamInfo&, uint64_t opaque_data)— calledwhen the codec receives a PING ACK frame from the peer.
pendingKeepalivePingId()— returns the opaque data of the outstanding PING,if any, allowing the observer to correlate send/ack pairs.
The observer is looked up from FilterState under the key
envoy.http2.keepalive_observer.Codec changes (
codec_impl.cc)sendKeepalive(): afteradapter_->SubmitPing(), checks for an observerand calls
onKeepalivePingSent()(~3 lines added).onPing()(ACK path): after logging the PING ACK, checks for an observerand calls
onKeepalivePingAck()(~3 lines added).keepaliveObserver()retrieves the observer fromconnection_.streamInfo().filterState()(~6 lines).Usage pattern
An upstream network filter sets a
KeepaliveObserverimplementation inthe connection's FilterState during
onNewConnection(). The codec picks itup automatically on the next keepalive cycle. Example:
filter_state.setData( kKeepaliveObserverFilterStateKey, std::make_shared<MyObserverImpl>(), StreamInfo::FilterState::StateType::ReadOnly, StreamInfo::FilterState::LifeSpan::Connection); No observer registered → zero overhead beyond a null-check per ping event. Risk Level: Low — opt-in via FilterState; no behavioral change when no observer is registered. The null-check in the keepalive hot path is negligible. Testing: New ConnectionKeepaliveObserver test in codec_impl_test.cc validates that onKeepalivePingSent and onKeepalivePingAck are called in correct sequence with proper timer interactions using a MockKeepaliveObserver. Docs Changes: N/A Release Notes: N/A Platform Specific Features: N/A