-
Notifications
You must be signed in to change notification settings - Fork 24
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
Count the number of throttled log message and print it. #1520
Conversation
5e68bb8
to
fb917d9
Compare
static std::chrono::steady_clock::time_point _clog_lastlog_##__LINE__; \ | ||
static unsigned long _clog_throttle_times_##__LINE__ = 0; \ | ||
std::chrono::duration _clog_elapsed_##__LINE__ = std::chrono::steady_clock::now() - _clog_lastlog_##__LINE__; \ | ||
if (collector::logging::CheckLogLevel(collector::logging::LogLevel::lvl) && (cond) && _clog_elapsed_##__LINE__ < interval) { \ |
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.
I have not been able to refactor this to use nested ifs. I think this is okay.
I will approve after merge conflicts are fixed. |
This is likely less efficient, but prevents warnings about ambiguous dangling else statement.
84d4c5a
to
dd35730
Compare
@@ -56,10 +56,15 @@ const size_t LevelPaddingWidth = 7; | |||
|
|||
class LogMessage { | |||
public: | |||
LogMessage(const char* file, int line, bool throttled, LogLevel level) | |||
: file_(file), line_(line), level_(level), throttled_(throttled) { | |||
LogMessage(const char* file, int line, LogLevel level, unsigned long* throttled_times = 0) |
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.
[nit] using nullptr
rather than 0
would make this a little clearer
LogMessage(const char* file, int line, LogLevel level, unsigned long* throttled_times = 0) | |
LogMessage(const char* file, int line, LogLevel level, unsigned long* throttled_times = nullptr) |
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.
+1 on this one, we are terrible at using nullptr
, we should try to do better.
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.
LGTM!
@@ -56,10 +56,15 @@ const size_t LevelPaddingWidth = 7; | |||
|
|||
class LogMessage { | |||
public: | |||
LogMessage(const char* file, int line, bool throttled, LogLevel level) | |||
: file_(file), line_(line), level_(level), throttled_(throttled) { | |||
LogMessage(const char* file, int line, LogLevel level, unsigned long* throttled_times = 0) |
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.
+1 on this one, we are terrible at using nullptr
, we should try to do better.
(std::chrono::steady_clock::now() - _clog_lastlog_##__LINE__ >= interval)) \ | ||
_clog_lastlog_##__LINE__ = std::chrono::steady_clock::now(), \ | ||
collector::logging::LogMessage(__FILE__, __LINE__, true, collector::logging::LogLevel::lvl) | ||
#define CLOG_THROTTLED_IF(cond, lvl, interval) \ |
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.
I'm gonna be honest, I don't like macros. I think most of them are directly written by the devil himself, waiting for us to make a silly mistake in an expansion, triggering undefined behavior and bringing down entire programs in an instant.
This particular case was already pretty bad, but with the added changes it becomes borderline unreadable, I had to put a TON of effort into just trying to understand what was going on in it and, I have to assume, if we ever need to do any further changes or (God forbid) do a bug fix, it will take way too much effort to do so.
That said, I am also in favor of the added feature, I think counting the amount of times a log has been throttled adds value (throttling twice is not as bad as throttling 2000 times). Maybe we can come up with a better solution, there might be a way we can rewrite at least part of the macro to be a concrete method and pass things like __LINE__
as an argument to it. Or maybe we have to rethink how our entire logging implementation works, the implementation itself is really clever, using the destructor of the class to do the actual print out, but that also means every time we log we are creating and destroying an object, maybe we want to change it to have a single instance of a logger object and this sort of throttling can be done with a map of sorts, grouping line number to the amount of triggers that have occurred.
I digress, I will not block the change from being merged because I like the idea behind it, but I cannot in good faith approve the PR because of the reasons stated before.
Description
We have recently increased significantly the delay for some throttled messages.
In order to get a better idea of the amount of messages, this PR adds a counter.
Checklist
inspected CI test results for throttled messages:
Testing
With a container generating 100 zombie processes, the collector contains: