google-cloud-logging

Description

The google-cloud-logging Plugin is used to send APISIX access logs to Google Cloud Logging Service.

This plugin also allows to push logs as a batch to your Google Cloud Logging Service. It might take some time to receive the log data. It will be automatically sent after the timer function in the batch processor expires.

Attributes

NameRequiredDefaultDescription
auth_configTrueEither auth_config or auth_file must be provided.
auth_config.private_keyTruePrivate key of the Google Cloud service account.
auth_config.project_idTrueProject ID in the Google Cloud service account.
auth_config.token_uriTruehttps://oauth2.googleapis.com/tokenToken URI of the Google Cloud service account.
auth_config.entries_uriFalsehttps://logging.googleapis.com/v2/entries:writeGoogle Cloud Logging Service API.
auth_config.scopesFalse[“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“]Access scopes of the Google Cloud service account. See OAuth 2.0 Scopes for Google APIs.
auth_fileTruePath to the Google Cloud service account authentication JSON file. Either auth_config or auth_file must be provided.
ssl_verifyFalsetrueWhen set to true, enables SSL verification as mentioned in OpenResty docs.
resourceFalse{“type”: “global”}Google monitor resource. See MonitoredResource for more details.
log_idFalseapisix.apache.org%2FlogsGoogle Cloud logging ID. See LogEntry for details.

NOTE: encrypt_fields = {"auth_config.private_key"} is also defined in the schema, which means that the field will be stored encrypted in etcd. See encrypted storage fields.

This Plugin supports using batch processors to aggregate and process entries (logs/data) in a batch. This avoids the need for frequently submitting the data. The batch processor submits data every 5 seconds or when the data in the queue reaches 1000. See Batch Processor for more information or setting your custom configuration.

Enabling the Plugin

Full configuration

The example below shows a complete configuration of the Plugin on a specific Route:

  1. curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "plugins": {
  4. "google-cloud-logging": {
  5. "auth_config":{
  6. "project_id":"apisix",
  7. "private_key":"-----BEGIN RSA PRIVATE KEY-----your private key-----END RSA PRIVATE KEY-----",
  8. "token_uri":"https://oauth2.googleapis.com/token",
  9. "scopes":[
  10. "https://www.googleapis.com/auth/logging.admin"
  11. ],
  12. "entries_uri":"https://logging.googleapis.com/v2/entries:write"
  13. },
  14. "resource":{
  15. "type":"global"
  16. },
  17. "log_id":"apisix.apache.org%2Flogs",
  18. "inactive_timeout":10,
  19. "max_retry_count":0,
  20. "buffer_duration":60,
  21. "retry_delay":1,
  22. "batch_max_size":1
  23. }
  24. },
  25. "upstream": {
  26. "type": "roundrobin",
  27. "nodes": {
  28. "127.0.0.1:1980": 1
  29. }
  30. },
  31. "uri": "/hello"
  32. }'

Minimal configuration

The example below shows a bare minimum configuration of the Plugin on a Route:

  1. curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "plugins": {
  4. "google-cloud-logging": {
  5. "auth_config":{
  6. "project_id":"apisix",
  7. "private_key":"-----BEGIN RSA PRIVATE KEY-----your private key-----END RSA PRIVATE KEY-----"
  8. }
  9. }
  10. },
  11. "upstream": {
  12. "type": "roundrobin",
  13. "nodes": {
  14. "127.0.0.1:1980": 1
  15. }
  16. },
  17. "uri": "/hello"
  18. }'

Example usage

Now, if you make a request to APISIX, it will be logged in your Google Cloud Logging Service.

  1. curl -i http://127.0.0.1:9080/hello

You can then login and view the logs in Google Cloud Logging Service.

Disable Plugin

To disable the google-cloud-logging Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.

  1. curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "uri": "/hello",
  4. "plugins": {},
  5. "upstream": {
  6. "type": "roundrobin",
  7. "nodes": {
  8. "127.0.0.1:1980": 1
  9. }
  10. }
  11. }'