[#28] 쿠버네티스 환경 배포 #29

Merged
pricelees merged 25 commits from infra/#28 into main 2025-08-04 05:59:38 +00:00
2 changed files with 46 additions and 8 deletions
Showing only changes of commit 2af0923189 - Show all commits

View File

@ -4,26 +4,38 @@ import net.ttddyy.dsproxy.ExecutionInfo
import net.ttddyy.dsproxy.QueryInfo import net.ttddyy.dsproxy.QueryInfo
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel
import net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener import net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener
import java.util.function.Predicate
class MDCAwareSlowQueryListenerWithoutParams( class MDCAwareSlowQueryListenerWithoutParams : SLF4JQueryLoggingListener {
private val thresholdMs: Long private val slowQueryPredicate: SlowQueryPredicate
) : SLF4JQueryLoggingListener() { private val sqlLogFormatter: SqlLogFormatter
init { constructor(logLevel: SLF4JLogLevel, thresholdMs: Long) {
this.logLevel = SLF4JLogLevel.WARN this.logLevel = logLevel
this.slowQueryPredicate = SlowQueryPredicate(thresholdMs)
this.sqlLogFormatter = SqlLogFormatter()
} }
override fun afterQuery( override fun afterQuery(
execInfo: ExecutionInfo, execInfo: ExecutionInfo,
queryInfoList: List<QueryInfo> queryInfoList: List<QueryInfo>
) { ) {
if (execInfo.elapsedTime >= thresholdMs) { if (slowQueryPredicate.test(execInfo.elapsedTime)) {
super.afterQuery(execInfo, queryInfoList) super.afterQuery(execInfo, queryInfoList)
} }
} }
override fun writeLog(message: String) { override fun writeLog(message: String) {
val modified = message.replace(Regex("""(,?\s*)Params:\[.*?]"""), "") super.writeLog(sqlLogFormatter.maskParams(message))
super.writeLog(modified)
} }
} }
class SqlLogFormatter {
fun maskParams(message: String) = message.replace(Regex("""(,?\s*)Params:\[.*?]"""), "")
}
class SlowQueryPredicate(
private val thresholdMs: Long
) : Predicate<Long> {
override fun test(t: Long): Boolean = (t >= thresholdMs)
}

View File

@ -0,0 +1,26 @@
package roomescape.common.log
import io.kotest.assertions.assertSoftly
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
class MDCAwareSlowQueryListenerWithoutParamsTest : StringSpec({
"SQL 메시지에서 Params 항목은 가린다." {
val message = """Query:["select * from members m where m.email=?"], Params:[(a@a.a)]"""
val expected = """Query:["select * from members m where m.email=?"]"""
val result = SqlLogFormatter().maskParams(message)
result shouldBe expected
}
"입력된 thresholdMs 보다 소요시간이 긴 쿼리를 기록한다." {
val slowQueryThreshold = 10L
val slowQueryPredicate = SlowQueryPredicate(thresholdMs = slowQueryThreshold)
assertSoftly(slowQueryPredicate) {
it.test(slowQueryThreshold) shouldBe true
it.test(slowQueryThreshold + 1) shouldBe true
it.test(slowQueryThreshold - 1) shouldBe false
}
}
})