Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#1249 from cnlkl/issue_488
Browse files Browse the repository at this point in the history
调整制品分析失败错误日志级别
  • Loading branch information
owenlxu authored Oct 12, 2023
2 parents e12c400 + 396a509 commit 643583f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ enum class ScannerMessageCode(
EXPORT_REPORT_STATUS_UN_QUALITY("export.report.status.un.quality", 26),
EXPORT_REPORT_STATUS_QUALITY_PASS("export.report.status.quality.pass", 27),
EXPORT_REPORT_STATUS_QUALITY_UN_PASS("export.report.status.quality.un.pass", 28),
EXPORT_REPORT_STATUS_FAILED("export.report.status.failed", 29);
EXPORT_REPORT_STATUS_FAILED("export.report.status.failed", 29),
ANALYST_ARTIFACT_DELETED("analyst.artifact.deleted", 30);

override fun getBusinessCode() = businessCode
override fun getKey() = key
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.bkrepo.analyst.exception

import com.tencent.bkrepo.analyst.message.ScannerMessageCode
import com.tencent.bkrepo.common.api.exception.ErrorCodeException

class ArtifactDeletedException(val sha256: String) :
ErrorCodeException(ScannerMessageCode.ANALYST_ARTIFACT_DELETED, sha256)
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ package com.tencent.bkrepo.analyst.service.impl

import com.tencent.bkrepo.analyst.configuration.ScannerProperties
import com.tencent.bkrepo.analyst.configuration.ScannerProperties.Companion.EXPIRED_SECONDS
import com.tencent.bkrepo.analyst.exception.ArtifactDeletedException
import com.tencent.bkrepo.analyst.pojo.SubScanTask
import com.tencent.bkrepo.analyst.pojo.request.ReportResultRequest
import com.tencent.bkrepo.analyst.service.ScanService
import com.tencent.bkrepo.analyst.service.TemporaryScanTokenService
import com.tencent.bkrepo.auth.api.ServiceTemporaryTokenClient
import com.tencent.bkrepo.auth.pojo.token.TemporaryTokenCreateRequest
import com.tencent.bkrepo.auth.pojo.token.TokenType
import com.tencent.bkrepo.common.analysis.pojo.scanner.SubScanTaskStatus
import com.tencent.bkrepo.common.analysis.pojo.scanner.standard.FileUrl
import com.tencent.bkrepo.common.analysis.pojo.scanner.standard.StandardScanner
import com.tencent.bkrepo.common.analysis.pojo.scanner.standard.ToolInput
Expand Down Expand Up @@ -125,15 +128,27 @@ class TemporaryScanTokenServiceImpl(
}

override fun getToolInput(subtaskId: String, token: String): ToolInput {
return getToolInput(scanService.get(subtaskId).apply { this.token = token })
try {
return getToolInput(scanService.get(subtaskId).apply { this.token = token })
} catch (e: ArtifactDeletedException) {
logger.warn("artifact [${e.sha256}] was deleted, set subtask[$subtaskId] to failed")
scanService.reportResult(ReportResultRequest(subtaskId, SubScanTaskStatus.FAILED.name))
throw e
}
}

override fun pullToolInput(executionCluster: String, token: String): ToolInput? {
val subtask = scanService.pull(executionCluster)
return subtask?.let {
logger.info("executionCluster[$executionCluster] pull subtask[${it.taskId}]")
subtask.token = token
getToolInput(it)
try {
getToolInput(it)
} catch (e: ArtifactDeletedException) {
logger.warn("artifact [${e.sha256}] was deleted, set subtask[${it.taskId}] to failed")
scanService.reportResult(ReportResultRequest(it.taskId, SubScanTaskStatus.FAILED.name))
null
}
}
}

Expand Down Expand Up @@ -221,11 +236,15 @@ class TemporaryScanTokenServiceImpl(
.build()
)

if (res.isNotOk() || res.data!!.records.isEmpty()) {
if (res.isNotOk()) {
logger.error("get node of layer[$it] failed, msg[${res.message}]")
throw SystemErrorException()
}

if (res.data!!.records.isEmpty()) {
throw ArtifactDeletedException(it)
}

res.data!!.records.first()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class FinishSubtaskAction(
require(context is FinishSubtaskContext)
with(context) {
if (targetState != SubScanTaskStatus.SUCCESS.name) {
logger.error(
logger.warn(
"task[${subtask.parentScanTaskId}], subtask[${subtask.id}], " +
"scan failed: $scanExecutorResult"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ export.report.status.un.quality=no quality rules set
export.report.status.quality.pass=quality rules passed
export.report.status.quality.un.pass=quality rule failed
export.report.status.failed=scan anomalies
analyst.artifact.deleted=Artifact [{0}] was deleted
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ export.report.status.un.quality=未设置质量规则
export.report.status.quality.pass=质量规则通过
export.report.status.quality.un.pass=质量规则未通过
export.report.status.failed=扫描异常
analyst.artifact.deleted=制品 [{0}] 已被删除
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ export.report.status.un.quality=未設置質量規則
export.report.status.quality.pass=質量規則通過
export.report.status.quality.un.pass=質量規則未通過
export.report.status.failed=掃描異常

analyst.artifact.deleted=製品 [{0}] 已刪除

0 comments on commit 643583f

Please sign in to comment.