You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/12/17 13:24:42 UTC

[GitHub] [apisix] gy09535 opened a new pull request #3070: feat:add batch process metrics

gy09535 opened a new pull request #3070:
URL: https://github.com/apache/apisix/pull/3070


   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   fix: https://github.com/apache/apisix/issues/2693
   
   add metric for batch process, such as:  sls logger, tcp logger ,udp logger , http logger, sys logger. 
   with this feature, users can use the metrics find how many entries remaining in batch process.
   ### Pre-submission checklist:
   
   * [x ] Did you explain what problem does this PR solve? Or what new features have been added?
   * [x] Have you added corresponding test cases?
   * [ ] Have you modified the corresponding document?
   * [x] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander merged pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #3070:
URL: https://github.com/apache/apisix/pull/3070


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] gy09535 commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
gy09535 commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r548426208



##########
File path: doc/plugins/prometheus.md
##########
@@ -125,6 +125,7 @@ Or you can goto [Grafana official](https://grafana.com/grafana/dashboards/11719)
 * `Bandwidth`: Total Bandwidth (egress/ingress) flowing through apisix. This metric is available per service and as a sum across all services.
 * `etcd reachability`: A gauge type with a value of 0 or 1, representing if etcd can be reached by a apisix or not.
 * `Connections`: Various Nginx connection metrics like active, reading, writing, and number of accepted connections.
+* `Batch process entries`: A gauge type, when we use plugins such as: sys logger, http logger, sls logger, tcp logger, udp logger and zipkin, the surplus entries which not sended will be statistics in the metrics.

Review comment:
       changed.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r546366105



##########
File path: apisix/utils/batch-processor.lua
##########
@@ -146,8 +150,20 @@ function batch_processor:push(entry)
         return
     end
 
+    if not batch_metrics and prometheus.get_prometheus() and self.name
+       and self.route_id and self.server_addr then
+        batch_metrics = prometheus.get_prometheus():gauge("batch_process_entries",
+                                                          "batch process remaining entries",
+                                                          {"name", "route_id", "server_addr"})
+    end
+
     local entries = self.entry_buffer.entries
     table.insert(entries, entry)
+    -- add batch metric for every route
+    if batch_metrics  then
+        local label = {self.name, self.route_id, self.server_addr}

Review comment:
       Look like we can store the `label` in `self`?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r548411407



##########
File path: doc/plugins/prometheus.md
##########
@@ -125,6 +125,7 @@ Or you can goto [Grafana official](https://grafana.com/grafana/dashboards/11719)
 * `Bandwidth`: Total Bandwidth (egress/ingress) flowing through apisix. This metric is available per service and as a sum across all services.
 * `etcd reachability`: A gauge type with a value of 0 or 1, representing if etcd can be reached by a apisix or not.
 * `Connections`: Various Nginx connection metrics like active, reading, writing, and number of accepted connections.
+* `Batch process entries`: A gauge type, when we use plugins such as: sys logger, http logger, sls logger, tcp logger, udp logger and zipkin, the surplus entries which not sended will be statistics in the metrics.

Review comment:
       Should mention the batch processor.
   Some suggestions:
   `surplus entries` => `entries`
   `not sended` => `hasn't been sent`
   `statistics` => `counted`




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] gy09535 commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
gy09535 commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r546480734



##########
File path: apisix/utils/batch-processor.lua
##########
@@ -146,8 +150,20 @@ function batch_processor:push(entry)
         return
     end
 
+    if not batch_metrics and prometheus.get_prometheus() and self.name
+       and self.route_id and self.server_addr then
+        batch_metrics = prometheus.get_prometheus():gauge("batch_process_entries",
+                                                          "batch process remaining entries",
+                                                          {"name", "route_id", "server_addr"})
+    end
+
     local entries = self.entry_buffer.entries
     table.insert(entries, entry)
+    -- add batch metric for every route
+    if batch_metrics  then
+        local label = {self.name, self.route_id, self.server_addr}

Review comment:
       fixed.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r546466864



##########
File path: t/plugin/prometheus.t
##########
@@ -1088,3 +1088,207 @@ GET /apisix/prometheus/metrics
 --- error_code: 200
 --- no_error_log
 [error]
+
+
+
+=== TEST 62: set batch plugins
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/9',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "prometheus": {},
+                            "syslog": {
+			                    "host": "127.0.0.1",
+			                    "include_req_body": false,
+			                    "max_retry_times": 1,
+			                    "tls": false,
+			                    "retry_interval": 1,
+			                    "batch_max_size": 1000,
+			                    "buffer_duration": 60,
+			                    "port": 0,
+			                    "name": "sys-logger",
+			                    "flush_limit": 4096,
+			                    "sock_type": "tcp",
+			                    "timeout": 3,
+			                    "drop_limit": 1048576,
+			                    "pool_size": 5
+		                    },
+                            "zipkin": {
+                                "endpoint": "http://127.0.0.1:9447",
+                                "service_name": "APISIX",
+                                "sample_ratio": 1
+                            },
+                            "http-logger": {
+                                "inactive_timeout": 5,
+                                "include_req_body": false,
+                                "timeout": 3,
+                                "name": "http-logger",
+                                "retry_delay": 1,
+                                "buffer_duration": 60,
+                                "uri": "http://127.0.0.1:19080/report",
+                                "concat_method": "json",
+                                "batch_max_size": 1000,
+                                "max_retry_count": 0
+                            }                          
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uris": ["/batch-process-metrics"]
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 63: hit batch-process-metrics
+--- request
+GET /batch-process-metrics
+--- error_code: 404
+
+
+
+=== TEST 64: check sys logger metrics
+--- request
+GET /apisix/prometheus/metrics
+--- error_code: 200
+--- response_body_like eval
+qr/apisix_batch_process_entries{name="sys-logger",route_id="9"/

Review comment:
       Escape `{`?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] Firstsawyou commented on pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
Firstsawyou commented on pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#issuecomment-747810787


   The test case reported an error and we need to resolve it. ^ _ ^


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] gy09535 commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
gy09535 commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r548366235



##########
File path: t/plugin/prometheus.t
##########
@@ -1088,3 +1088,207 @@ GET /apisix/prometheus/metrics
 --- error_code: 200
 --- no_error_log
 [error]
+
+
+
+=== TEST 62: set batch plugins
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/9',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "prometheus": {},
+                            "syslog": {
+			                    "host": "127.0.0.1",
+			                    "include_req_body": false,
+			                    "max_retry_times": 1,
+			                    "tls": false,
+			                    "retry_interval": 1,
+			                    "batch_max_size": 1000,
+			                    "buffer_duration": 60,
+			                    "port": 0,
+			                    "name": "sys-logger",
+			                    "flush_limit": 4096,
+			                    "sock_type": "tcp",
+			                    "timeout": 3,
+			                    "drop_limit": 1048576,
+			                    "pool_size": 5
+		                    },
+                            "zipkin": {
+                                "endpoint": "http://127.0.0.1:9447",
+                                "service_name": "APISIX",
+                                "sample_ratio": 1
+                            },
+                            "http-logger": {
+                                "inactive_timeout": 5,
+                                "include_req_body": false,
+                                "timeout": 3,
+                                "name": "http-logger",
+                                "retry_delay": 1,
+                                "buffer_duration": 60,
+                                "uri": "http://127.0.0.1:19080/report",
+                                "concat_method": "json",
+                                "batch_max_size": 1000,
+                                "max_retry_count": 0
+                            }                          
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uris": ["/batch-process-metrics"]
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 63: hit batch-process-metrics
+--- request
+GET /batch-process-metrics
+--- error_code: 404
+
+
+
+=== TEST 64: check sys logger metrics
+--- request
+GET /apisix/prometheus/metrics
+--- error_code: 200
+--- response_body_like eval
+qr/apisix_batch_process_entries{name="sys-logger",route_id="9"/

Review comment:
       plugin set error. 😄




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] gy09535 commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
gy09535 commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r548366235



##########
File path: t/plugin/prometheus.t
##########
@@ -1088,3 +1088,207 @@ GET /apisix/prometheus/metrics
 --- error_code: 200
 --- no_error_log
 [error]
+
+
+
+=== TEST 62: set batch plugins
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/9',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "prometheus": {},
+                            "syslog": {
+			                    "host": "127.0.0.1",
+			                    "include_req_body": false,
+			                    "max_retry_times": 1,
+			                    "tls": false,
+			                    "retry_interval": 1,
+			                    "batch_max_size": 1000,
+			                    "buffer_duration": 60,
+			                    "port": 0,
+			                    "name": "sys-logger",
+			                    "flush_limit": 4096,
+			                    "sock_type": "tcp",
+			                    "timeout": 3,
+			                    "drop_limit": 1048576,
+			                    "pool_size": 5
+		                    },
+                            "zipkin": {
+                                "endpoint": "http://127.0.0.1:9447",
+                                "service_name": "APISIX",
+                                "sample_ratio": 1
+                            },
+                            "http-logger": {
+                                "inactive_timeout": 5,
+                                "include_req_body": false,
+                                "timeout": 3,
+                                "name": "http-logger",
+                                "retry_delay": 1,
+                                "buffer_duration": 60,
+                                "uri": "http://127.0.0.1:19080/report",
+                                "concat_method": "json",
+                                "batch_max_size": 1000,
+                                "max_retry_count": 0
+                            }                          
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uris": ["/batch-process-metrics"]
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 63: hit batch-process-metrics
+--- request
+GET /batch-process-metrics
+--- error_code: 404
+
+
+
+=== TEST 64: check sys logger metrics
+--- request
+GET /apisix/prometheus/metrics
+--- error_code: 200
+--- response_body_like eval
+qr/apisix_batch_process_entries{name="sys-logger",route_id="9"/

Review comment:
       plugin set error 😄




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] gy09535 commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
gy09535 commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r546316126



