Skip to content

Commit

Permalink
bugfix: 修复第三方插件日志获取异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshuaikang authored and normal-wls committed Jul 19, 2023
1 parent 1e3f03d commit bb51e98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
20 changes: 10 additions & 10 deletions plugin_service/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
from rest_framework.response import Response

from plugin_service import env
from plugin_service.conf import PLUGIN_LOGGER, PLUGIN_DISTRIBUTOR_NAME
from plugin_service.api_decorators import inject_plugin_client, validate_params
from plugin_service.conf import PLUGIN_DISTRIBUTOR_NAME, PLUGIN_LOGGER
from plugin_service.exceptions import PluginServiceException
from plugin_service.plugin_client import PluginServiceApiClient
from plugin_service.serializers import (
PluginListResponseSerializer,
DetailResponseSerializer,
MetaResponseSerializer,
LogResponseSerializer,
LogQuerySerializer,
PluginDetailQuerySerializer,
PluginCodeQuerySerializer,
PluginListQuerySerializer,
LogResponseSerializer,
MetaResponseSerializer,
PluginAppDetailResponseSerializer,
PluginCodeQuerySerializer,
PluginDetailListQuerySerializer,
PluginDetailListResponseSerializer,
PluginDetailQuerySerializer,
PluginListQuerySerializer,
PluginListResponseSerializer,
PluginTagListResponseSerializer,
PluginTagsListQuerySerializer,
)
Expand Down Expand Up @@ -220,12 +220,12 @@ def get_meta(request: Request):


@swagger_auto_schema(
method="GET",
method="POST",
operation_summary="获取插件服务执行日志",
query_serializer=LogQuerySerializer,
request_body=LogQuerySerializer,
responses={200: LogResponseSerializer},
)
@api_view(["GET"])
@api_view(["POST"])
@validate_params(LogQuerySerializer)
def get_logs(request: Request):
"""获取插件服务执行日志"""
Expand Down
20 changes: 13 additions & 7 deletions plugin_service/plugin_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
from django.core.files.uploadedfile import UploadedFile

from . import env
from .client_decorators import (
check_use_plugin_service,
data_parser,
json_response_decoder,
)
from .conf import PLUGIN_CLIENT_LOGGER
from .client_decorators import data_parser, json_response_decoder, check_use_plugin_service
from .exceptions import PluginServiceNotUse, PluginServiceException
from .exceptions import PluginServiceException, PluginServiceNotUse

logger = logging.getLogger(PLUGIN_CLIENT_LOGGER)

Expand Down Expand Up @@ -227,14 +231,14 @@ def batch_get_paas_plugin_detailed_info(environment=None, search_term=None, dist
@json_response_decoder
def get_paas_logs(plugin_code, trace_id, scroll_id=None, environment=None):
"""通过PaaS平台查询插件服务日志"""
url, params = PluginServiceApiClient._prepare_paas_api_request(
url, data = PluginServiceApiClient._prepare_paas_api_request(
path_params=["system/bk_plugins", plugin_code, "logs"], environment=environment
)
params.update({"trace_id": trace_id})
data.update({"trace_id": trace_id})
if scroll_id:
params.update({"scroll_id": scroll_id})
data.update({"scroll_id": scroll_id})

return PluginServiceApiClient._request_api_and_error_retry(url, method="get", params=params)
return PluginServiceApiClient._request_api_and_error_retry(url, method="post", data=data)

@staticmethod
@json_response_decoder
Expand All @@ -248,7 +252,9 @@ def get_paas_plugin_tags(environment=None, **kwargs):
def _prepare_apigw_api_request(self, path_params: list, inject_authorization: dict = None):
"""插件服务APIGW接口请求信息准备"""
url = os.path.join(
env.PLUGIN_APIGW_API_HOST_FORMAT.format(self.plugin_apigw_name), env.APIGW_ENVIRONMENT, *path_params,
env.PLUGIN_APIGW_API_HOST_FORMAT.format(self.plugin_apigw_name),
env.APIGW_ENVIRONMENT,
*path_params,
)
authorization_info = {
"bk_app_code": env.PLUGIN_SERVICE_APIGW_APP_CODE,
Expand Down

0 comments on commit bb51e98

Please sign in to comment.