Skip to main content
Version: 2.15

google-cloud-logging

描述#

google-cloud-logging 插件用于将 Apache APISIX 的请求日志发送到 Google Cloud Logging Service

该插件提供了将请求的日志数据以批处理队列的形式推送到谷歌云日志服务的功能。

有关 Apache APISIXBatch-Processor 的更多信息,请参考: Batch-Processor

属性#

名称是否必需默认值描述
auth_config半可选必须配置 auth_configauth_file 之一
auth_config.private_key必选谷歌服务帐号的私钥参数
auth_config.project_id必选谷歌服务帐号的项目 ID
auth_config.token_uri可选https://oauth2.googleapis.com/token请求谷歌服务帐户的令牌的 URI
auth_config.entries_uri可选https://logging.googleapis.com/v2/entries:write谷歌日志服务写入日志条目的 API
auth_config.scopes可选["https://www.googleapis.com/auth/logging.read","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/logging.admin","https://www.googleapis.com/auth/cloud-platform"]谷歌服务账号的访问范围,参考:OAuth 2.0 Scopes for Google APIs
auth_file半可选谷歌服务账号 JSON 文件的路径(必须配置 auth_configauth_file 之一)
ssl_verify可选true启用 SSL 验证,配置根据 OpenResty 文档 选项
resource可选{"type": "global"}谷歌监控资源,参考: MonitoredResource
log_id可选apisix.apache.org%2Flogs谷歌日志 ID,参考: LogEntry

本插件支持使用批处理器来聚合并批量处理条目(日志/数据)。这样可以避免插件频繁地提交数据,默认设置情况下批处理器会每 5 秒钟或队列中的数据达到 1000 条时提交数据,如需了解或自定义批处理器相关参数设置,请参考 Batch-Processor 配置部分。

如何开启#

下面例子展示了如何为指定路由开启 google-cloud-logging 插件。

完整配置#

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"google-cloud-logging": {
"auth_config":{
"project_id":"apisix",
"private_key":"-----BEGIN RSA PRIVATE KEY-----your private key-----END RSA PRIVATE KEY-----",
"token_uri":"https://oauth2.googleapis.com/token",
"scopes":[
"https://www.googleapis.com/auth/logging.admin"
],
"entries_uri":"https://logging.googleapis.com/v2/entries:write"
},
"resource":{
"type":"global"
},
"log_id":"apisix.apache.org%2Flogs",
"inactive_timeout":10,
"max_retry_count":0,
"max_retry_count":0,
"buffer_duration":60,
"retry_delay":1,
"batch_max_size":1
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
},
"uri": "/hello"
}'

最小化配置#

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"google-cloud-logging": {
"auth_config":{
"project_id":"apisix",
"private_key":"-----BEGIN RSA PRIVATE KEY-----your private key-----END RSA PRIVATE KEY-----"
}
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
},
"uri": "/hello"
}'

测试插件#

  • 向配置 google-cloud-logging 插件的路由发送请求
$ curl -i http://127.0.0.1:9080/hello
HTTP/1.1 200 OK
...
hello, world
  • 登录谷歌云日志服务,查看日志

Google Cloud Logging Service

禁用插件#

禁用 google-cloud-logging 插件非常简单,只需将 google-cloud-logging 对应的 JSON 配置移除即可。

$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/hello",
"plugins": {},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}'