aboutsummaryrefslogtreecommitdiffstats
path: root/logd/src
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-04-16 13:15:10 +0000
committerArne Juul <arnej@verizonmedia.com>2020-04-16 13:15:10 +0000
commit37ef831811850d1cf510ff391dee6618daac7c8f (patch)
tree885d4b2dc6d804db66747ce2775cf04d999269e5 /logd/src
parent59f2c782fe66711b733a48bcdcad22fe37f25197 (diff)
only do aggressive removal if spamming detected at least 3 times
Diffstat (limited to 'logd/src')
-rw-r--r--logd/src/logd/watcher.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/logd/src/logd/watcher.cpp b/logd/src/logd/watcher.cpp
index 036ef09bee6..a91de132061 100644
--- a/logd/src/logd/watcher.cpp
+++ b/logd/src/logd/watcher.cpp
@@ -117,6 +117,7 @@ Watcher::watchfile()
{
struct donecache already;
char newfn[FILENAME_MAX];
+ int spamfill_counter = 0;
char *target = getenv("VESPA_LOG_TARGET");
if (target == nullptr || strncmp(target, "file:", 5) != 0) {
@@ -215,23 +216,30 @@ Watcher::watchfile()
if (rotate) {
vespalib::duration rotTime = rotTimer.elapsed();
- if (rotTime > 59s || (sb.st_size == offset && rotTime > 4s)) {
- removeOldLogs(filename);
+ off_t overflow_size = (1.1 * _confsubscriber.getRotateSize());
+ if ((rotTime > 59s) ||
+ (sb.st_size == offset && rotTime > 4s) ||
+ (sb.st_size > overflow_size && rotTime > 2s))
+ {
if (sb.st_size != offset) {
LOG(warning, "logfile rotation incomplete after %2.3f s (dropping %" PRIu64 " bytes)",
vespalib::to_s(rotTime), static_cast<uint64_t>(sb.st_size - offset));
} else {
LOG(debug, "logfile rotation complete after %2.3f s", vespalib::to_s(rotTime));
}
- if (((now - created) < (rotTime + 300s))
- && (sb.st_size > (1.1 * _confsubscriber.getRotateSize())))
- {
- LOG(warning, "logfile spamming, aggressively removing %s", newfn);
- unlink(newfn);
+ if (((now - created) < (rotTime + 180s)) && (sb.st_size > overflow_size)) {
+ ++spamfill_counter;
+ } else {
+ spamfill_counter = 0;
}
created = now;
rotate = false;
close(_wfd);
+ if (spamfill_counter > 2) {
+ LOG(warning, "logfile spamming %d times, aggressively removing %s", spamfill_counter, newfn);
+ unlink(newfn);
+ }
+ removeOldLogs(filename);
goto again;
}
} else if (stat(filename, &sb) != 0