diff --git a/src/KArtSell.Host/Infrastructure/RateLimiterService.cs b/src/KArtSell.Host/Infrastructure/RateLimiterService.cs index ac0bfe5c..fbb14907 100644 --- a/src/KArtSell.Host/Infrastructure/RateLimiterService.cs +++ b/src/KArtSell.Host/Infrastructure/RateLimiterService.cs @@ -79,14 +79,14 @@ public class RateLimiterService LogQuotaExceeded(_logger, apiName, retryAfter, null); // Log rejection event - await LogEventAsync(apiName, "rejected", cancellationToken); + await LogEventAsync(apiName, "rejected", 1, 0, 0, cancellationToken); return (false, retryAfter); } // Token consumed successfully LogTokenConsumed(_logger, apiName, result.Value.CurrentTokens, null); - await LogEventAsync(apiName, "allowed", cancellationToken); + await LogEventAsync(apiName, "allowed", 1, 1, result.Value.CurrentTokens, cancellationToken); return (true, 0); } @@ -139,11 +139,11 @@ public class RateLimiterService _logger.LogInformation("Rate limit quotas initialized: {Count} APIs", ApiConfigs.Count); } - private async Task LogEventAsync(string apiName, string action, CancellationToken cancellationToken) + private async Task LogEventAsync(string apiName, string decision, int tokensRequested, int tokensUsed, decimal remainingTokens, CancellationToken cancellationToken) { const string sql = """ - INSERT INTO infrastructure.rate_limit_events (api_name, action, executed_at, published_at) - VALUES (@apiName, @action, @now, @now) + INSERT INTO infrastructure.rate_limit_events (api_name, decision, tokens_requested, tokens_used, remaining_tokens, occurred_at, published_at) + VALUES (@apiName, @decision, @tokensRequested, @tokensUsed, @remainingTokens, @now, @now) """; try @@ -151,7 +151,7 @@ public class RateLimiterService await using var connection = await _dataSource.OpenConnectionAsync(cancellationToken); await connection.ExecuteAsync( sql, - new { apiName = apiName.ToLower(), action, now = _clock.UtcNow.UtcDateTime }, + new { apiName = apiName.ToLower(), decision, tokensRequested, tokensUsed, remainingTokens, now = _clock.UtcNow.UtcDateTime }, commandTimeout: 5); } catch (Exception ex)