Skip to content

Commit

Permalink
perf: 日志单行输出超过限制(16KB)自动分行 TencentBlueKing#8856
Browse files Browse the repository at this point in the history
  • Loading branch information
royalhuang committed May 24, 2023
1 parent f0989cf commit 7ae2436
Showing 1 changed file with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ import com.tencent.devops.common.log.pojo.TaskBuildLogProperty
import com.tencent.devops.common.log.pojo.enums.LogStorageMode
import com.tencent.devops.common.log.pojo.enums.LogType
import com.tencent.devops.common.log.pojo.message.LogMessage
import com.tencent.devops.common.service.utils.CommonUtils
import com.tencent.devops.common.service.utils.ZipUtil
import com.tencent.devops.common.util.HttpRetryUtils
import com.tencent.devops.log.meta.Ansi
import com.tencent.devops.process.pojo.BuildVariables
import com.tencent.devops.process.utils.PIPELINE_START_USER_ID
import com.tencent.devops.worker.common.LOG_DEBUG_FLAG
Expand Down Expand Up @@ -265,9 +263,16 @@ object LoggerService {

try {
if (currentTaskLineNo <= LOG_TASK_LINE_LIMIT) {
var offset = 0
// 上报前做长度等内容限制
fixUploadMessage(logMessage)
this.uploadQueue.put(logMessage)
while (offset < logMessage.message.length) {
val chunk = logMessage.message.substring(
offset, minOf(offset + LOG_MESSAGE_LENGTH_LIMIT, logMessage.message.length)
)
this.uploadQueue.put(logMessage.copy(message = chunk))
offset += LOG_MESSAGE_LENGTH_LIMIT
}

} else if (elementId2LogProperty[elementId]?.logStorageMode != LogStorageMode.LOCAL) {
logger.warn(
"The number of Task[$elementId] log lines exceeds the limit, " +
Expand Down Expand Up @@ -471,19 +476,6 @@ object LoggerService {
}
}

private fun fixUploadMessage(logMessage: LogMessage) {
// 字符数超过32766时analyzer索引分析将失效,同时为保护系统稳定性,若配置值为空或负数则限制为32KB
if (logMessage.message.length > LOG_MESSAGE_LENGTH_LIMIT) {
logMessage.message = Ansi().bold().fgYellow()
.a("[Length exceeds limit]")
.reset().toString()
}
logMessage.message = CommonUtils.interceptStringInLength(
string = logMessage.message,
length = LOG_MESSAGE_LENGTH_LIMIT
) ?: ""
}

private fun disableLogUpload() {
// 将已有任务的日志模式都设为本地保存
elementId2LogProperty.forEach { (elementId, property) ->
Expand Down

0 comments on commit 7ae2436

Please sign in to comment.