-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
DNS lookup by Consul node ID #2702
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c5e140c
Small premature optimization in `isUUID()`.
sean- f3f3f73
Enable looking up consul nodes by their node ID.
sean- 13fb395
Toggle `AllowMissing` to false to accommodate old clients without Nod…
sean- e86cefe
Rename `nodeName` to `nodeNameOrID`.
sean- 854f2b2
Whoops. Return an empty set in the event that there are multiple mat…
sean- 295ca81
Run a test of `NodeServices()` with a NodeID as an argument.
sean- 62527c1
Treat a uuid prefix lookup error as a soft error, as if a node name l…
sean- c16f334
Treat a uuid prefix lookup error as a soft error, as if a node name
sean- File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,23 @@ import ( | |
"github.com/hashicorp/consul/lib" | ||
"github.com/hashicorp/consul/types" | ||
"github.com/hashicorp/go-memdb" | ||
uuid "github.com/hashicorp/go-uuid" | ||
) | ||
|
||
func makeRandomNodeID(t *testing.T) types.NodeID { | ||
id, err := uuid.GenerateUUID() | ||
if err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
return types.NodeID(id) | ||
} | ||
|
||
func TestStateStore_EnsureRegistration(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth it to add another test, or a clause here that calls |
||
s := testStateStore(t) | ||
|
||
// Start with just a node. | ||
req := &structs.RegisterRequest{ | ||
ID: types.NodeID("40e4a748-2192-161a-0510-9bf59fe950b5"), | ||
ID: makeRandomNodeID(t), | ||
Node: "node1", | ||
Address: "1.2.3.4", | ||
TaggedAddresses: map[string]string{ | ||
|
@@ -27,6 +36,7 @@ func TestStateStore_EnsureRegistration(t *testing.T) { | |
"somekey": "somevalue", | ||
}, | ||
} | ||
nodeID := req.ID | ||
if err := s.EnsureRegistration(1, req); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
|
@@ -37,14 +47,21 @@ func TestStateStore_EnsureRegistration(t *testing.T) { | |
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
if out.ID != types.NodeID("40e4a748-2192-161a-0510-9bf59fe950b5") || | ||
if out.ID != nodeID || | ||
out.Node != "node1" || out.Address != "1.2.3.4" || | ||
len(out.TaggedAddresses) != 1 || | ||
out.TaggedAddresses["hello"] != "world" || | ||
out.Meta["somekey"] != "somevalue" || | ||
out.CreateIndex != 1 || out.ModifyIndex != 1 { | ||
t.Fatalf("bad node returned: %#v", out) | ||
} | ||
_, out2, err := s.GetNodeID(nodeID) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
if !reflect.DeepEqual(out, out2) { | ||
t.Fatalf("bad node returned: %#v -- %#v", out, out2) | ||
} | ||
} | ||
verifyNode() | ||
|
||
|
@@ -183,27 +200,39 @@ func TestStateStore_EnsureRegistration_Restore(t *testing.T) { | |
|
||
// Start with just a node. | ||
req := &structs.RegisterRequest{ | ||
ID: makeRandomNodeID(t), | ||
Node: "node1", | ||
Address: "1.2.3.4", | ||
} | ||
nodeID := string(req.ID) | ||
nodeName := string(req.Node) | ||
restore := s.Restore() | ||
if err := restore.Registration(1, req); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
restore.Commit() | ||
|
||
// Retrieve the node and verify its contents. | ||
verifyNode := func() { | ||
_, out, err := s.GetNode("node1") | ||
verifyNode := func(nodeLookup string) { | ||
_, out, err := s.GetNode(nodeLookup) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
if out.Node != "node1" || out.Address != "1.2.3.4" || | ||
if out == nil { | ||
_, out, err = s.GetNodeID(types.NodeID(nodeLookup)) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
|
||
if out == nil || out.Address != "1.2.3.4" || | ||
!(out.Node == nodeLookup || string(out.ID) == nodeLookup) || | ||
out.CreateIndex != 1 || out.ModifyIndex != 1 { | ||
t.Fatalf("bad node returned: %#v", out) | ||
} | ||
} | ||
verifyNode() | ||
verifyNode(nodeID) | ||
verifyNode(nodeName) | ||
|
||
// Add in a service definition. | ||
req.Service = &structs.NodeService{ | ||
|
@@ -219,8 +248,8 @@ func TestStateStore_EnsureRegistration_Restore(t *testing.T) { | |
restore.Commit() | ||
|
||
// Verify that the service got registered. | ||
verifyService := func() { | ||
idx, out, err := s.NodeServices(nil, "node1") | ||
verifyService := func(nodeLookup string) { | ||
idx, out, err := s.NodeServices(nil, nodeLookup) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
|
@@ -240,7 +269,7 @@ func TestStateStore_EnsureRegistration_Restore(t *testing.T) { | |
|
||
// Add in a top-level check. | ||
req.Check = &structs.HealthCheck{ | ||
Node: "node1", | ||
Node: nodeName, | ||
CheckID: "check1", | ||
Name: "check", | ||
} | ||
|
@@ -252,7 +281,7 @@ func TestStateStore_EnsureRegistration_Restore(t *testing.T) { | |
|
||
// Verify that the check got registered. | ||
verifyCheck := func() { | ||
idx, out, err := s.NodeChecks(nil, "node1") | ||
idx, out, err := s.NodeChecks(nil, nodeName) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
|
@@ -263,19 +292,21 @@ func TestStateStore_EnsureRegistration_Restore(t *testing.T) { | |
t.Fatalf("bad: %#v", out) | ||
} | ||
c := out[0] | ||
if c.Node != "node1" || c.CheckID != "check1" || c.Name != "check" || | ||
if c.Node != nodeName || c.CheckID != "check1" || c.Name != "check" || | ||
c.CreateIndex != 3 || c.ModifyIndex != 3 { | ||
t.Fatalf("bad check returned: %#v", c) | ||
} | ||
} | ||
verifyNode() | ||
verifyService() | ||
verifyNode(nodeID) | ||
verifyNode(nodeName) | ||
verifyService(nodeID) | ||
verifyService(nodeName) | ||
verifyCheck() | ||
|
||
// Add in another check via the slice. | ||
req.Checks = structs.HealthChecks{ | ||
&structs.HealthCheck{ | ||
Node: "node1", | ||
Node: nodeName, | ||
CheckID: "check2", | ||
Name: "check", | ||
}, | ||
|
@@ -287,10 +318,12 @@ func TestStateStore_EnsureRegistration_Restore(t *testing.T) { | |
restore.Commit() | ||
|
||
// Verify that the additional check got registered. | ||
verifyNode() | ||
verifyService() | ||
verifyNode(nodeID) | ||
verifyNode(nodeName) | ||
verifyService(nodeID) | ||
verifyService(nodeName) | ||
func() { | ||
idx, out, err := s.NodeChecks(nil, "node1") | ||
idx, out, err := s.NodeChecks(nil, nodeName) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
|
@@ -301,13 +334,13 @@ func TestStateStore_EnsureRegistration_Restore(t *testing.T) { | |
t.Fatalf("bad: %#v", out) | ||
} | ||
c1 := out[0] | ||
if c1.Node != "node1" || c1.CheckID != "check1" || c1.Name != "check" || | ||
if c1.Node != nodeName || c1.CheckID != "check1" || c1.Name != "check" || | ||
c1.CreateIndex != 3 || c1.ModifyIndex != 4 { | ||
t.Fatalf("bad check returned: %#v", c1) | ||
} | ||
|
||
c2 := out[1] | ||
if c2.Node != "node1" || c2.CheckID != "check2" || c2.Name != "check" || | ||
if c2.Node != nodeName || c2.CheckID != "check2" || c2.Name != "check" || | ||
c2.CreateIndex != 4 || c2.ModifyIndex != 4 { | ||
t.Fatalf("bad check returned: %#v", c2) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is probably worth a comment about trying to make sure there's not another node that matches the prefix. It's pretty obscure logic :-)
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 wrt the comment below - it's not that we didn't find anything - there were too many things.