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

  1. curl http://127.0.0.1:9080/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. }'

Minimize configuration

  1. curl http://127.0.0.1:9080/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. }'

Test Plugin

  • Send request to route configured with the google-cloud-logging plugin
  1. $ curl -i http://127.0.0.1:9080/hello
  2. HTTP/1.1 200 OK
  3. ...
  4. 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.

  1. $ curl http://127.0.0.1:9080/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. }'