google-cloud-logging
Summary#
Name#
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#
| Name | Requirement | Default | Description | 
|---|---|---|---|
| auth_config | Semi-optional | one of auth_config or auth_file must be configured | |
| auth_config.private_key | required | the private key parameters of the Google service account | |
| auth_config.project_id | required | the project id parameters of the Google service account | |
| auth_config.token_uri | optional | https://oauth2.googleapis.com/token | the token uri parameters of the Google service account | 
| auth_config.entries_uri | optional | https://logging.googleapis.com/v2/entries:write | google cloud logging service API | 
| auth_config.scopes | optional | ["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_file | semi-optional | path to the google service account json file(Semi-optional, one of auth_config or auth_file must be configured) | |
| ssl_verify | optional | true | enable SSL verification, option as per OpenResty docs | 
| resource | optional | {"type": "global"} | the Google monitor resource, refer to: MonitoredResource | 
| log_id | optional | apisix.apache.org%2Flogs | google cloud logging id, refer to: LogEntry | 
| max_retry_count | optional | 0 | max number of retries before removing from the processing pipe line | 
| retry_delay | optional | 1 | number of seconds the process execution should be delayed if the execution fails | 
| buffer_duration | optional | 60 | max age in seconds of the oldest entry in a batch before the batch must be processed | 
| inactive_timeout | optional | 5 | max age in seconds when the buffer will be flushed if inactive | 
| batch_max_size | optional | 1000 | max size of each batch | 
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-loggingplugin 
$ curl -i http://127.0.0.1:9080/hello
HTTP/1.1 200 OK
...
hello, world
- Login to Google Cloud to view 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
        }
    }
}'