Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API 网关:请求日志查询 #265

Open
alex-smile opened this issue Sep 20, 2023 · 0 comments
Open

API 网关:请求日志查询 #265

alex-smile opened this issue Sep 20, 2023 · 0 comments

Comments

@alex-smile
Copy link
Contributor

alex-smile commented Sep 20, 2023

Description

本文档介绍,调用 API 后,如何查询请求的日志记录。容器化及二进制版本,网关都提供了对应的 API 请求日志采集功能,开启后,可采集及查询 API 请求日志记录。

容器化版本

网关 API

1. 如何启用网关 API 的日志采集

第一步:chart values.yaml 中,通过 apigateway.bkLogConfig 配置是否启用日志采集,及日志上报数据ID;将 enabled 设置为 true,并在日志平台 bklog "管理" -> "自定义上报" 中,创建 3 个 自定义上报数据ID,并配置 stdoutDataId、containerDataId、fileDataId。此时日志平台 bklog 将会采集网关请求流水日志文件 /usr/local/apisix/logs/access.log 中的请求流水日志。

第二步:采集项 index 默认应为 chart values.yaml 中 dashboard.bkApigwApiLogEsIndex 中配置的:2_bklog_bkapigateway_apigateway_container*(待确认)

第三步:观察日志平台 bklog 中是否采集到日志(需有请求量),并为其配置日志清洗。因请求流水为一个 json 字符串,需利用日志平台的清洗规则,将 json 串中日志解析为日志字段。

清洗模板参考:
image

image image

1.14 版本开始,增加一个清洗字段

  • bk_username string

2. 如何查询网关 API 的请求日志

在日志平台检索中,可查询清洗后的请求日志记录,index 为:[采集项]bkapigateway-apigateway-container(2_bklog.bkapigateway_apigateway_container)

组件 API

第一步:chart values.yaml 中,通过 bkEsb.bkLogConfig 配置是否启用日志采集,及日志上报数据ID;将 enabled 设置为 true,并在日志平台 bklog "管理" -> "自定义上报" 中,创建 2 个 自定义上报数据ID,并配置 stdoutDataId、containerDataId。此时日志平台 bklog 将会采集 ESB 请求流水日志文件 /apps/logs/esb_api.log 中的请求流水日志。

第二步:采集项 index 默认应为 chart values.yaml 中 dashboard.bkEsbApiLogEsIndex 中配置的:2_bklog_bkapigateway_esb_container*(待确认)

第三步:观察日志平台 bklog 中是否采集到日志(需有请求量),并为其配置日志清洗。因请求流水为一个 json 字符串,需利用日志平台的清洗规则,将 json 串中日志解析为日志字段。

清洗模板参考:

image image

二进制版本

二进制版本,网关提供了基于 filebeat + logstash 的日志采集方案。需联系运维同学部署此日志采集方案。部署后,日志将采集到对应的 Elasticsearch 中,如需在线查看请求日志,可联系运维部署一个 Kibana。(日志采集方案在 paas_plugins 项目)

默认的 Elasticsearch index:

  • 网关 API:bkapigateway_apigateway_api_log
  • 组件 API:bkapigateway_esb_api_log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant