1
#include "source/common/quic/quic_stats_gatherer.h"
2

            
3
#include <cstdint>
4

            
5
#include "envoy/formatter/http_formatter_context.h"
6

            
7
namespace Envoy {
8
namespace Quic {
9

            
10
void QuicStatsGatherer::OnPacketAcked(int acked_bytes,
11
79469
                                      quic::QuicTime::Delta /* delta_largest_observed */) {
12
79469
  bytes_outstanding_ -= acked_bytes;
13
79469
  if (bytes_outstanding_ == 0 && fin_sent_ && !logging_done_) {
14
2240
    if (time_source_ != nullptr) {
15
2240
      last_downstream_ack_timestamp_ = time_source_->monotonicTime();
16
2240
    }
17
2240
    maybeDoDeferredLog();
18
2240
  }
19
79469
}
20

            
21
93
void QuicStatsGatherer::OnPacketRetransmitted(int retransmitted_bytes) {
22
93
  retransmitted_packets_++;
23
93
  retransmitted_bytes_ += retransmitted_bytes;
24
93
}
25

            
26
4779
void QuicStatsGatherer::maybeDoDeferredLog(bool record_ack_timing) {
27
4779
  if (!fix_defer_logging_miss_for_half_closed_stream_) {
28
    logging_done_ = true;
29
  }
30
4779
  if (stream_info_ == nullptr) {
31
3272
    return;
32
3272
  }
33
1507
  if (fix_defer_logging_miss_for_half_closed_stream_) {
34
1507
    logging_done_ = true;
35
1507
  }
36
1507
  if (time_source_ != nullptr && record_ack_timing) {
37
1472
    stream_info_->downstreamTiming().onLastDownstreamAckReceived(*time_source_);
38
1474
  } else if (fix_defer_logging_miss_for_half_closed_stream_ &&
39
35
             last_downstream_ack_timestamp_.has_value()) {
40
2
    stream_info_->downstreamTiming().last_downstream_ack_received_ = last_downstream_ack_timestamp_;
41
2
  }
42
1507
  stream_info_->addBytesRetransmitted(retransmitted_bytes_);
43
1507
  stream_info_->addPacketsRetransmitted(retransmitted_packets_);
44

            
45
1507
  const Formatter::Context log_context{request_header_map_.get(),
46
1507
                                       response_header_map_.get(),
47
1507
                                       response_trailer_map_.get(),
48
1507
                                       {},
49
1507
                                       AccessLog::AccessLogType::DownstreamEnd};
50

            
51
1507
  for (const AccessLog::InstanceSharedPtr& log_handler : access_log_handlers_) {
52
1507
    log_handler->log(log_context, *stream_info_);
53
1507
  }
54
1507
}
55

            
56
} // namespace Quic
57
} // namespace Envoy