Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions test/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,19 @@ def test_dump_wait_failures_use_rate_limited_error_logging(relative_path):
assert set(matching_calls) == {"error_limit"}


def test_default_rate_limit_window_is_ten_seconds():
def test_default_rate_limit_window_is_sixty_seconds():
header = (REPO_ROOT / "ucm/shared/infra/logger/cc/spdlog_logger.h").read_text(
encoding="utf-8"
)
logger_doc = (REPO_ROOT / "ucm/logger.py").read_text(encoding="utf-8")

assert "kDefaultRateLimitWindowMs = 10000" in header
assert "default: 10000 = 10s" in logger_doc
assert "kDefaultRateLimitWindowMs = 60000" in header
assert "default: 60000 = 60s" in logger_doc


def test_health_breaker_transition_logging_is_unlimited():
source = (REPO_ROOT / "ucm/store/pipeline/cc/health_breaker_store.cc").read_text(
encoding="utf-8"
)

assert 'UC_WARN_UNLIMITED(\n "Store health breaker' in source
4 changes: 2 additions & 2 deletions ucm/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
(default: true, see logger_patch)

UCM_LOG_RATE_LIMIT_ENABLE: Enable/disable rate limiting (default: true)
UCM_LOG_RATE_LIMIT_WINDOW_MS: Time window in milliseconds (default: 10000 = 10s)
UCM_LOG_RATE_LIMIT_WINDOW_MS: Time window in milliseconds (default: 60000 = 60s)
UCM_LOG_RATE_LIMIT_MAX_LOGS: Max logs per window (default: 3, max: 3)

Usage:
logger = init_logger(__name__)

# Rate-limited logging (10s window, max 3 logs per location)
# Rate-limited logging (60s window, max 3 logs per location)
logger.info_limit("Processing request %s", req_id)

# One-time logging (cached by lru_cache)
Expand Down
2 changes: 1 addition & 1 deletion ucm/shared/infra/logger/cc/spdlog_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct SourceLocation {
const char* InternSourceString(std::string&& s);

class Logger {
static constexpr uint64_t kDefaultRateLimitWindowMs = 10000;
static constexpr uint64_t kDefaultRateLimitWindowMs = 60000;
std::shared_ptr<spdlog::logger> logger_;
std::shared_ptr<spdlog::logger> file_logger_;
std::mutex mutex_;
Expand Down
2 changes: 1 addition & 1 deletion ucm/store/pipeline/cc/health_breaker_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void HealthBreakerStore::RecordHealth(bool healthy)
}
}
if (oldEnabled != newEnabled) {
UC_WARN(
UC_WARN_UNLIMITED(
"Store health breaker({}) transitioned to {}, window=[{}], samples={}, failures={}, "
"threshold={}.",
storeId_, newEnabled ? "HEALTHY" : "UNHEALTHY", healthWindow, sampleCount, failureCount,
Expand Down
Loading