dickens7 commented on a change in pull request #4559:
URL: https://github.com/apache/apisix/pull/4559#discussion_r667342787



##########
File path: apisix/plugins/request-id.lua
##########
@@ -14,36 +14,163 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
-local core          = require("apisix.core")
-local plugin_name   = "request-id"
-local ngx           = ngx
-local uuid          = require("resty.jit-uuid")
+
+local ngx = ngx
+local bit = require("bit")
+local core = require("apisix.core")
+local snowflake = require("snowflake")
+local uuid = require("resty.jit-uuid")
+local process = require("ngx.process")
+local tostring = tostring
+local math_pow = math.pow
+
+local plugin_name = "request-id"
+
+local worker_number = nil
+local snowflake_init = nil
+
+local attr = nil
 
 local schema = {
     type = "object",
     properties = {
         header_name = {type = "string", default = "X-Request-Id"},
-        include_in_response = {type = "boolean", default = true}
+        include_in_response = {type = "boolean", default = true},
+        algorithm = {type = "string", enum = {"uuid", "snowflake"}, default = 
"uuid"}
     }
 }
 
+local attr_schema = {
+    type = "object",
+    properties = {
+        snowflake = {
+            type = "object",
+            properties = {
+                enable = {type = "boolean"},
+                snowflake_epoc = {type = "integer", minimum = 1, default = 
1609459200000},
+                node_id_bits = {type = "integer", minimum = 1, default = 5},
+                sequence_bits = {type = "integer", minimum = 1, default = 10},
+                datacenter_id_bits = {type = "integer", minimum = 1, default = 
5},

Review comment:
       <s> `default=5` is the setting of standard snowflake algorithm. Setting 
`default=7` may be confusing for people who are not familiar with the snowflake 
algorithm. The Snowflake configuration is off by default, so we can introduce 
the settings in document clearly. </s>
   
   The configuration items were adjusted to merge `datacenter_id_bits` and 
`node_id_bits` into `data_machine_bits`. 
   
   ```yaml
   plugin_attr:
     request-id:
       snowflake:
         enable: true
         snowflake_epoc: 1609459200000   # the starting timestamp is expressed 
in milliseconds
         data_machine_bits: 12           # data machine bit
         sequence_bits: 10               # each machine generates a maximum of 
(1 << sequence_bits) serial numbers per millisecond
         worker_number_ttl: 30           # live time for worker number in etcd 
(unit: second)
         worker_number_interval: 10      # lease renewal interval in etcd 
(unit: second)
   ```
   
   The PR https://github.com/api7/lua-snowflake/pull/3, commit the code after 
processing
   




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