shreemaan-abhishek commented on code in PR #11111: URL: https://github.com/apache/apisix/pull/11111#discussion_r1566020327
########## docs/en/latest/discovery/kubernetes.md: ########## @@ -351,3 +351,55 @@ A: Assume your [_ServiceAccount_](https://kubernetes.io/docs/tasks/configure-pod ```shell kubectl -n apisix get secret kubernetes-discovery-token-c64cv -o jsonpath={.data.token} | base64 -d ``` + +## Debugging API + +It also offers control api for debugging. + +### Memory Dump API + +```shell +GET /v1/discovery/kubernetes/dump Review Comment: ```suggestion curl http://127.0.0.1:9090/v1/discovery/kubernetes/dump | jq ``` ########## apisix/discovery/kubernetes/init.lua: ########## @@ -615,4 +615,46 @@ function _M.init_worker() end end + +function _M.dump_data() + + local eps = {} + for _, conf in ipairs(local_conf.discovery.kubernetes) do + + local id = conf.id + local endpoint_dict = get_endpoint_dict(id) + local keys, err = endpoint_dict:get_keys() + if err then + error(err) + break + end + + if keys then + local k8s = {} + for i = 1, #keys do + + local key = keys[i] + --skip key with suffix #version Review Comment: why? ########## apisix/discovery/kubernetes/init.lua: ########## @@ -615,4 +615,46 @@ function _M.init_worker() end end + +function _M.dump_data() + + local eps = {} + for _, conf in ipairs(local_conf.discovery.kubernetes) do + + local id = conf.id + local endpoint_dict = get_endpoint_dict(id) + local keys, err = endpoint_dict:get_keys() + if err then + error(err) + break + end + + if keys then + local k8s = {} + for i = 1, #keys do + + local key = keys[i] + --skip key with suffix #version + if key:sub(-#"#version") ~= "#version" then Review Comment: using `ngx.re.sub` is more performant. ########## docs/en/latest/discovery/kubernetes.md: ########## @@ -351,3 +351,55 @@ A: Assume your [_ServiceAccount_](https://kubernetes.io/docs/tasks/configure-pod ```shell kubectl -n apisix get secret kubernetes-discovery-token-c64cv -o jsonpath={.data.token} | base64 -d ``` + +## Debugging API + +It also offers control api for debugging. + +### Memory Dump API + Review Comment: Add a descriptive sentence something like "to query/list the nodes discoverd by kubernetes discovery, you can query the `/v1/discovery/kubernetes/dump` control API endpoint like so:" ########## docs/en/latest/discovery/kubernetes.md: ########## @@ -351,3 +351,55 @@ A: Assume your [_ServiceAccount_](https://kubernetes.io/docs/tasks/configure-pod ```shell kubectl -n apisix get secret kubernetes-discovery-token-c64cv -o jsonpath={.data.token} | base64 -d ``` + +## Debugging API + +It also offers control api for debugging. + +### Memory Dump API + +```shell +GET /v1/discovery/kubernetes/dump +``` + +For example: Review Comment: gives the following response: ########## t/kubernetes/discovery/kubernetes3.t: ########## @@ -187,6 +187,13 @@ _EOC_ core.log.err("operator k8s cluster error: ", err) return 500 end + + ngx.sleep(1) + + local k8s = require("apisix.discovery.kubernetes") + local data = k8s.dump_data() + ngx.say(core.json.encode(data,true)) + Review Comment: please also add another test that shows usage of querying endpoints using the control API ########## docs/en/latest/discovery/kubernetes.md: ########## @@ -351,3 +351,55 @@ A: Assume your [_ServiceAccount_](https://kubernetes.io/docs/tasks/configure-pod ```shell kubectl -n apisix get secret kubernetes-discovery-token-c64cv -o jsonpath={.data.token} | base64 -d ``` + +## Debugging API + +It also offers control api for debugging. + +### Memory Dump API + +```shell +GET /v1/discovery/kubernetes/dump +``` + +For example: + +```shell +# curl http://127.0.0.1:9090/v1/discovery/kubernetes/dump | jq Review Comment: ```suggestion ``` -- 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]
