This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 019eca7 fix: google cloud logging plugin file config error (#5646)
019eca7 is described below
commit 019eca71b31de632541d9f1fe41666f9531d394b
Author: 帅进超 <[email protected]>
AuthorDate: Wed Dec 1 08:52:42 2021 +0800
fix: google cloud logging plugin file config error (#5646)
---
apisix/plugins/google-cloud-logging.lua | 4 +-
t/plugin/google-cloud-logging.t | 96 +++++++++++++++++++++++++++++++
t/plugin/google-cloud-logging/config.json | 9 +++
3 files changed, 107 insertions(+), 2 deletions(-)
diff --git a/apisix/plugins/google-cloud-logging.lua
b/apisix/plugins/google-cloud-logging.lua
index f007e9b..961762d 100644
--- a/apisix/plugins/google-cloud-logging.lua
+++ b/apisix/plugins/google-cloud-logging.lua
@@ -187,7 +187,7 @@ local function get_auth_config(config)
local file_content, err = core.io.get_file(config.auth_file)
if not file_content then
- return nil, "failed to read configuration, file: " .. config.auth_file
.. " err:" .. err
+ return nil, "failed to read configuration, file: " .. config.auth_file
.. " err: " .. err
end
local config_data
@@ -196,7 +196,7 @@ local function get_auth_config(config)
return nil, "config parse failure, data: " .. file_content .. " , err:
" .. err
end
- auth_config_cache = config.auth_config
+ auth_config_cache = config_data
return auth_config_cache
end
diff --git a/t/plugin/google-cloud-logging.t b/t/plugin/google-cloud-logging.t
index 1b8a893..202e28c 100644
--- a/t/plugin/google-cloud-logging.t
+++ b/t/plugin/google-cloud-logging.t
@@ -509,3 +509,99 @@ qr/\{\"error\"\:\"[\w+\s+]*\"\}/
--- error_log
Batch Processor[google-cloud-logging] failed to process entries
Batch Processor[google-cloud-logging] exceeded the max_retry_count
+
+
+
+=== TEST 16: set route (file configuration is successful)
+--- config
+ location /t {
+ content_by_lua_block {
+
+ local config = {
+ uri = "/hello",
+ upstream = {
+ type = "roundrobin",
+ nodes = {
+ ["127.0.0.1:1980"] = 1
+ }
+ },
+ plugins = {
+ ["google-cloud-logging"] = {
+ auth_file =
"t/plugin/google-cloud-logging/config.json",
+ inactive_timeout = 1,
+ batch_max_size = 1,
+ }
+ }
+ }
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT,
config)
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 17: test route(file configuration is successful)
+--- request
+GET /hello
+--- wait: 2
+--- response_body
+hello world
+
+
+
+=== TEST 18: set route (file configuration is failed)
+--- config
+ location /t {
+ content_by_lua_block {
+
+ local config = {
+ uri = "/hello",
+ upstream = {
+ type = "roundrobin",
+ nodes = {
+ ["127.0.0.1:1980"] = 1
+ }
+ },
+ plugins = {
+ ["google-cloud-logging"] = {
+ auth_file = "google-cloud-logging/config.json",
+ inactive_timeout = 1,
+ batch_max_size = 1,
+ }
+ }
+ }
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT,
config)
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 19: test route(file configuration is failed)
+--- request
+GET /hello
+--- wait: 2
+--- response_body
+hello world
+--- error_log
+config.json: No such file or directory
diff --git a/t/plugin/google-cloud-logging/config.json
b/t/plugin/google-cloud-logging/config.json
new file mode 100644
index 0000000..015dab2
--- /dev/null
+++ b/t/plugin/google-cloud-logging/config.json
@@ -0,0 +1,9 @@
+{
+ "private_key": "-----BEGIN RSA PRIVATE
KEY-----\nMIIBOgIBAAJBAKebDxlvQMGyEesAL1r1nIJBkSdqu3Hr7noq/0ukiZqVQLSJPMOv\n0oxQSutvvK3hoibwGakDOza+xRITB7cs2cECAwEAAQJAYPWh6YvjwWobVYC45Hz7\n+pqlt1DWeVQMlN407HSWKjdH548ady46xiQuZ5Cfx3YyCcnsfVWaQNbC+jFbY4YL\nwQIhANfASwz8+2sKg1xtvzyaChX5S5XaQTB+azFImBJumixZAiEAxt93Td6JH1RF\nIeQmD/K+DClZMqSrliUzUqJnCPCzy6kCIAekDsRh/UF4ONjAJkKuLedDUfL3rNFb\n2M4BBSm58wnZAiEAwYLMOg8h6kQ7iMDRcI9I8diCHM8yz0SfbfbsvzxIFxECICXs\nYvIufaZvBa8f+E/9CANlVhm5wKAyM8N8GJsiCyEG\n---
[...]
+ "project_id": "apisix",
+ "token_uri": "http://127.0.0.1:1980/google/logging/token",
+ "scopes": [
+ "https://apisix.apache.org/logs:admin"
+ ],
+ "entries_uri": "http://127.0.0.1:1980/google/logging/entries"
+}