Skip to content

Commit

Permalink
feat: 支持输出详细下载失败日志 #2326
Browse files Browse the repository at this point in the history
* feat: 支持详细下载失败日志 #2326

* feat: 支持详细下载失败日志 #2326

* feat: 支持详细下载失败日志 #2326
  • Loading branch information
cnlkl authored Jul 3, 2024
1 parent 66a0e13 commit 633fd9f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ abstract class AbstractArtifactRepository : ArtifactRepository {
val range = HeaderUtils.getHeader(HttpHeaders.RANGE) ?: StringPool.DASH
logger.warn(
"User[$principal],ip[$clientAddress] download artifact[$artifactInfo] failed[$code]$message" +
" X_FORWARDED_FOR: $xForwardedFor, range: $range"
" X_FORWARDED_FOR: $xForwardedFor, range: $range", exception
)
ArtifactMetrics.getDownloadFailedCounter().increment()
} catch (exception: ArtifactNotFoundException){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.tencent.bkrepo.common.artifact.util.http.IOExceptionUtils
import com.tencent.bkrepo.common.storage.core.StorageProperties
import com.tencent.bkrepo.common.storage.monitor.Throughput
import com.tencent.bkrepo.common.storage.monitor.measureThroughput
import org.slf4j.LoggerFactory
import org.springframework.http.HttpMethod
import org.springframework.util.unit.DataSize
import java.io.IOException
Expand Down Expand Up @@ -115,10 +116,12 @@ abstract class AbstractArtifactResourceHandler(
// org.springframework.http.converter.HttpMessageNotWritableException异常,会重定向到/error页面
// 又因为/error页面不存在,最终返回404,所以要对IOException进行包装,在上一层捕捉处理
val message = exception.message.orEmpty()
val status = if (IOExceptionUtils.isClientBroken(exception))
val status = if (IOExceptionUtils.isClientBroken(exception)){
HttpStatus.BAD_REQUEST
else
} else {
logger.warn("write range stream failed", exception)
HttpStatus.INTERNAL_SERVER_ERROR
}
throw ArtifactResponseException(message, status)
}
}
Expand All @@ -131,4 +134,7 @@ abstract class AbstractArtifactResourceHandler(
return if (isRangeRequest) HttpStatus.PARTIAL_CONTENT.value else HttpStatus.OK.value
}

companion object {
private val logger = LoggerFactory.getLogger(AbstractArtifactResourceHandler::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.tencent.bkrepo.common.storage.core.StorageProperties
import com.tencent.bkrepo.common.storage.monitor.Throughput
import com.tencent.bkrepo.common.storage.monitor.measureThroughput
import com.tencent.bkrepo.repository.pojo.node.NodeDetail
import org.slf4j.LoggerFactory
import org.springframework.http.HttpMethod
import java.io.IOException
import java.time.LocalDateTime
Expand Down Expand Up @@ -198,7 +199,12 @@ open class DefaultArtifactResourceWriter(
}
} catch (exception: IOException) {
val message = exception.message.orEmpty()
val status = if (isClientBroken(exception)) HttpStatus.BAD_REQUEST else HttpStatus.INTERNAL_SERVER_ERROR
val status = if (isClientBroken(exception)) {
HttpStatus.BAD_REQUEST
} else {
logger.warn("write zip stream failed", exception)
HttpStatus.INTERNAL_SERVER_ERROR
}
throw ArtifactResponseException(message, status)
} finally {
resource.artifactMap.values.forEach { it.closeQuietly() }
Expand Down Expand Up @@ -232,6 +238,7 @@ open class DefaultArtifactResourceWriter(
}

companion object {
private val logger = LoggerFactory.getLogger(DefaultArtifactResourceWriter::class.java)
private val binaryMediaTypes = setOf(MediaTypes.APPLICATION_APK)
}
}

0 comments on commit 633fd9f

Please sign in to comment.