-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Network::Connection: Add L4 crash dumping support #14509
Changes from 2 commits
1bd6d98
60dc8a6
63bbc55
056c07a
a85e8c2
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,28 @@ | ||
#pragma once | ||
|
||
#include <ostream> | ||
|
||
#include "envoy/common/pure.h" | ||
|
||
namespace Envoy { | ||
|
||
/* | ||
* Interface for classes that can dump their state. | ||
* This is similar to ScopeTrackedObject interface, but cannot be registered | ||
* for tracking work. | ||
*/ | ||
class Dumpable { | ||
public: | ||
virtual ~Dumpable() = default; | ||
/** | ||
* Dump debug state of the object in question to the provided ostream. | ||
* | ||
* This is called on Envoy fatal errors, so should do minimal memory allocation. | ||
* | ||
* @param os the ostream to output to. | ||
* @param indent_level how far to indent, for pretty-printed classes and subclasses. | ||
*/ | ||
virtual void dumpState(std::ostream& os, int indent_level = 0) const PURE; | ||
}; | ||
|
||
} // namespace Envoy |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,10 @@ | |
#include "envoy/network/socket.h" | ||
|
||
#include "common/common/assert.h" | ||
#include "common/common/dump_state_utils.h" | ||
#include "common/common/empty_string.h" | ||
#include "common/common/enum_to_int.h" | ||
#include "common/common/scope_tracker.h" | ||
#include "common/network/address_impl.h" | ||
#include "common/network/listen_socket_impl.h" | ||
#include "common/network/raw_buffer_socket.h" | ||
|
@@ -530,6 +532,7 @@ void ConnectionImpl::onWriteBufferHighWatermark() { | |
} | ||
|
||
void ConnectionImpl::onFileEvent(uint32_t events) { | ||
ScopeTrackerScopeState scope(this, this->dispatcher_); | ||
ENVOY_CONN_LOG(trace, "socket event: {}", *this, events); | ||
|
||
if (immediate_error_event_ != ConnectionEvent::Connected) { | ||
|
@@ -753,6 +756,27 @@ void ConnectionImpl::flushWriteBuffer() { | |
} | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, Connection::State connection_state) { | ||
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. Implementing this operator in the middle of this cc file is a bit odd. Consider moving to an anonymous namespace at the top of the file or to the library that defines the Connection::State enum class. 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. Moved it to anonymous namespace at the top of this file. Done. |
||
switch (connection_state) { | ||
case Connection::State::Open: | ||
return os << "Open"; | ||
case Connection::State::Closing: | ||
return os << "Closing"; | ||
case Connection::State::Closed: | ||
return os << "Closed"; | ||
} | ||
return os; | ||
} | ||
|
||
// ScopeTrackedObject | ||
KBaichoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void ConnectionImpl::dumpState(std::ostream& os, int indent_level) const { | ||
const char* spaces = spacesForLevel(indent_level); | ||
os << spaces << "ConnectionImpl " << this << DUMP_MEMBER(connecting_) << DUMP_MEMBER(bind_error_) | ||
<< DUMP_MEMBER(state()) << DUMP_MEMBER(read_buffer_limit_) << "\n"; | ||
|
||
DUMP_DETAILS(socket_); | ||
} | ||
|
||
ServerConnectionImpl::ServerConnectionImpl(Event::Dispatcher& dispatcher, | ||
ConnectionSocketPtr&& socket, | ||
TransportSocketPtr&& transport_socket, | ||
|
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.
class ScopeTrackedObject : public Dumpable {}
But are the two interfaces really needed? Why is it important to distinguish between objects that can be registered and ones that simply have a dump method?
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.
The intent is to decrease cognitive load and have it be more explicit than implicit i.e. why is
foo
atrackedobject
that gets registered, butbar
atrackedobject
that doesn't.If we enforce this via the type system, the intent is a bit more clear instead of "maybe they forgot to register
bar
to get dumped".Thoughts?
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.
Is not being able to register the object useful? Having 2 interfaces that are so similar adds to cognitive load.
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.
Yeah I would tend to agree that the two interfaces do not feel that useful to me, but I don't feel strongly about it. At minimum I would derive from the other class as @antoniovicente suggests.
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.
Fair point, will just go with
ScopeTrackedObject
to keep it simple