-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
quic: add QUIC downstream connection close error stats. #16584
Changes from 16 commits
b7b52e1
a704f7d
e77ca28
1b9275b
a47dc19
c4394c5
71f28c3
a71c23c
79e200b
8957117
5c83f5f
6cd0d83
4fe3fc5
ac867ce
d009105
832b098
8b7047a
0cc03f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "common/quic/quic_stat_names.h" | ||
|
||
namespace Envoy { | ||
namespace Quic { | ||
|
||
// TODO(renjietang): Currently these stats are only available in downstream. Wire it up to upstream | ||
// QUIC also. | ||
QuicStatNames::QuicStatNames(Stats::SymbolTable& symbol_table) | ||
: stat_name_pool_(symbol_table), symbol_table_(symbol_table), | ||
http3_prefix_(stat_name_pool_.add("http3")), downstream_(stat_name_pool_.add("downstream")), | ||
upstream_(stat_name_pool_.add("upstream")), from_self_(stat_name_pool_.add("tx")), | ||
from_peer_(stat_name_pool_.add("rx")) { | ||
// Preallocate most used counters | ||
// Most popular in client initiated connection close. | ||
connectionCloseStatName(quic::QUIC_NETWORK_IDLE_TIMEOUT); | ||
RenjieTang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Most popular in server initiated connection close. | ||
connectionCloseStatName(quic::QUIC_SILENT_IDLE_TIMEOUT); | ||
} | ||
|
||
void QuicStatNames::incCounter(Stats::Scope& scope, const Stats::StatNameVec& names) { | ||
Stats::SymbolTable::StoragePtr stat_name_storage = symbol_table_.join(names); | ||
RenjieTang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
scope.counterFromStatName(Stats::StatName(stat_name_storage.get())).inc(); | ||
} | ||
|
||
void QuicStatNames::chargeQuicConnectionCloseStats(Stats::Scope& scope, | ||
quic::QuicErrorCode error_code, | ||
quic::ConnectionCloseSource source, | ||
bool is_upstream) { | ||
ASSERT(&symbol_table_ == &scope.symbolTable()); | ||
|
||
if (error_code >= quic::QUIC_LAST_ERROR) { | ||
ENVOY_LOG(warn, fmt::format("Error code {} is out of range of QuicErrorCodes.", error_code)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test case for this? Also, I think warning here can log spam. I would recommend making this debug level and potentially also adding a stat for unknown error code or something like that. Thank you. /wait There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
return; | ||
} | ||
|
||
const Stats::StatName connection_close = connectionCloseStatName(error_code); | ||
incCounter(scope, {http3_prefix_, is_upstream ? upstream_ : downstream_, | ||
source == quic::ConnectionCloseSource::FROM_SELF ? from_self_ : from_peer_, | ||
connection_close}); | ||
} | ||
|
||
Stats::StatName QuicStatNames::connectionCloseStatName(quic::QuicErrorCode error_code) { | ||
return Stats::StatName( | ||
connection_error_stat_names_.get(error_code, [this, error_code]() -> const uint8_t* { | ||
return stat_name_pool_.addReturningStorage( | ||
absl::StrCat("quic_connection_close_error_code_", QuicErrorCodeToString(error_code))); | ||
})); | ||
} | ||
|
||
} // namespace Quic | ||
} // namespace Envoy |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "envoy/stats/scope.h" | ||
|
||
#include "common/common/thread.h" | ||
#include "common/stats/symbol_table_impl.h" | ||
|
||
#include "quiche/quic/core/quic_error_codes.h" | ||
#include "quiche/quic/core/quic_types.h" | ||
|
||
namespace Envoy { | ||
namespace Quic { | ||
|
||
class QuicStatNames { | ||
public: | ||
// This class holds lazily symbolized stat names and is responsible for charging them. | ||
explicit QuicStatNames(Stats::SymbolTable& symbol_table); | ||
|
||
void chargeQuicConnectionCloseStats(Stats::Scope& scope, quic::QuicErrorCode error_code, | ||
quic::ConnectionCloseSource source, bool is_upstream); | ||
|
||
private: | ||
// Find the actual counter in |scope| and increment it. | ||
// An example counter name: "http3.downstream.tx.quic_connection_close_error_code_QUIC_NO_ERROR". | ||
void incCounter(Stats::Scope& scope, const Stats::StatNameVec& names); | ||
|
||
Stats::StatName connectionCloseStatName(quic::QuicErrorCode error_code); | ||
|
||
Stats::StatNamePool stat_name_pool_; | ||
Stats::SymbolTable& symbol_table_; | ||
const Stats::StatName http3_prefix_; | ||
const Stats::StatName downstream_; | ||
const Stats::StatName upstream_; | ||
alyssawilk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const Stats::StatName from_self_; | ||
const Stats::StatName from_peer_; | ||
Thread::AtomicPtrArray<const uint8_t, quic::QUIC_LAST_ERROR, | ||
Thread::AtomicPtrAllocMode::DoNotDelete> | ||
connection_error_stat_names_; | ||
}; | ||
|
||
} // namespace Quic | ||
} // namespace Envoy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a quick read through it's not clear to me that this won't create an unbounded number of stats controlled by downstream (for exampled if the name somehow has the code number in it and the client controls the codes). This is probably not the case, but can you add more comments about why this is safe for use with uncontrolled peers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point!
I initially had an assertion in QuicStatNames::connectionCloseStatName() to make sure we don't create unlimited amount of stats.
But after some investigation, I found that if the connection close is initiated from peers, the error_code is parsed from the wire and no enum range checking is done. So an assertion here is too strong and malicious clients might be able to attack Envoy by sending out-of-range error codes.
Instead, I now added a check in QuicStatNames::chargeQuicConnectionCloseStats() to ignore out-of-range error_codes and log a warning.
I will follow up to dig deeper into the quiche code and see if bad error code handling can be done earlier.