Skip to content
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

Avoiding high frequency logging #484

Closed
oschaaf opened this issue Aug 25, 2020 · 5 comments · Fixed by #511
Closed

Avoiding high frequency logging #484

oschaaf opened this issue Aug 25, 2020 · 5 comments · Fixed by #511

Comments

@oschaaf
Copy link
Member

oschaaf commented Aug 25, 2020

Sometimes there's error flow control in the hot path that deserves logging, but plain logging there
risks generating a large amount of log spam.
It would be great to have a low-barrier and easy-to-consume way to emit a single or bounded number of log lines in these cases.

@oschaaf
Copy link
Member Author

oschaaf commented Aug 25, 2020

/cc @htuch do you know if Envoy already has something in place for this?

@oschaaf
Copy link
Member Author

oschaaf commented Aug 25, 2020

Maybe something like ENVOY_LOG_ONCE(...) in this minimal PoC would work?:

#include <atomic>
#include <iostream>

#define ENVOY_LOG(...) std::cerr << "logline" << std::endl;

#define ENVOY_LOG_ONCE(...) \
do { \
    static std::atomic<bool>* logged = new std::atomic<bool>(false); \
    bool kExpected = false; \
    if (logged->compare_exchange_strong(kExpected /*expected value*/, true /*new value*/)) { \
        ENVOY_LOG(__VA_ARGS_); \
    } \
} while (0)

int main() {
    int i =0;
    while (i++ < 100) {
        ENVOY_LOG_ONCE("1");
        ENVOY_LOG_ONCE("2");
    }
}

// clang  -lstdc++ test.cc  && ./a.out
// Only two log lines will be emitted from the while loop above.

@oschaaf
Copy link
Member Author

oschaaf commented Aug 25, 2020

afterthought -- the PoC above attempts to be precise and logs exactly once in multi-threaded scenarios. But it might be possible to trade in precision for performance by looking into eventual consistency (or even just accepting logging once / thread as a reasonable bound). It may also be reasonable to emit another log message indicating that log messages of this type are being truncated.

@htuch
Copy link
Member

htuch commented Aug 26, 2020

@oschaaf please add this to upstream Envoy, this is an often requested feature. I think there are multiple variations that could make sence, ENVOY_LOG_ONCE, ENVOY_LOG_EVERY_N, ENVOY_LOG_EVERY_N_SECONDS.

oschaaf added a commit to oschaaf/envoy that referenced this issue Aug 26, 2020
Sometimes there's error flow control in the hot path that deserves logging,
but plain logging there risks generating a large amount of log spam.
It would be great to have a low-barrier and easy-to-consume way to emit a single
or bounded number of log lines in these cases. This proposes a means to emit
a single log line in those cases.

Cross referencing Nighthawk issue to prompted this:
envoyproxy/nighthawk#484

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf
Copy link
Member Author

oschaaf commented Aug 26, 2020

@htuch proposed envoyproxy/envoy#12830

ggreenway pushed a commit to envoyproxy/envoy that referenced this issue Sep 2, 2020
Sometimes there's error flow control in the hot path that deserves logging,
but plain logging there risks generating a large amount of log spam.
It would be great to have a low-barrier and easy-to-consume way to emit a single
or bounded number of log lines in these cases. This proposes a means to emit
a single log line in those cases.

Cross referencing Nighthawk issue to prompted this:
envoyproxy/nighthawk#484

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
oschaaf added a commit to oschaaf/nighthawk that referenced this issue Sep 4, 2020
Fixes envoyproxy#484

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
dubious90 pushed a commit that referenced this issue Sep 8, 2020
Throttle log emission in a few potentially high frequency paths.

Fixes #484

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants