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 2021/11/11 06:21:13 UTC

[GitHub] [apisix] bisakhmondal opened a new pull request #5480: refactor: Method for latency calculation and related refactoring

bisakhmondal opened a new pull request #5480:
URL: https://github.com/apache/apisix/pull/5480


   ### 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. -->
   - Separate utility method for latency calculation.
   - Refactor datadog and Prometheus plugin to use the same
   
   ### Pre-submission checklist:
   
   <!--
   Please follow the requirements:
   1. Use Draft if the PR is not ready to be reviewed
   2. Test is required for the feat/fix PR, unless you have a good reason
   3. Doc is required for the feat PR
   4. Use a new commit to resolve review instead of `push -f`
   5. Use "request review" to notify the reviewer once you have resolved the review
   -->
   
   * [x] Did you explain what problem does this PR solve? Or what new features have been added?
   * [ ] 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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] spacewander commented on a change in pull request #5480: refactor: Method for latency calculation and related refactoring

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



##########
File path: apisix/utils/log-util.lua
##########
@@ -153,4 +153,27 @@ function _M.get_req_original(ctx, conf)
 end
 
 
+function _M.latency_details_in_ms(ctx)
+    local latency = (ngx.now() - ngx.req.start_time()) * 1000
+    local upstream_latency, apisix_latency = nil, latency
+
+    if ctx.var.upstream_response_time then
+        upstream_latency = ctx.var.upstream_response_time * 1000
+        apisix_latency = apisix_latency - upstream_latency
+
+        -- The latency might be negative, as Nginx uses different time measurements in
+        -- different metrics.
+        -- See https://github.com/apache/apisix/issues/5146#issuecomment-928919399
+        if apisix_latency < 0 then
+            apisix_latency = 0
+        end
+    end
+
+    return {

Review comment:
       We can return multiple results directly in Lua.




-- 
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: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] bisakhmondal commented on a change in pull request #5480: refactor: Method for latency calculation and related refactoring

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



##########
File path: apisix/utils/log-util.lua
##########
@@ -153,4 +153,27 @@ function _M.get_req_original(ctx, conf)
 end
 
 
+function _M.latency_details_in_ms(ctx)
+    local latency = (ngx.now() - ngx.req.start_time()) * 1000
+    local upstream_latency, apisix_latency = nil, latency
+
+    if ctx.var.upstream_response_time then
+        upstream_latency = ctx.var.upstream_response_time * 1000
+        apisix_latency = apisix_latency - upstream_latency
+
+        -- The latency might be negative, as Nginx uses different time measurements in
+        -- different metrics.
+        -- See https://github.com/apache/apisix/issues/5146#issuecomment-928919399
+        if apisix_latency < 0 then
+            apisix_latency = 0
+        end
+    end
+
+    return {

Review comment:
       Yes. But in this case, I thought a map would be efficient It's easy to pick the respective value through key without checking which param represents what latency. 
   If you suggest, updating the signature. 




-- 
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: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] bisakhmondal commented on a change in pull request #5480: refactor: Method for latency calculation and related refactoring

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



##########
File path: apisix/utils/log-util.lua
##########
@@ -153,4 +153,27 @@ function _M.get_req_original(ctx, conf)
 end
 
 
+function _M.latency_details_in_ms(ctx)
+    local latency = (ngx.now() - ngx.req.start_time()) * 1000
+    local upstream_latency, apisix_latency = nil, latency
+
+    if ctx.var.upstream_response_time then
+        upstream_latency = ctx.var.upstream_response_time * 1000
+        apisix_latency = apisix_latency - upstream_latency
+
+        -- The latency might be negative, as Nginx uses different time measurements in
+        -- different metrics.
+        -- See https://github.com/apache/apisix/issues/5146#issuecomment-928919399
+        if apisix_latency < 0 then
+            apisix_latency = 0
+        end
+    end
+
+    return {

Review comment:
       Done




-- 
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: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] spacewander merged pull request #5480: refactor: Method for latency calculation and related refactoring

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


   


-- 
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: notifications-unsubscribe@apisix.apache.org

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