spacewander commented on a change in pull request #4633:
URL: https://github.com/apache/apisix/pull/4633#discussion_r677931605



##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -146,7 +248,19 @@ local function process()
             core.log.warn("set log filter failed for ", err)
             return
         end
-
+        if not config.tcp then

Review comment:
       Also need to filter out config.skywalking

##########
File path: docs/en/latest/plugins/error-log-logger.md
##########
@@ -96,8 +103,26 @@ Step: update the attributes of the plugin
 ```shell
 curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/error-log-logger -H 
'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
 {
-  "host": "127.0.0.1",
-  "port": 1999,
+  "tcp": {
+    "host": "127.0.0.1",
+    "port": 1999
+  },
+  "inactive_timeout": 1
+}'
+```
+
+## How to set the SkyWalking OAP server address
+
+Step: update the attributes of the plugin
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/error-log-logger -H 
'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+  "type": "SKYWALKING",
+  "skywalking": {
+    "host": "127.0.0.1",

Review comment:
       skywalking doesn't use host?

##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -36,23 +37,52 @@ local lrucache = core.lrucache.new({
 local metadata_schema = {
     type = "object",
     properties = {
-        host = schema_def.host_def,
-        port = {type = "integer", minimum = 0},
-        tls = {type = "boolean", default = false},
-        tls_server_name = {type = "string"},
-        timeout = {type = "integer", minimum = 1, default = 3},
-        keepalive = {type = "integer", minimum = 1, default = 30},
+        type = {type = "string", default = "TCP", enum = {"TCP", 
"SKYWALKING"}},
+        tcp = {
+            type = "object",
+            properties = {
+                host = schema_def.host_def,
+                port = {type = "integer", minimum = 0},
+                tls = {type = "boolean", default = false},
+                tls_server_name = {type = "string"},
+            },
+            required = {"host", "port"}
+        },
+        skywalking = {
+            type = "object",
+            properties = {
+                endpoint_addr = {schema_def.uri, default = 
"http://127.0.0.1:12900/v3/logs"},
+                service_name = {type = "string", default = "APISIX"},
+                service_instance_name = {type="string", default = "APISIX 
Service Instance"},
+            },
+            required = {"endpoint_addr"}

Review comment:
       Once you provide a default value, the field is actually optional, as 
users don't need to specify their values.

##########
File path: t/plugin/error-log-logger-skywalking.t
##########
@@ -0,0 +1,232 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use t::APISIX 'no_plan';
+
+log_level('debug');
+repeat_each(1);
+no_long_string();
+no_root_location();
+worker_connections(128);
+run_tests;
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+    location /t {
+        content_by_lua_block {
+        local core = require("apisix.core")
+            local plugin = require("apisix.plugins.error-log-logger")
+            local ok, err = plugin.check_schema(
+                {
+                    skywalking = {
+                        endpoint_addr = "http://127.0.0.1";
+                    }
+                },
+                core.schema.TYPE_METADATA
+            )
+            if not ok then
+                ngx.say(err)
+            end
+
+            ngx.say("done")
+        }
+    }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test schema checker, missing required field
+--- config
+    location /t {
+        content_by_lua_block {
+        local core = require("apisix.core")
+            local plugin = require("apisix.plugins.error-log-logger")
+            local ok, err = plugin.check_schema(
+                {
+                    skywalking = {
+                        service = "APISIX"
+                    }
+                },
+                core.schema.TYPE_METADATA
+            )
+            if not ok then
+                ngx.say(err)
+            end
+
+            ngx.say("done")
+        }
+    }
+--- request
+GET /t
+--- response_body
+property "skywalking" validation failed: property "endpoint_addr" is required
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 3: test unreachable server
+--- yaml_config
+apisix:
+    enable_admin: true
+    admin_key: null
+plugins:
+  - error-log-logger
+--- config
+    location /tg {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            local t = require("lib.test_admin").test
+            local code, body = 
t('/apisix/admin/plugin_metadata/error-log-logger',
+                ngx.HTTP_PUT,
+                [[{
+                    "skywalking": {
+                        "endpoint_addr": "http://127.0.0.1:1988/log";
+                    },
+                    "inactive_timeout": 1
+                }]]
+                )
+            ngx.sleep(2)
+            core.log.warn("this is a warning message for test.")
+        }
+    }
+--- request
+GET /tg
+--- response_body
+--- error_log eval
+qr/.*\[lua\] batch-processor.lua:63: Batch Processor\[error-log-logger\] 
failed to process entries: error while sending data to 
skywalking\[http:\/\/127.0.0.1:1988\/log\] connection refused, context: 
ngx.timer/
+--- wait: 3
+
+
+
+=== TEST 4: put plugin metadata and log an error level message
+--- yaml_config
+apisix:
+    enable_admin: true
+    admin_key: null
+plugins:
+  - error-log-logger
+--- config
+    location /tg {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            local t = require("lib.test_admin").test
+            local code, body = 
t('/apisix/admin/plugin_metadata/error-log-logger',
+                ngx.HTTP_PUT,
+                [[{
+                    "skywalking": {
+                        "endpoint_addr": "http://127.0.0.1:1982/log";,
+                        "service_instance_name": "instance"
+                    },
+                    "batch_max_size": 15,
+                    "inactive_timeout": 1
+                }]]
+                )
+            ngx.sleep(2)
+            core.log.error("this is an error message for test.")

Review comment:
       Need a test for multiple error logs

##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -36,23 +37,52 @@ local lrucache = core.lrucache.new({
 local metadata_schema = {
     type = "object",
     properties = {
-        host = schema_def.host_def,
-        port = {type = "integer", minimum = 0},
-        tls = {type = "boolean", default = false},
-        tls_server_name = {type = "string"},
-        timeout = {type = "integer", minimum = 1, default = 3},
-        keepalive = {type = "integer", minimum = 1, default = 30},
+        type = {type = "string", default = "TCP", enum = {"TCP", 
"SKYWALKING"}},

Review comment:
       The type field is unused now?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to