Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

kiddkai
Copy link

@kiddkai kiddkai commented Apr 15, 2016

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 server
to get what services are available, and what are the ip addresses + port for that specific services. It returns us:


$ dig @127.0.0.1 -p 8600 test_service.service.consul SRV

; <<>> DiG 9.8.3-P1 <<>> @127.0.0.1 -p 8600 test_service.service.consul SRV
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32661
;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;test_service.service.consul.   IN      SRV

;; ANSWER SECTION:
test_service.service.consul. 0  IN      SRV     1 1 3003 zekaizhengs-mbp.corpad.net.local.node.dc1.consul.
test_service.service.consul. 0  IN      SRV     1 1 3000 zekaizhengs-mbp.corpad.net.local.node.dc1.consul.

;; ADDITIONAL SECTION:
zekaizhengs-mbp.corpad.net.local.node.dc1.consul. 0 IN A 169.254.160.242
zekaizhengs-mbp.corpad.net.local.node.dc1.consul. 0 IN A 169.254.160.242

;; Query time: 0 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Thu Apr 14 15:45:26 2016
;; MSG SIZE  rcvd: 363

But the current lua-resty-dns module actually just returns us the hostname + port for the query. And from the dig result shows that the additional section already have the information I need. So in order
to 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.

@kiddkai
Copy link
Author

kiddkai commented Apr 15, 2016

@agentzh
Copy link
Member

agentzh commented Apr 15, 2016

@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 answers table but with a special field like section being set?

@kiddkai
Copy link
Author

kiddkai commented Apr 15, 2016

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

@agentzh
Copy link
Member

agentzh commented Apr 15, 2016

@kiddkai Can we just reuse the existing options table for the query and tcp_query methods? Maybe we should allow specifying individual sections? Choosing between all sections and just the answers section looks not flexible enough to me :) Thoughts?

@kiddkai
Copy link
Author

kiddkai commented Apr 15, 2016

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.

@kiddkai
Copy link
Author

kiddkai commented Apr 15, 2016

If go go down the path to implement supporting specify individual section. What options you think we should add to the query method?

@agentzh
Copy link
Member

agentzh commented Apr 16, 2016

@kiddkai How about additional_section = true | false and authority_section = true | false?

@kiddkai
Copy link
Author

kiddkai commented Apr 16, 2016

Sounds good, will do that change.

@kiddkai
Copy link
Author

kiddkai commented Apr 18, 2016

Hi @agentzh

I Just add additional_section and authority_section to both tcp_query and query.

A dumb question. I want to add tests for the changes, do you know how I can generates the mock dns response? I can use tcpdump to get the dns responses. But don't know how to put it into the t file.
Will happy to know more about it.

Cheers

@kiddkai
Copy link
Author

kiddkai commented Apr 18, 2016

Another thing need to do maybe is bump up the _VERSION.

@kiddkai
Copy link
Author

kiddkai commented Apr 19, 2016

No worries, just get my head around perl. Will add mock tests for this functional.

@agentzh
Copy link
Member

agentzh commented Apr 22, 2016

@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

@kiddkai
Copy link
Author

kiddkai commented Apr 22, 2016

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.

@agentzh
Copy link
Member

agentzh commented Apr 22, 2016

@kiddkai Awesome! Looking forward to your updated PR. Glad to hear that you enjoyed it :)

@kiddkai
Copy link
Author

kiddkai commented Apr 26, 2016

Hey @agentzh , just updated. Now test covers the new features I added in this repo. I guess everything is done for this PR 👯

@agentzh
Copy link
Member

agentzh commented Apr 26, 2016

@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

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 using new_tab.
  • table.insert is expensive, it's better to replace using index.

Copy link
Author

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.

Copy link
Author

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.

Copy link
Member

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

Copy link
Author

@kiddkai kiddkai Apr 28, 2016

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.

http://wiki.luajit.org/NYI#libraries_table-library

Copy link
Author

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
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Author

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 .

@kiddkai kiddkai force-pushed the master branch 2 times, most recently from 23c452d to be43352 Compare May 18, 2016 01:31
@kiddkai
Copy link
Author

kiddkai commented May 18, 2016

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 README.md, yay 💃

@agentzh
Copy link
Member

agentzh commented May 18, 2016

@kiddkai Thanks for the updates. I'll look at it again.

@Tieske
Copy link
Contributor

Tieske commented May 31, 2016

Any update on this? Would be great to get this in.

@agentzh
Copy link
Member

agentzh commented May 31, 2016

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

@Tieske
Copy link
Contributor

Tieske commented May 31, 2016

👍

was hoping for 1.9.15.1 😄

insert(answers, ans)
ans.section = section

if not should_skip then
Copy link
Member

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?

@agentzh
Copy link
Member

agentzh commented Jun 1, 2016

@kiddkai Please check out my latest comments. Also, please rebase to the latest master. Thank you!

@kiddkai kiddkai force-pushed the master branch 3 times, most recently from a57c9a2 to c75d606 Compare June 14, 2016 01:29
@kiddkai
Copy link
Author

kiddkai commented Jun 14, 2016

Hi @agentzh , just updated my pr. You can review it again to see if there's anything is bad :D.

@boostbob
Copy link

boostbob commented Jul 5, 2016

very cool, it's useful for me.

@agentzh
Copy link
Member

agentzh commented Jul 6, 2016

@kiddkai Thanks for your updates! I'll have another look soon :)

insert(answers, ans)
end

ans.section = section

Copy link
Member

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.

Copy link
Member

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

@agentzh
Copy link
Member

agentzh commented Jul 28, 2016

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

@kiddkai
Copy link
Author

kiddkai commented Jul 28, 2016

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,
Copy link
Member

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?

Copy link
Author

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

@kiddkai
Copy link
Author

kiddkai commented Jul 28, 2016

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
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

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

true, just update it

@agentzh
Copy link
Member

agentzh commented Jul 28, 2016

@kiddkai Just merged a modified version of your branch into master. some more edits in the docs. Thanks!

@agentzh agentzh closed this Jul 28, 2016
@kiddkai
Copy link
Author

kiddkai commented Jul 28, 2016

YAY, cool

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.

6 participants