diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwLogResourceV3Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwLogResourceV3Impl.kt index 451c1b19fd1..461c6d47b99 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwLogResourceV3Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwLogResourceV3Impl.kt @@ -27,7 +27,9 @@ package com.tencent.devops.openapi.resources.apigw.v3 +import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.api.util.OkhttpUtils import com.tencent.devops.common.client.Client import com.tencent.devops.common.log.pojo.QueryLogStatus import com.tencent.devops.common.web.RestResource @@ -36,12 +38,18 @@ import com.tencent.devops.common.log.pojo.QueryLogs import com.tencent.devops.openapi.api.apigw.v3.ApigwLogResourceV3 import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value +import javax.ws.rs.core.MediaType import javax.ws.rs.core.Response @RestResource class ApigwLogResourceV3Impl @Autowired constructor( private val client: Client ) : ApigwLogResourceV3 { + + @Value("\${gateway.url:#{null}}") + private val gatewayUrl: String? = "" + override fun getInitLogs( appCode: String?, apigwType: String?, @@ -152,15 +160,20 @@ class ApigwLogResourceV3Impl @Autowired constructor( "downloadLogs project[$projectId] pipelineId[$pipelineId] buildId[$buildId]" + "jobId[$jobId] executeCount[$executeCount] tag[$tag] jobId[$jobId]" ) - return client.get(ServiceLogResource::class).downloadLogs( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - buildId = buildId, - tag = tag, - jobId = jobId, - executeCount = executeCount - ) + val path = StringBuilder("http://$gatewayUrl/log/api/service/logs/") + path.append(projectId) + path.append("/$pipelineId/$buildId/download?executeCount=${executeCount ?: 1}") + + if (!tag.isNullOrBlank()) path.append("&tag=$tag") + if (!jobId.isNullOrBlank()) path.append("&jobId=$jobId") + + val response = OkhttpUtils.doLongGet(path.toString(), mapOf(AUTH_HEADER_USER_ID to userId)) + return Response + .ok(response.body()!!.byteStream(), MediaType.APPLICATION_OCTET_STREAM_TYPE) + .header("content-disposition", "attachment; filename = $pipelineId-$buildId-log.txt") + .header("Cache-Control", "no-cache") + .header("X-DEVOPS-PROJECT-ID", "gitciproject") + .build() } override fun getLogMode(