Line data Source code
1 : #include "source/common/quic/quic_stat_names.h" 2 : 3 : namespace Envoy { 4 : namespace Quic { 5 : 6 : #ifdef ENVOY_ENABLE_QUIC 7 : 8 : // TODO(renjietang): Currently these stats are only available in downstream. Wire it up to upstream 9 : // QUIC also. 10 : QuicStatNames::QuicStatNames(Stats::SymbolTable& symbol_table) 11 : : stat_name_pool_(symbol_table), symbol_table_(symbol_table), 12 : http3_prefix_(stat_name_pool_.add("http3")), downstream_(stat_name_pool_.add("downstream")), 13 : upstream_(stat_name_pool_.add("upstream")), from_self_(stat_name_pool_.add("tx")), 14 778 : from_peer_(stat_name_pool_.add("rx")) { 15 : // Preallocate most used counters 16 : // Most popular in client initiated connection close. 17 778 : connectionCloseStatName(quic::QUIC_NETWORK_IDLE_TIMEOUT); 18 : // Most popular in server initiated connection close. 19 778 : connectionCloseStatName(quic::QUIC_SILENT_IDLE_TIMEOUT); 20 : // Most popular in client initiated stream reset. 21 778 : resetStreamErrorStatName(quic::QUIC_STREAM_CANCELLED); 22 : // Most popular in server initiated stream reset. 23 778 : resetStreamErrorStatName(quic::QUIC_STREAM_STREAM_CREATION_ERROR); 24 778 : } 25 : 26 239 : void QuicStatNames::incCounter(Stats::Scope& scope, const Stats::StatNameVec& names) { 27 239 : Stats::SymbolTable::StoragePtr stat_name_storage = symbol_table_.join(names); 28 239 : scope.counterFromStatName(Stats::StatName(stat_name_storage.get())).inc(); 29 239 : } 30 : 31 : void QuicStatNames::chargeQuicConnectionCloseStats(Stats::Scope& scope, 32 : quic::QuicErrorCode error_code, 33 : quic::ConnectionCloseSource source, 34 0 : bool is_upstream) { 35 0 : ASSERT(&symbol_table_ == &scope.symbolTable()); 36 : 37 0 : if (error_code > quic::QUIC_LAST_ERROR) { 38 0 : error_code = quic::QUIC_LAST_ERROR; 39 0 : } 40 : 41 0 : const Stats::StatName connection_close = connectionCloseStatName(error_code); 42 0 : incCounter(scope, {http3_prefix_, (is_upstream ? upstream_ : downstream_), 43 0 : (source == quic::ConnectionCloseSource::FROM_SELF ? from_self_ : from_peer_), 44 0 : connection_close}); 45 0 : } 46 : 47 : void QuicStatNames::chargeQuicResetStreamErrorStats(Stats::Scope& scope, 48 : quic::QuicResetStreamError error_code, 49 239 : bool from_self, bool is_upstream) { 50 239 : ASSERT(&symbol_table_ == &scope.symbolTable()); 51 : 52 239 : auto internal_code = error_code.internal_code(); 53 239 : if (internal_code > quic::QUIC_STREAM_LAST_ERROR) { 54 0 : internal_code = quic::QUIC_STREAM_LAST_ERROR; 55 0 : } 56 : 57 239 : const Stats::StatName stream_error = resetStreamErrorStatName(internal_code); 58 239 : incCounter(scope, {http3_prefix_, (is_upstream ? upstream_ : downstream_), 59 239 : (from_self ? from_self_ : from_peer_), stream_error}); 60 239 : } 61 : 62 1556 : Stats::StatName QuicStatNames::connectionCloseStatName(quic::QuicErrorCode error_code) { 63 1556 : ASSERT(error_code <= quic::QUIC_LAST_ERROR); 64 : 65 1556 : return Stats::StatName( 66 1556 : connection_error_stat_names_.get(error_code, [this, error_code]() -> const uint8_t* { 67 1556 : return stat_name_pool_.addReturningStorage( 68 1556 : absl::StrCat("quic_connection_close_error_code_", QuicErrorCodeToString(error_code))); 69 1556 : })); 70 1556 : } 71 : 72 1795 : Stats::StatName QuicStatNames::resetStreamErrorStatName(quic::QuicRstStreamErrorCode error_code) { 73 1795 : ASSERT(error_code <= quic::QUIC_STREAM_LAST_ERROR); 74 : 75 1795 : return Stats::StatName( 76 1795 : reset_stream_error_stat_names_.get(error_code, [this, error_code]() -> const uint8_t* { 77 1561 : return stat_name_pool_.addReturningStorage(absl::StrCat( 78 1561 : "quic_reset_stream_error_code_", QuicRstStreamErrorCodeToString(error_code))); 79 1561 : })); 80 1795 : } 81 : 82 : #else 83 : QuicStatNames::QuicStatNames(Stats::SymbolTable& /*symbol_table*/) {} 84 : 85 : #endif 86 : 87 : } // namespace Quic 88 : } // namespace Envoy