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



##########
File path: t/plugin/error-log-logger-skywalking.t
##########
@@ -0,0 +1,201 @@
+#
+# 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();
+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
+--- 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";
+                    },
+                    "inactive_timeout": 1
+                }]]
+                )
+        }
+    }
+--- request
+GET /tg
+--- response_body
+--- no_error_log
+[error]
+
+
+
+=== TEST 5: log an error level message
+--- yaml_config
+plugins:
+  - error-log-logger
+--- config
+    location /tg {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            ngx.sleep(2)
+            core.log.error("this is an error message for test.")
+        }
+    }
+--- request
+GET /tg
+--- response_body
+--- error_log eval
+qr/.*\[\{\"body\":\{\"text\":\{\"text\":\".*this is an error message for 
test.*\"\}\},\"endpoint\":\"\",\"service\":\"APISIX\",\"serviceInstance\":\"APISIX
 Service Instance\".*/
+--- wait: 5
+
+
+
+=== TEST 6: delete metadata for the plugin, recover to the default
+--- 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_DELETE)
+
+            if code >= 300 then
+                ngx.status = code
+            end
+
+            ngx.say(body)
+        }
+    }
+--- request
+GET /tg
+--- response_body
+passed
+--- no_error_log
+[error]

Review comment:
       Please configure your editor to add a newline there

##########
File path: docs/en/latest/plugins/error-log-logger.md
##########
@@ -30,31 +30,39 @@ title: error-log-logger
 
 ## Name
 
-`error-log-logger` is a plugin which pushes the log data of APISIX's error.log 
to TCP servers.
+`error-log-logger` is a plugin which pushes the log data of APISIX's 
`error.log` to TCP servers or [Apache 
SkyWalking](https://skywalking.apache.org/).
 
-This plugin will provide the ability to send the log data which selected by 
the level to Monitoring tools and other TCP servers.
+This plugin will provide the ability to send the log data which selected by 
the level to Monitoring tools and other TCP servers, and SkyWalking over HTTP.
 
-This plugin provides the ability as a batch to push the log data to your 
external TCP servers. If not receive the log data, don't worry, it will 
automatically send the logs after the timer function expires in our Batch 
Processor.
+This plugin provides the ability as a batch to push the log data to your 
external TCP servers or monitoring tools. If not receive the log data, don't 
worry, it will automatically send the logs after the timer function expires in 
our Batch Processor.
 
 For more info on Batch-Processor in Apache APISIX please refer.
 [Batch-Processor](../batch-processor.md)
 
 ## Attributes
 
-| Name             | Type    | Requirement | Default | Valid   | Description   
                                                                           |
-| ---------------- | ------- | ----------- | ------- | ------- | 
----------------------------------------------------------------------------------------
 |
-| host             | string  | required    |         |         | IP address or 
the Hostname of the TCP server.                                            |
-| port             | integer | required    |         | [0,...] | Target 
upstream port.                                                                  
  |
-| timeout          | integer | optional    | 3       | [1,...] | Timeout for 
the upstream to connect and send, unit: second.                                 
                  |
-| keepalive        | integer | optional    | 30      | [1,...] | Time for 
keeping the cosocket alive, unit: second.                                       
            |
-| level            | string  | optional    | WARN    |         | The filter's 
log level, default warn, choose the level in ["STDERR", "EMERG", "ALERT", 
"CRIT", "ERR", "ERROR", "WARN", "NOTICE", "INFO", "DEBUG"], the value ERR 
equals ERROR.         |
-| tls              | boolean | optional    | false   |         | Control 
whether to perform SSL verification                                             
 |
-| tls_server_name  | string  | optional    |         |         | The server 
name for the new TLS extension  SNI                                             
               |
-| batch_max_size   | integer | optional    | 1000    | [1,...] | Max size of 
each batch                                                                   |
-| inactive_timeout | integer | optional    | 3       | [1,...] | Maximum age 
in seconds when the buffer will be flushed if inactive                       |
-| buffer_duration  | integer | optional    | 60      | [1,...] | Maximum age 
in seconds of the oldest entry in a batch before the batch must be processed |
-| max_retry_count  | integer | optional    | 0       | [0,...] | Maximum 
number of retries before removing from the processing pipe line                 
 |
-| retry_delay      | integer | optional    | 1       | [0,...] | Number of 
seconds the process execution should be delayed if the execution fails         |
+| Name                             | Type    | Requirement | Default           
             | Valid   | Description                                            
                                   |
+| -------------------------------- | ------- | ----------- | 
------------------------------ | ------- | 
-----------------------------------------------------------------------------------------
 |
+| tcp.host                         | string  | required    |                   
             |         | IP address or the Hostname of the TCP server.          
                                   |
+| tcp.port                         | integer | required    |                   
             | [0,...] | Target upstream port.                                  
                                   |
+| tcp.tls                          | boolean | optional    | false             
             |         | Control whether to perform SSL verification.           
                                   |
+| tcp.tls_server_name              | string  | optional    |                   
             |         | The server name for the new TLS extension  SNI.        
                                   |
+| skywalking.endpoint_addr         | string  | required    | 
http://127.0.0.1:12900/v3/logs |         | the http endpoint of Skywalking.     
                                                     |
+| skywalking.service_name          | string  | optional    | APISIX            
             |         | service name for skywalking reporter                   
                                   |
+| skywalking.service_instance_name | String  | optional    | APISIX Instance 
Name           |         | Service instance name for skywalking reporter, set 
it to `$hostname` to get local hostname directly.|
+| timeout                          | integer | optional    | 3                 
             | [1,...] | (`Deprecated`) Timeout for the upstream to connect and 
send, unit: second.                |
+| host                             | string  | optional    |                   
             |         | IP address or the Hostname of the TCP server.          
                                   |

Review comment:
       The host is deprecated but timeout isn't? Also, better to point out what 
field can be used instead of the deprecated one

##########
File path: t/plugin/error-log-logger.t
##########
@@ -157,8 +159,10 @@ plugins:
             local code, body = 
t('/apisix/admin/plugin_metadata/error-log-logger',
                 ngx.HTTP_PUT,
                 [[{
-                    "host": "127.0.0.1",
-                    "port": 9999,
+                    "tcp": {

Review comment:
       Need to keep some old test to check for the compatibility.

##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -134,6 +229,14 @@ local function update_filter(value)
 end
 
 
+local function send(data)
+    if config.tcp then

Review comment:
       Err... I think we should check skywalking first to avoid breaking the 
old configuration.




-- 
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