From 3371b241dfe08c842684eee6d92e1449cd359ed8 Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 21 Jul 2025 17:50:12 +0200 Subject: [PATCH] =?UTF-8?q?(fix)=20Umbau=20zu=20SCS=20###=20API-Gateway=20?= =?UTF-8?q?erweitern=20-=20Bestehenden=20API-Gateway-Service=20mit=20zus?= =?UTF-8?q?=C3=A4tzlichen=20Funktionen=20ausstatten:=20=20=20=20=20-=20Rat?= =?UTF-8?q?e=20Limiting=20implementieren=20=20=20=20=20-=20Request/Respons?= =?UTF-8?q?e=20Logging=20verbessern=20=20=20=20=20-=20Cross-Service=20Trac?= =?UTF-8?q?ing=20mit=20eindeutigen=20Request-IDs=20einf=C3=BChren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/at/mocode/gateway/config/RateLimitingConfig.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api-gateway/src/jvmMain/kotlin/at/mocode/gateway/config/RateLimitingConfig.kt b/api-gateway/src/jvmMain/kotlin/at/mocode/gateway/config/RateLimitingConfig.kt index fe773e45..2bec9d57 100644 --- a/api-gateway/src/jvmMain/kotlin/at/mocode/gateway/config/RateLimitingConfig.kt +++ b/api-gateway/src/jvmMain/kotlin/at/mocode/gateway/config/RateLimitingConfig.kt @@ -124,7 +124,7 @@ private object AdaptiveRateLimiting { "(CPU: ${String.format("%.1f", cpuLoad)}%, Memory: ${String.format("%.1f", memoryUsage)}%)") } } catch (e: Exception) { - // If any error occurs, reset to normal load + // If any error occurs, reset to a normal load currentLoadFactor.set(100) println("[AdaptiveRateLimiting] Error monitoring system load: ${e.message}") } @@ -168,7 +168,7 @@ private fun generateRequestKey(vararg inputs: String?): String { for (input in inputs) { if (input != null && input.isNotEmpty()) { - // Combine hashes using XOR and bit rotation for better distribution + // Combine hashes using XOR and a bit of rotation for better distribution val inputHash = efficientHash(input) combinedHash = (combinedHash xor inputHash) + ((combinedHash shl 5) + (combinedHash shr 2)) } @@ -214,7 +214,7 @@ fun Application.configureRateLimiting() { // Using efficient hashing for better performance requestKey { call -> val ip = call.request.local.remoteHost - val requestId = call.attributes.getOrNull(REQUEST_ID_KEY)?.toString() ?: "" + val requestId = call.attributes.getOrNull(REQUEST_ID_KEY) ?: "" val endpoint = endpoint // Include endpoint in the key for better separation // Use efficient hashing to generate request key generateRequestKey(ip, requestId, endpoint) @@ -497,7 +497,7 @@ private fun determineUserTypeFromPayload(payload: String): String { } // Check for an array of roles - val rolesArrayRegex = "\"(role|roles|authorities)\"\\s*:\\s*\\[([^\\]]+)\\]".toRegex() + val rolesArrayRegex = "\"(role|roles|authorities)\"\\s*:\\s*\\[([^]]+)]".toRegex() val arrayMatchResult = rolesArrayRegex.find(payload) if (arrayMatchResult != null) {