##########
File path: apisix/plugins/prometheus/exporter.lua
##########
@@ -45,10 +45,10 @@ local DEFAULT_BUCKETS = { 1, 2, 5, 7, 10, 15, 20, 25, 30, 40, 50, 60, 70,
 local metrics = {}
 
 
-    local inner_tab_arr = {}
-local function gen_arr(...)
-    clear_tab(inner_tab_arr)
 
+local function gen_arr(...)

Review comment:
       got it.

##########
File path: apisix/utils/batch-processor.lua
##########
@@ -146,8 +150,19 @@ function batch_processor:push(entry)
         return
     end
 
+    if not batch_metrics and prometheus.get_prometheus() and self.name
+       and self.route_id and self.server_addr then
+        batch_metrics = prometheus.get_prometheus():gauge("batch_process_entries",
+                                                          "batch process remaining entries",
+                                                          {"name", "route_id", "server_addr"})
+    end
+
     local entries = self.entry_buffer.entries
     table.insert(entries, entry)
+    -- add batch metric for every route
+    if batch_metrics  then
+        batch_metrics:set(#entries, prometheus.gen_arr(self.name, self.route_id, self.server_addr))

Review comment:
       fixed.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r545098278



##########
File path: apisix/plugins/prometheus/exporter.lua
##########
@@ -45,10 +45,10 @@ local DEFAULT_BUCKETS = { 1, 2, 5, 7, 10, 15, 20, 25, 30, 40, 50, 60, 70,
 local metrics = {}
 
 
-    local inner_tab_arr = {}
-local function gen_arr(...)
-    clear_tab(inner_tab_arr)
 
+local function gen_arr(...)

Review comment:
       We don't need this if we can't share the table.

##########
File path: apisix/utils/batch-processor.lua
##########
@@ -146,8 +150,19 @@ function batch_processor:push(entry)
         return
     end
 
+    if not batch_metrics and prometheus.get_prometheus() and self.name
+       and self.route_id and self.server_addr then
+        batch_metrics = prometheus.get_prometheus():gauge("batch_process_entries",
+                                                          "batch process remaining entries",
+                                                          {"name", "route_id", "server_addr"})
+    end
+
     local entries = self.entry_buffer.entries
     table.insert(entries, entry)
+    -- add batch metric for every route
+    if batch_metrics  then
+        batch_metrics:set(#entries, prometheus.gen_arr(self.name, self.route_id, self.server_addr))

Review comment:
       We can store the table: `self.xxx = {self.name, self.route_id, self.server_addr}`.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r548366160



##########
File path: apisix/utils/batch-processor.lua
##########
@@ -146,8 +150,20 @@ function batch_processor:push(entry)
         return
     end
 
+    if not batch_metrics and prometheus.get_prometheus() and self.name
+       and self.route_id and self.server_addr then
+        batch_metrics = prometheus.get_prometheus():gauge("batch_process_entries",
+                                                          "batch process remaining entries",

Review comment:
       We need to update the https://github.com/apache/apisix/blob/master/doc/plugins/prometheus.md#available-metrics




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] gy09535 commented on a change in pull request #3070: feat: add batch process metrics

Posted by GitBox <gi...@apache.org>.
gy09535 commented on a change in pull request #3070:
URL: https://github.com/apache/apisix/pull/3070#discussion_r548408386



##########
File path: apisix/utils/batch-processor.lua
##########
@@ -146,8 +150,20 @@ function batch_processor:push(entry)
         return
     end
 
+    if not batch_metrics and prometheus.get_prometheus() and self.name
+       and self.route_id and self.server_addr then
+        batch_metrics = prometheus.get_prometheus():gauge("batch_process_entries",
+                                                          "batch process remaining entries",

Review comment:
       added.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org