-
Notifications
You must be signed in to change notification settings - Fork 107
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
parses addresses in all the sections #10
Conversation
@kiddkai Backward compatibility of the API is important. Maybe we should add new options to allow the caller to request records in those additional sections (like "authority" and "additional" sections)? Instead of creating nested tables, maybe we can just append those records to the existing |
Good point, so just add a new option called 'parse_all_sections(Boolean)' ? In this case will be pretty easy for the API consumers. And it will just have the same behaviour as the current PR. The other way is provide more options like give "give me the results for some specific section". And the response parser will do the work. I prefer the parse_all_sections solution since the record size of the dns response is limited. And the internal implementation can keep really simple. And we have a new "section" field each answer which can let the consumer do the filter work. What do you think @agentzh |
@kiddkai Can we just reuse the existing |
Yup, reusing the options table is what I planing to do. I can implement to let it supports specifying individual sections. The hard part for me maybe is just the naming for the new options. For me as a API consumer of this module. Either returning answers or answers from all sections is good enough for my use case. It's true that some developer may want something specific from the response. |
If go go down the path to implement supporting specify individual section. What options you think we should add to the query method? |
@kiddkai How about |
Sounds good, will do that change. |
Hi @agentzh I Just add A dumb question. I want to add tests for the changes, do you know how I can generates the Cheers |
Another thing need to do maybe is bump up the |
No worries, just get my head around perl. Will add |
@kiddkai Well, you don't really need to use Perl for writing tests. The tests are declarative. See the tutorials here if you have problems: https://openresty.gitbooks.io/programming-openresty/content/testing/index.html |
Hi @agentzh, thank you for the suggestion. I've already make the TestDNS file support mocking the srv record and other sections response 4days ago. But I don't have chance to update my PR yet. Quite a busy week. I will apply the changes I made to my PR in the werkend. It's a great fun to write the DNS mocking feature. Really like the design of testing in openresty. |
@kiddkai Awesome! Looking forward to your updated PR. Glad to hear that you enjoyed it :) |
Hey @agentzh , just updated. Now test covers the new features I added in this repo. I guess everything is done for this PR 👯 |
@kiddkai Thanks for your hard work! @doujiang24 Will you have a quick look at this PR? If nothing is found, I'll merge this :) |
elseif ans.section == SECTION_AR and additional_section then | ||
table.insert(result, ans) | ||
end | ||
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.
@kiddkai ,good job!
- the size of answers is explicitly, it's better to pre-allocate the
result
usingnew_tab
. table.insert
is expensive, it's better to replace using index.
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.
Hey @guanglinlv , no problems, will allocate the table first for all the records.
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.
also my code intent here is also wrong, thanks for pointing out.
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.
@kiddkai , nice job!
we usually use for i = 1, #answers do
instead iparis
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.
yup, understand that. because I saw the ipars
is already optimised by the luajit
, so
I use it.
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.
Hi @doujiang24, just get back to the code and did a double check. When we start doing _filter
answers, the answer is already becomes a list of table and doesn't specify how many answers in each section. I guess if we want to pass the "how many items in each section" we need to change
the shape of the answers which comes from parse_response
. And make a nested hash table which looks like:
{
['answers'] = { ... },
['authority'] = { ... },
['additional'] = { ... }
}
Then we will be able to know how many items in each section. Otherwise it will become little bit
hacky to pre-allocate the table using new_tab
since the state of how many answers in each section
didn't pass around in the original design.
Cheers
@@ -1,4 +1,4 @@ | |||
Name | |||
Name |
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 this change?
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.
I guess is my vim auto format this, will change it back .
23c452d
to
be43352
Compare
Hi @agentzh @doujiang24 , just updated the PR. Currently, it still parses all the records in all sections. But it will not insert the answer into the result table unless user enables it. So current implementation will not have extra filter process 🐒. @agentzh I also fixes the |
@kiddkai Thanks for the updates. I'll look at it again. |
Any update on this? Would be great to get this in. |
@Tieske Still working on the 1.9.15.1 release. Will look into this after the formal release is out. I hope that 1.9.15.2 can include this. |
👍 was hoping for 1.9.15.1 😄 |
insert(answers, ans) | ||
ans.section = section | ||
|
||
if not should_skip then |
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.
Instead of always parsing the unwanted sections, we should just stop parsing directly?
@kiddkai Please check out my latest comments. Also, please rebase to the latest master. Thank you! |
a57c9a2
to
c75d606
Compare
Hi @agentzh , just updated my pr. You can review it again to see if there's anything is bad :D. |
very cool, it's useful for me. |
@kiddkai Thanks for your updates! I'll have another look soon :) |
insert(answers, ans) | ||
end | ||
|
||
ans.section = section | ||
|
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.
The Lua variables type_hi
and type_lo
below are not declared as local
and thus are examples of global variable abuses.
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.
The lua-releng
tool provided by the nginx-devel-utils
github repository does find all such global variable misuses:
Checking use of Lua global variables in file lib/resty/dns/resolver.lua...
op no. line instruction args ; code
31 [335] SETGLOBAL 13 -4 ; type_hi
36 [336] SETGLOBAL 13 -5 ; type_lo
38 [337] GETGLOBAL 14 -4 ; type_hi
41 [337] GETGLOBAL 14 -5 ; type_lo
48 [343] SETGLOBAL 14 -8 ; class_hi
53 [344] SETGLOBAL 14 -10 ; class_lo
55 [345] GETGLOBAL 15 -8 ; class_hi
58 [345] GETGLOBAL 15 -10 ; class_lo
@kiddkai Found some more small issues, as in my comments above. Well, since the remaining issues are minor, I'll fix them locally myself. Just FYI :) Thanks for your work on this! |
Fixing them, will fix them soon |
@@ -65,6 +69,10 @@ local _M = { | |||
TYPE_SRV = TYPE_SRV, | |||
TYPE_SPF = TYPE_SPF, | |||
CLASS_IN = CLASS_IN, | |||
SECTION_QD = SECTION_QD, |
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 SECTON_QD
constant is unused internally in the implementation nor documented in README. Better remove it?
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.
Yeah, is not being used anywhere. I can remove it
Hi @agentzh I just fixes all of the styling issue you just mentioned, so feel free to review it again. Don't know why still have the line 572 issue shows there. I am sure that is two blank line there now ~ |
if not answers then | ||
return nil, err | ||
end | ||
return answers |
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 eliminating the original tail call to _tcp_query
above? Seems like we should just do
return _tcp_query(self, query, id, opts)
here?
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.
true, just update it
@kiddkai Just merged a modified version of your branch into master. some more edits in the docs. Thanks! |
YAY, cool |
Hi @agentzh ,
This seems like a breaking change to this module. Basically, what this PR do is returns all the sections in the dns response. Previously, it just returns the answer section.
This change based on our requirement that when we do a
SRV
request to our consul serverto get what services are available, and what are the ip addresses + port for that specific services. It returns us:
But the current
lua-resty-dns
module actually just returns us the hostname + port for the query. And from thedig
result shows that theadditional section
already have the information I need. So in orderto make less dns request like this project: https://github.com/vlipco/srv-router/blob/master/conf/srv_router.lua#L84
I create this pr for the change. Which may breaks the current modules exists which using this module.