Line data Source code
1 : #pragma once 2 : 3 : #include <cstdint> 4 : 5 : #include "envoy/access_log/access_log.h" 6 : #include "envoy/http/codec.h" 7 : #include "envoy/http/header_map.h" 8 : #include "envoy/stream_info/stream_info.h" 9 : 10 : #include "quiche/quic/core/quic_ack_listener_interface.h" 11 : 12 : namespace Envoy { 13 : namespace Quic { 14 : 15 : // Ack listener that stores access logging information and performs 16 : // logging after the final ack. 17 : class QuicStatsGatherer : public quic::QuicAckListenerInterface { 18 : public: 19 232 : explicit QuicStatsGatherer(Envoy::TimeSource* time_source) : time_source_(time_source) {} 20 : 21 : // QuicAckListenerInterface 22 : void OnPacketAcked(int acked_bytes, quic::QuicTime::Delta delta_largest_observed) override; 23 : void OnPacketRetransmitted(int retransmitted_bytes) override; 24 : 25 : // Add bytes sent for this stream, for internal tracking of bytes acked. 26 0 : void addBytesSent(uint64_t bytes_sent, bool end_stream) { 27 0 : bytes_outstanding_ += bytes_sent; 28 0 : fin_sent_ = end_stream; 29 0 : } 30 : // Log this stream using available stream info and access loggers. 31 : void maybeDoDeferredLog(bool record_ack_timing = true); 32 : // Set list of pointers to access loggers. 33 232 : void setAccessLogHandlers(std::list<AccessLog::InstanceSharedPtr> handlers) { 34 232 : access_log_handlers_ = handlers; 35 232 : } 36 : // Set headers, trailers, and stream info used for deferred logging. 37 : void 38 : setDeferredLoggingHeadersAndTrailers(Http::RequestHeaderMapConstSharedPtr request_header_map, 39 : Http::ResponseHeaderMapConstSharedPtr response_header_map, 40 : Http::ResponseTrailerMapConstSharedPtr response_trailer_map, 41 0 : std::unique_ptr<StreamInfo::StreamInfo> stream_info) { 42 0 : request_header_map_ = request_header_map; 43 0 : response_header_map_ = response_header_map; 44 0 : response_trailer_map_ = response_trailer_map; 45 0 : stream_info_ = std::move(stream_info); 46 0 : } 47 232 : bool loggingDone() { return logging_done_; } 48 0 : uint64_t bytesOutstanding() { return bytes_outstanding_; } 49 : 50 : private: 51 : uint64_t bytes_outstanding_ = 0; 52 : bool fin_sent_ = false; 53 : std::list<AccessLog::InstanceSharedPtr> access_log_handlers_{}; 54 : Http::RequestHeaderMapConstSharedPtr request_header_map_; 55 : Http::ResponseHeaderMapConstSharedPtr response_header_map_; 56 : Http::ResponseTrailerMapConstSharedPtr response_trailer_map_; 57 : // nullptr indicates that deferred logging should be skipped. 58 : std::unique_ptr<StreamInfo::StreamInfo> stream_info_; 59 : Envoy::TimeSource* time_source_ = nullptr; 60 : bool logging_done_ = false; 61 : uint64_t retransmitted_packets_ = 0; 62 : uint64_t retransmitted_bytes_ = 0; 63 : }; 64 : 65 : } // namespace Quic 66 : } // namespace Envoy