-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
nsqadmin: work-around bug for raw ipv6 addresses #1179
Conversation
c4285ff
to
5661079
Compare
This doesn't seem like the right place to fix this. Maybe it should be processed when the nsqd is registered, rather than when it is looked-up? The default broadcast-address is the hostname (and it is often set to a dns name). So I think that if you get an ipv6 address for this, it was probably configured explicitly as the broadcast-address for that nsqd? So maybe the thing to do is to specify the ipv6 address without square brackets when you specify the broadcast-address to nsqd? (Are there other places where we combine an address and a port and do not use |
Yes. That's right.
I have tried this but the api like
Definitely we can write a function by ourself. But this may not be the right thing to do since i think we need to follow the programming language spec. We use ip directly because we do not want to rely on dns. This is mainly for stability. Aslo, colon is not a valid character in a dns name. This should not cause any ambiguity. |
You're right, this way works, at least for this specific case. But it is "hacky". These values should be correct earlier in the process.
This is what should be figured out.
Yeah, I was saying we should find places where we concatenate host and port with something like |
5661079
to
721cc67
Compare
I have figured out that nsqadmin nodes pages will use nsq/nsqadmin/static/js/views/nodes.hbs Line 27 in 470346f
When we set an ipv6 address as the nsqd broadcast_address, the composite node link will be |
Message |
There is a right way to do it, it's just that you and I don't understand the backbonejs architecture. Here's a crazy guess, untested and probably not working: --- a/nsqadmin/static/js/collections/nodes.js
+++ b/nsqadmin/static/js/collections/nodes.js
@@ -18,6 +18,13 @@ var Nodes = Backbone.Collection.extend({
},
parse: function(resp) {
+ resp['nodes'].forEach(function(n) {
+ var jaddr = n['broadcast_address'];
+ if (jaddr.includes(':')) {
+ jaddr = '[' + jaddr + ']'; // ipv6 addr needs []
+ }
+ n['broadcast_address_http'] = jaddr + ":" + n['http_port'];
+ });
return resp['nodes'];
}
});
--- a/nsqadmin/static/js/views/nodes.hbs
+++ b/nsqadmin/static/js/views/nodes.hbs
@@ -24,7 +24,7 @@
{{#each collection}}
<tr {{#if out_of_date}}class="warning"{{/if}}>
<td>{{hostname}}</td>
- <td><a class="link" href="{{basePath "/nodes"}}/{{broadcast_address}}:{{http_port}}">{{broadcast_address}}</a></td>
+ <td><a class="link" href="{{basePath "/nodes"}}/{{broadcast_address_http}}">{{broadcast_address}}</a></td>
<td>{{tcp_port}}</td>
<td>{{http_port}}</td>
<td>{{version}}</td> |
... and another "I have no idea what I'm doing" untested idea, but again showing the kind of change that fixes the problem where it actually is: --- a/nsqadmin/static/js/models/node.js
+++ b/nsqadmin/static/js/models/node.js
@@ -12,6 +12,14 @@ var Node = Backbone.Model.extend({ //eslint-disable-line no-undef
return AppState.apiPath('/nodes');
},
+ url: function() {
+ var jaddr = this.get('broadcast_address');
+ if (jaddr.includes(':')) {
+ jaddr = '[' + jaddr + ']'; // ipv6 addr needs []
+ }
+ return AppState.apiPath('/nodes') + '/' + encodeURIComponent(jaddr + ':' + this.get('http_port'));
+ }
+
tombstoneTopic: function(topic) {
return this.destroy({
--- a/nsqadmin/static/js/views/nodes.hbs
+++ b/nsqadmin/static/js/views/nodes.hbs
@@ -24,7 +24,7 @@
{{#each collection}}
<tr {{#if out_of_date}}class="warning"{{/if}}>
<td>{{hostname}}</td>
- <td><a class="link" href="{{basePath "/nodes"}}/{{broadcast_address}}:{{http_port}}">{{broadcast_address}}</a></td>
+ <td><a class="link" href="{{url}}">{{broadcast_address}}</a></td>
<td>{{tcp_port}}</td>
<td>{{http_port}}</td> |
@ploxiln I have thought about this. But the problem is that after display the broadcast_address in |
testing locally, |
(started nsqd with |
Yes, this will work.
You mean that you can successfully request |
The "nodes" page works, just the link to a "node" details page does not work. But I haven't tested ipv6 broadcast addr with the graphite integration at all ... |
(I also tested nsq_tail using nsqlookupd and getting that ipv6 broadcast address though, that worked.) |
Yes, that's what i mean. Sorry for not making myself clear.
That is because you set the broadcast address to ipv6 address only without square bracket, right? Once you enclose an ipv6 broadcast address with a square bracket, you can not do this correctly. |
... because |
Yes. I agreed. We should only set |
oh, I see this has been updated ... yeah this is better ... This is still not the correct place. This is just where it's easier for us to make changes. But this is passing an ipv6 address to the frontend js in a strange format, to trick it to include brackets where the frontend should know to put brackets on its own. But at least this is contained to nsqadmin, and can't further confuse other components. So this can be fixed in the frontend js later. |
can you just update the commit title/description plz |
721cc67
to
6282c50
Compare
@ploxiln I have changed commit title and description.
So, IIUC, you mean that we can merge this, for now? |
@ploxiln I agree that display broadcast address in |
Yes, planning to merge this, and figure out the frontend js stuff later. Another point of clarification: while I haven't tried it, I suspect that ipv6 was already supported if you use DNS names instead of raw addresses. What this PR does is work-around a UI bug with raw ipv6 addresses. It does not "add ipv6 support" for the normal case of using dns names to manage your servers. |
It is important to me to fix bugs in the right place, whenever possible. Consider if I had merged your original proposal, where you specify ipv6 address with the wrong format to |
This change breaks the individual node page for me, it gets NOT FOUND now for |
What is the detailed error message and have you try to debug this further? |
it's a plain 404 in the logs, and when I switched back to master branch that page worked |
for _, producer := range producers { | ||
// Assume it is an ipv6 address if a colon is in it | ||
if strings.Contains(producer.BroadcastAddress, ":") { | ||
producer.BroadcastAddress = fmt.Sprintf("[%s]", producer.BroadcastAddress) |
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 should not apply the work-around here, this makes producers.Search(node)
just below not find anything, and result in the 404 "NODE_NOT_FOUND"
for _, producer := range producers { | ||
// Assume it is an ipv6 address if a colon is in it | ||
if strings.Contains(producer.BroadcastAddress, ":") { | ||
producer.BroadcastAddress = fmt.Sprintf("[%s]", producer.BroadcastAddress) |
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.
looks like this place is also inappropriate because this is going to be used for GetNSQDStats()
, not for web UI links
Ipv6 address in
broadcast_address
should be returned with leading and trilling square bracket trimmed.When we use go-nsq connect to nsqd by using lookupd's lookup api, go-nsq will compose the address by calling
net.JoinHostPort
.net.JoinHostPort
will assume that if it is an ipv6 address, there should be no square brackets asnet.JoinHostPort
will add square brackets when it detects an ipv6 address is added.