-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add tars discovery #6599
feat: add tars discovery #6599
Conversation
t/tars/discovery/tars.t
Outdated
use t::APISIX 'no_plan'; | ||
|
||
repeat_each(1); | ||
log_level('debug'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to use debug level?
t/tars/discovery/tars.t
Outdated
|
||
=== TEST 1: create initial server and servant | ||
--- timeout: 12 | ||
--- yaml_config eval: $::yaml_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already set the yaml_config?
t/tars/discovery/tars.t
Outdated
"DONE\n", | ||
"{ 1 1 1 }\n", | ||
] | ||
--- no_error_log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's save the no_error_log like
Line 40 in 1ac7166
if ((!defined $block->error_log) && (!defined $block->no_error_log)) { |
apisix/discovery/tars/init.lua
Outdated
|
||
function _M.init_worker() | ||
-- TODO: maybe we can read dict name from discovery config | ||
endpoint_dict = ngx.shared.discovery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use a new shdict instead of hijacking authz-keycloak's
apisix/discovery/tars/init.lua
Outdated
end | ||
|
||
local conf = local_conf.discovery.tars | ||
default_weight = local_conf.discovery.tars.default_weight or 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default_weight = local_conf.discovery.tars.default_weight or 100 | |
default_weight = conf.default_weight |
The default weight is set already.
|
||
if not last_fetch_error then | ||
db_cli:set_keepalive(120 * 1000, 1) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need close
if err?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to handle this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need
close
if err?
Sorry, I think this place doesn't actively call db:close() should be acceptable,
Here provides agentzh's view
apisix/discovery/tars/init.lua
Outdated
return nil | ||
end | ||
|
||
local endpoint = core.json.decode(endpoint_content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get the err and put it in the msg
local activated_buffer = core.table.new(10, 0) | ||
local nodes_buffer = core.table.new(0, 5) | ||
|
||
local endpoints_pattern = core.table.concat( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you show us the data which is matched by this regex?
apisix/discovery/tars/init.lua
Outdated
end | ||
|
||
|
||
local function create_endpoint_lrucache(servant) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local function create_endpoint_lrucache(servant) | |
local function add_endpoint_to_lrucache(servant) |
apisix/discovery/tars/init.lua
Outdated
|
||
|
||
local function get_endpoint(servant) | ||
local endpoint_version = endpoint_dict:get_stale(servant .. "#version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you tell me why get_statle is used instead of get?
@spacewander |
Sorry, I don't understand how this failure happened. |
|
||
if not last_fetch_error then | ||
db_cli:set_keepalive(120 * 1000, 1) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to handle this.
@@ -266,6 +266,7 @@ nginx_config: # config for render the template to generate n | |||
introspection: 10m | |||
access-tokens: 1m | |||
ext-plugin: 1m | |||
tars: 1m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it configurable in the next PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to handle this.
Sorry,I did not get your point
Your means we can keep using this db hanlder event get last_db_error ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to close the handler when getting last_db_error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean we need to decide whether to close or not based on the value of error ?
Currently the case of error=='again' has been handled
But So Sorry for I don't know what other error values do not need to be closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the example, we need to close if we don't keepalive?
https://github.com/openresty/lua-resty-mysql#synopsis
-- put it into the connection pool of size 100,
-- with 10 seconds max idle timeout
local ok, err = db:set_keepalive(10000, 100)
if not ok then
ngx.say("failed to set keepalive: ", err)
return
end
-- or just close the connection right away:
-- local ok, err = db:close()
-- if not ok then
-- ngx.say("failed to close: ", err)
-- return
-- end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I think this place doesn't actively call db:close() should be acceptable,
this link provides agentzh's view
@spacewander
|
||
|
||
local function get_endpoint(servant) | ||
local endpoint_version, err = endpoint_dict:get_stale(servant .. "#version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use get_stale when we don't have an expiration time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fitst:
All servant:nodes pairs are from SQL queries and have no expiration time in the cache sense
Next:
When we read the results of fectch_full the logic is as follows:
1. endpoint_dict:flush_all()
2. for (result : results )
{
endpoint_dict[servant]=nodes
}
3. endpoint_dict:flush_expired()
get_endpoint may happen at 2, we have to use endpoint_dict:get_stale
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't set any expiration for the shdict's data, right? So why do we need to use get_stale & flush_expired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't set any expiration for the shdict's data, right?
We call endpoint_dict:flush_all() to marks all the existing items as expired before read full query results.
Why:
Consider the following situation:
If the current endpoint is as follows:
k1:v1, k2:v2, k3:v3
Then we full query get the following results
k1:v1, k4:v4, k5:v5
At this time, we need
1: add k4:v4, k5:v5
2: delete k2:v2, k3:v3
flush_all and flush_expired can achieve this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your explanation. Let's enrich the comment in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhixiongdu027
Please add some comment about the expiration operation, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I add comment in function fetch_full and forget function get_endpoint()
I will update
t/tars/discovery/tars.t
Outdated
database: db_tars | ||
user: root | ||
password: tars2022 | ||
full_fetch_interval: 90 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use a shorter interval instead of waiting > 90 in the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this value Is check by schema ,
can we use an fake schema.lua int test ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can reduce the min in the schema? A sane user may not use a low value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A sane user may not use a low value.
Yes, I agree with this
But I think the meaning of scheame's existence is to ensure that this value is within a reasonable range,
Is it not appropriate to modify the schema if it is only for testing .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about rewriting schema in the test?
Like
Lines 34 to 35 in 9d450d7
local client = require("skywalking.client") | |
client.backendTimerDelay = 0.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will try
t/tars/discovery/tars.t
Outdated
local core = require("apisix.core") | ||
local d = require("apisix.discovery.tars") | ||
|
||
ngx.sleep(11) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
Hi, I still have some questions to ask, please take a look at the comments I wrote. |
@spacewander @tzssangglass |
return err | ||
end | ||
extract_endpoint(res) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For style, let's add return nil
at the end
|
||
|
||
local function get_endpoint(servant) | ||
local endpoint_version, err = endpoint_dict:get_stale(servant .. "#version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhixiongdu027
Please add some comment about the expiration operation, thanks.
end | ||
extract_endpoint(res) | ||
end | ||
endpoint_dict:flush_expired() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For style, let's add return nil at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some comment about the expiration operation, thanks.
Sorry, I add comment in function fetch_full and forget function get_endpoint()
I will update
hi @zhixiongdu027 , file conflict, you need to merge master branch to your PR. |
Done |
What this PR does / why we need it:
Pre-submission checklist:
#6570
Hello everyone:
This is a PR for the tars discovery module, which is part of "tars-proxy".
Work on "tars-proxy" continues, but maybe we can finish tars discovery first