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/12/15 07:31:58 UTC
[GitHub] [apisix] shuaijinchao opened a new pull request #5820: fix(sls-logger): log entry unable get millisecond timestamp
shuaijinchao opened a new pull request #5820:
URL: https://github.com/apache/apisix/pull/5820
### 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. -->
log entry unable get millisecond timestamp
### 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. If you need to resolve merge conflicts after the PR is reviewed, please merge master but do not rebase
6. 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?
* [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.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] shuaijinchao commented on a change in pull request #5820: fix(sls-logger): log entry unable get millisecond timestamp
Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on a change in pull request #5820:
URL: https://github.com/apache/apisix/pull/5820#discussion_r770255083
##########
File path: t/plugin/sls-logger.t
##########
@@ -188,9 +184,41 @@ hello world
ngx.say(data)
}
}
---- request
-GET /t
--- response_body
123
---- no_error_log
-[error]
+
+
+
+=== TEST 7: sls log get milliseconds
+--- config
+ location /t {
+ content_by_lua_block {
+ local function get_syslog_timestamp_millisecond(log_entry)
+ local first_idx = string.find(log_entry, " ") + 1
+ local last_idx2 = string.find(log_entry, " ", first_idx)
+ local rfc3339_date = string.sub(log_entry, first_idx, last_idx2)
+ local rfc3339_len = string.len(rfc3339_date)
+ local rfc3339_millisecond = string.sub(rfc3339_date, rfc3339_len - 4, rfc3339_len - 2)
+ return tonumber(rfc3339_millisecond)
+ end
+
+ math.randomseed(os.time())
+ local rfc5424 = require("apisix.plugins.slslog.rfc5424")
+ local m = 0
+ for i = 1, 5 do
+ ngx.sleep(string.format("%0.3f", math.random()))
Review comment:
Because `ngx.now` may have a millisecond value of `0`, perform multiple tests to ensure that the final result meets expectations.
--
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 #5820: fix(sls-logger): log entry unable get millisecond timestamp
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #5820:
URL: https://github.com/apache/apisix/pull/5820#discussion_r770344198
##########
File path: t/plugin/sls-logger.t
##########
@@ -188,9 +184,41 @@ hello world
ngx.say(data)
}
}
---- request
-GET /t
--- response_body
123
---- no_error_log
-[error]
+
+
+
+=== TEST 7: sls log get milliseconds
+--- config
+ location /t {
+ content_by_lua_block {
+ local function get_syslog_timestamp_millisecond(log_entry)
+ local first_idx = string.find(log_entry, " ") + 1
+ local last_idx2 = string.find(log_entry, " ", first_idx)
+ local rfc3339_date = string.sub(log_entry, first_idx, last_idx2)
+ local rfc3339_len = string.len(rfc3339_date)
+ local rfc3339_millisecond = string.sub(rfc3339_date, rfc3339_len - 4, rfc3339_len - 2)
+ return tonumber(rfc3339_millisecond)
+ end
+
+ math.randomseed(os.time())
+ local rfc5424 = require("apisix.plugins.slslog.rfc5424")
+ local m = 0
+ for i = 1, 5 do
+ ngx.sleep(string.format("%0.3f", math.random()))
Review comment:
Let's add this explanation as a comment.
--
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] shuaijinchao commented on a change in pull request #5820: fix(sls-logger): log entry unable get millisecond timestamp
Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on a change in pull request #5820:
URL: https://github.com/apache/apisix/pull/5820#discussion_r770352424
##########
File path: t/plugin/sls-logger.t
##########
@@ -188,9 +184,41 @@ hello world
ngx.say(data)
}
}
---- request
-GET /t
--- response_body
123
---- no_error_log
-[error]
+
+
+
+=== TEST 7: sls log get milliseconds
+--- config
+ location /t {
+ content_by_lua_block {
+ local function get_syslog_timestamp_millisecond(log_entry)
+ local first_idx = string.find(log_entry, " ") + 1
+ local last_idx2 = string.find(log_entry, " ", first_idx)
+ local rfc3339_date = string.sub(log_entry, first_idx, last_idx2)
+ local rfc3339_len = string.len(rfc3339_date)
+ local rfc3339_millisecond = string.sub(rfc3339_date, rfc3339_len - 4, rfc3339_len - 2)
+ return tonumber(rfc3339_millisecond)
+ end
+
+ math.randomseed(os.time())
+ local rfc5424 = require("apisix.plugins.slslog.rfc5424")
+ local m = 0
+ for i = 1, 5 do
+ ngx.sleep(string.format("%0.3f", math.random()))
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] shuaijinchao commented on a change in pull request #5820: fix(sls-logger): log entry unable get millisecond timestamp
Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on a change in pull request #5820:
URL: https://github.com/apache/apisix/pull/5820#discussion_r769573844
##########
File path: t/plugin/sls-logger.t
##########
@@ -188,9 +184,38 @@ hello world
ngx.say(data)
}
}
---- request
-GET /t
--- response_body
123
---- no_error_log
-[error]
+
+
+
+=== TEST 7: sls log get milliseconds
+--- config
+ location /t {
+ content_by_lua_block {
+ local function get_syslog_timestamp_millisecond(sls_log)
+ local first_idx = string.find(sls_log, " ") + 1
+ local last_idx2 = string.find(sls_log, " ", first_idx)
+ local rfc3339_date = string.sub(sls_log, first_idx, last_idx2)
+ local rfc3339_len = string.len(rfc3339_date)
+ local rfc3339_millisecond = string.sub(rfc3339_date, rfc3339_len - 4, rfc3339_len - 2)
+ return tonumber(rfc3339_millisecond)
+ end
+
+ local rfc5424 = require("apisix.plugins.slslog.rfc5424")
+ local m = 0
+ for _ = 1, 10 do
+ local sls_log = rfc5424.encode("SYSLOG", "INFO", "localhost", "apisix",
+ 123456, "apisix.apache.org", "apisix.apache.log",
+ "apisix.sls.logger", "BD274822-96AA-4DA6-90EC-15940FB24444",
+ "hello world")
Review comment:
updated
--
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 #5820: fix(sls-logger): log entry unable get millisecond timestamp
Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #5820:
URL: https://github.com/apache/apisix/pull/5820
--
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 #5820: fix(sls-logger): log entry unable get millisecond timestamp
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #5820:
URL: https://github.com/apache/apisix/pull/5820#discussion_r769541265
##########
File path: t/plugin/sls-logger.t
##########
@@ -188,9 +184,38 @@ hello world
ngx.say(data)
}
}
---- request
-GET /t
--- response_body
123
---- no_error_log
-[error]
+
+
+
+=== TEST 7: sls log get milliseconds
+--- config
+ location /t {
+ content_by_lua_block {
+ local function get_syslog_timestamp_millisecond(sls_log)
+ local first_idx = string.find(sls_log, " ") + 1
+ local last_idx2 = string.find(sls_log, " ", first_idx)
+ local rfc3339_date = string.sub(sls_log, first_idx, last_idx2)
+ local rfc3339_len = string.len(rfc3339_date)
+ local rfc3339_millisecond = string.sub(rfc3339_date, rfc3339_len - 4, rfc3339_len - 2)
+ return tonumber(rfc3339_millisecond)
+ end
+
+ local rfc5424 = require("apisix.plugins.slslog.rfc5424")
+ local m = 0
+ for _ = 1, 10 do
+ local sls_log = rfc5424.encode("SYSLOG", "INFO", "localhost", "apisix",
+ 123456, "apisix.apache.org", "apisix.apache.log",
+ "apisix.sls.logger", "BD274822-96AA-4DA6-90EC-15940FB24444",
+ "hello world")
Review comment:
Why not use ngx.sleep?
--
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 #5820: fix(sls-logger): log entry unable get millisecond timestamp
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #5820:
URL: https://github.com/apache/apisix/pull/5820#discussion_r770221671
##########
File path: t/plugin/sls-logger.t
##########
@@ -188,9 +184,41 @@ hello world
ngx.say(data)
}
}
---- request
-GET /t
--- response_body
123
---- no_error_log
-[error]
+
+
+
+=== TEST 7: sls log get milliseconds
+--- config
+ location /t {
+ content_by_lua_block {
+ local function get_syslog_timestamp_millisecond(log_entry)
+ local first_idx = string.find(log_entry, " ") + 1
+ local last_idx2 = string.find(log_entry, " ", first_idx)
+ local rfc3339_date = string.sub(log_entry, first_idx, last_idx2)
+ local rfc3339_len = string.len(rfc3339_date)
+ local rfc3339_millisecond = string.sub(rfc3339_date, rfc3339_len - 4, rfc3339_len - 2)
+ return tonumber(rfc3339_millisecond)
+ end
+
+ math.randomseed(os.time())
+ local rfc5424 = require("apisix.plugins.slslog.rfc5424")
+ local m = 0
+ for i = 1, 5 do
+ ngx.sleep(string.format("%0.3f", math.random()))
Review comment:
Why use `for i = 1, 5 do` and sleep randomly?
--
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