Skip to content

feat: add method that parse ip from /etc/hosts in high priority#8270

Merged
spacewander merged 8 commits into
apache:masterfrom
TenYearsIn:master
Nov 22, 2022
Merged

feat: add method that parse ip from /etc/hosts in high priority#8270
spacewander merged 8 commits into
apache:masterfrom
TenYearsIn:master

Conversation

@TenYearsIn

@TenYearsIn TenYearsIn commented Nov 7, 2022

Copy link
Copy Markdown
Contributor

Description

Fixes #5233

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

Comment thread apisix/core/resolver.lua Outdated
@soulbird

soulbird commented Nov 8, 2022

Copy link
Copy Markdown
Contributor

Need test cases also.

Comment thread apisix/core/resolver.lua
@TenYearsIn

Copy link
Copy Markdown
Contributor Author

please approve running workflows @spacewander

@TenYearsIn

Copy link
Copy Markdown
Contributor Author

I analyze the error test cases reported by the CI, but I find that It has nothing to do with the code I commit, what I should do

@spacewander

Copy link
Copy Markdown
Member

The tests fail because there is no "dns resolver domain: xxx to yyy" in the error.log, as resolving host in /etc/hosts doesn't go through the DNS client. Maybe you can add a similar log to let test pass.

@TenYearsIn

Copy link
Copy Markdown
Contributor Author

The tests fail because there is no "dns resolver domain: xxx to yyy" in the error.log, as resolving host in /etc/hosts doesn't go through the DNS client. Maybe you can add a similar log to let test pass.

Thx, How can i trigger ci locally. I want to know the cause .

@spacewander

Copy link
Copy Markdown
Member

The tests fail because there is no "dns resolver domain: xxx to yyy" in the error.log, as resolving host in /etc/hosts doesn't go through the DNS client. Maybe you can add a similar log to let test pass.

Thx, How can i trigger ci locally. I want to know the cause .

You can submit the PR to your fork, where you have the right to rerun it if you want.

@TenYearsIn

TenYearsIn commented Nov 17, 2022

Copy link
Copy Markdown
Contributor Author

I Find out that some test cases can't match this feature. So I modify some test-case code . Please review my thoughts @spacewander

Comment thread apisix/core/resolver.lua
-- use ipv4 in high priority
local ip = rev["ipv4"]
if not ip then
ip = rev["ipv6"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to consider this setting:

enable_ipv6: true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of this setting before, But I think when the default value of this setting is true , We also use ipv4 . So I think the ip's mapping that in /etc/hosts decides, but I improve ipv4's priority

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the users disable ipv6, we should not return the IPv6 address in /etc/hosts to them.

Comment thread t/core/resolver.t Outdated
}
}
--- request
GET /t

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can set the common sections at the top of this file like

add_block_preprocessor(sub {

So we don't need to repeat it in each test.

Comment thread t/core/resolver.t Outdated
Comment thread t/node/upstream-node-dns.t Outdated
Comment thread apisix/core/resolver.lua
if not hosts then
return hosts, err
end
HOSTS_IP_MATCH_CACHE = hosts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will HOSTS_IP_MATCH_CACHE be cleaned? APISIX will not update it after it is read at startup. Unless APISIX is restarted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of configuration is basically unchanged, so I didn't consider reloading logic at that time

Comment thread apisix/core/resolver.lua
-- use ipv4 in high priority
local ip = rev["ipv4"]
if not ip then
ip = rev["ipv6"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the users disable ipv6, we should not return the IPv6 address in /etc/hosts to them.

Comment thread t/core/resolver.t

if (!$block->request) {
$block->set_value("request", "GET /t");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's enable the no_error_log by default too:

if (!$block->no_error_log && !$block->error_log) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please Review ~ @spacewander

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

request help: no host allowed while connecting to upstream

5 participants