-
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
Add ENVOY_LOG_PERIODIC #12961
Add ENVOY_LOG_PERIODIC #12961
Conversation
Follow up to envoyproxy#12830 with another sparse log variant. The periodic version relies on a real world time source, which can be discussed separately here. Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
/assign htuch |
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, but quick check with @jmarantz on whether it would make sense to have a time singleton here for testing.
IMO I'd rather test with real-time here and not introduce singletons. |
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.
Thanks!
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
ENVOY_LOG(LEVEL, ##__VA_ARGS__); \ | ||
if (ENVOY_LOG_COMP_LEVEL(ENVOY_LOGGER(), LEVEL)) { \ | ||
static auto* countdown = new std::atomic<uint64_t>(); \ | ||
if (countdown->fetch_add(1) < N) { \ |
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 counter may eventually overflow. ;)
source/common/common/logger.h
Outdated
ENVOY_LOG(LEVEL, ##__VA_ARGS__); \ | ||
if (ENVOY_LOG_COMP_LEVEL(ENVOY_LOGGER(), LEVEL)) { \ | ||
static auto* count = new std::atomic<uint64_t>(); \ | ||
if (std::bitset<64>(1 + count->fetch_add(1)).count() == 1) { \ |
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.
How about this kind of thing:
auto bits = count->fetch_add(1);
if ( bits && !(bits & (bits-1)) )
The unsigned
type here is fine.
Any bitwise &&
of any power of 2 with a number less by 1 will give 0. No need to involve std::bitset
and we get rid of that magic number too.
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 went with std::bitset
because I think I remember it being compiled to something fast under the hood (__builtin_popcount?); but also - and this is probably subjective - I find it easier to grok. The +1 deserves a comment, e.g. // +1 because the first hit needs to be logged
, but this imho this also wouldn't hurt with the -1
(or maybe the whole expression) in the variant you propose, depending on who the audience is?
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.
Ok. Let's leave it be for now, no problemo. bitset.count()
is readable, true.
Yes, __builtin_popcount
for GCC and for LLVM it's a similar thing; which translates, depending on the platform, into about 2-3 cpu intructions, or into Kernighan’s algorithm (latter is slower than this little trick).
But you're right. To follow readibility guidelines i should've suggested a lambda at least here, sth like auto is_exactly_one_bit_set = [](const uint64_t bits) { return bits && !(bits & (bits-1)); };
.
I'm still trying to figure out how relaxed these atomic ops we could make. We probably can be fine with |
re: I'm still trying to figure out how relaxed these atomic ops we could make. Yeah, I had some similar thoughts there: #12830 (comment) |
Rgr. Pretty much exactly my thoughts. I won't be blocking you on this PR anymore, apologies. Let's get it going. I will read up on this and hopefully be able to contribute with more insight later on. |
Sure; super appreciate the feedback. If you want, we can discuss more on Slack too if you like, my handle is oschaaf. |
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
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.
approved, but keeping my eye on it ;)
source/common/common/logger.h
Outdated
if ((count->fetch_add(1) % N) == 0) { \ | ||
ENVOY_LOG(LEVEL, ##__VA_ARGS__); \ | ||
if (ENVOY_LOG_COMP_LEVEL(ENVOY_LOGGER(), LEVEL)) { \ | ||
static auto* count = new std::atomic<int64_t>(); \ |
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.
Please switch these back to uint64_t
. There is no possibility of overflow in 500+ years if we're bumping once a nanosecond..
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.
Done in 15819e6, except in the case where it's implied via the chrono count() call.
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
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, thanks!
@oschaaf this looks like a legitimate build failure on Windows. |
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Pushed efbabc5 to resolve a platform issue. Let's hope that resolves the CI error. |
Follow up to #12830 with another sparse log variant.
The periodic version relies on a real world time source, which can
be discussed separately here.
Signed-off-by: Otto van der Schaaf oschaaf@we-amp.com
Risk Level: Low
Testing: Unit tests