shuaijinchao commented on a change in pull request #6202:
URL: https://github.com/apache/apisix/pull/6202#discussion_r803569654



##########
File path: apisix/plugins/server-info.lua
##########
@@ -158,25 +150,66 @@ local function report(premature, report_ttl)
         end
     end
 
-    server_info.last_report_time = ngx_time()
-
+    -- get inside etcd data, if not exist, create it
     local key = "/data_plane/server_info/" .. server_info.id
-    local ok, err = core.etcd.set(key, server_info, report_ttl)
+    local res, _ = core.etcd.get(key)
+    if  not res.body.node then
+        local newres, err = core.etcd.set(key, server_info, report_ttl)
+        if not newres then
+            core.log.error("failed to set server_info: ", err)
+        end
+
+        -- set lease_id to ngx dict
+        local ok, err = internal_status:set("lease_id", newres.body.lease_id)
+        if not ok then
+            core.log.error("failed to save boot_time to shdict: ", err)
+        end
+
+        return
+    end
+
+    local res, _ = core.etcd.get(key)

Review comment:
       ditto

##########
File path: apisix/plugins/server-info.lua
##########
@@ -203,8 +236,7 @@ end
 
 
 function _M.init()
-    core.log.info("server info: ", core.json.delay_encode(get()))
-
+    -- core.log.info("server info: ", core.json.delay_encode(get()))

Review comment:
       remove debug and redundant code

##########
File path: apisix/plugins/server-info.lua
##########
@@ -158,25 +150,66 @@ local function report(premature, report_ttl)
         end
     end
 
-    server_info.last_report_time = ngx_time()
-
+    -- get inside etcd data, if not exist, create it
     local key = "/data_plane/server_info/" .. server_info.id
-    local ok, err = core.etcd.set(key, server_info, report_ttl)
+    local res, _ = core.etcd.get(key)
+    if  not res.body.node then
+        local newres, err = core.etcd.set(key, server_info, report_ttl)
+        if not newres then
+            core.log.error("failed to set server_info: ", err)
+        end
+
+        -- set lease_id to ngx dict
+        local ok, err = internal_status:set("lease_id", newres.body.lease_id)
+        if not ok then
+            core.log.error("failed to save boot_time to shdict: ", err)
+        end

Review comment:
       should not continue to set `ngx dict` if `newres` fetch fails

##########
File path: apisix/plugins/server-info.lua
##########
@@ -217,13 +249,14 @@ function _M.init()
         return
     end
 
+    -- local report_ttl = attr and attr.report_ttl or default_report_ttl

Review comment:
       ditto

##########
File path: apisix/plugins/server-info.lua
##########
@@ -158,25 +150,66 @@ local function report(premature, report_ttl)
         end
     end
 
-    server_info.last_report_time = ngx_time()
-
+    -- get inside etcd data, if not exist, create it
     local key = "/data_plane/server_info/" .. server_info.id
-    local ok, err = core.etcd.set(key, server_info, report_ttl)
+    local res, _ = core.etcd.get(key)

Review comment:
       need to judge failure




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