Skip to main content
Version: 2.14

google-cloud-logging

Description#

google-cloud-logging plugin is used to send the access log of Apache APISIX to the Google Cloud Logging Service.

This plugin provides the ability to push log data as a batch to Google Cloud logging Service.

For more info on Batch-Processor in Apache APISIX please refer: Batch-Processor

Attributes#

NameRequirementDefaultDescription
auth_configSemi-optionalone of auth_config or auth_file must be configured
auth_config.private_keyrequiredthe private key parameters of the Google service account
auth_config.project_idrequiredthe project id parameters of the Google service account
auth_config.token_urioptionalhttps://oauth2.googleapis.com/tokenthe token uri parameters of the Google service account
auth_config.entries_urioptionalhttps://logging.googleapis.com/v2/entries:writegoogle cloud logging service API
auth_config.scopesoptional["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"]the access scopes parameters of the Google service account, refer to: OAuth 2.0 Scopes for Google APIs
auth_filesemi-optionalpath to the google service account json file(Semi-optional, one of auth_config or auth_file must be configured)
ssl_verifyoptionaltrueenable SSL verification, option as per OpenResty docs
resourceoptional{"type": "global"}the Google monitor resource, refer to: MonitoredResource
log_idoptionalapisix.apache.org%2Flogsgoogle cloud logging id, refer to: LogEntry

The plugin supports the use of batch processors to aggregate and process entries(logs/data) in a batch. This avoids frequent data submissions by the plugin, which by default the batch processor submits data every 5 seconds or when the data in the queue reaches 1000. For information or custom batch processor parameter settings, see Batch-Processor configuration section.

How To Enable#

The following is an example of how to enable the google-cloud-logging for a specific route.

Full configuration#

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,            "buffer_duration":60,            "retry_delay":1,            "batch_max_size":1        }    },    "upstream": {        "type": "roundrobin",        "nodes": {            "127.0.0.1:1980": 1        }    },    "uri": "/hello"}'

Minimize configuration#

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"}'

Test Plugin#

  • Send request to route configured with the google-cloud-logging plugin
$ curl -i http://127.0.0.1:9080/helloHTTP/1.1 200 OK...hello, world
  • Login to Google Cloud to view logging service

Google Cloud Logging Service

Disable Plugin#

Disabling the google-cloud-logging plugin is very simple, just remove the JSON configuration corresponding to google-cloud-logging.

$ 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        }    }}'