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

Don't deregister services and checks which are not managed by Nomad #568

Merged
merged 7 commits into from
Dec 11, 2015

Conversation

diptanu
Copy link
Contributor

@diptanu diptanu commented Dec 11, 2015

Fixes #560 and #525

@@ -31,7 +31,7 @@ func testAllocRunner(restarts bool) (*MockAllocStateUpdater, *AllocRunner) {
conf.AllocDir = os.TempDir()
upd := &MockAllocStateUpdater{}
alloc := mock.Alloc()
consulClient, _ := NewConsulService(logger, "127.0.0.1:8500", "", "", false, false)
consulClient, _ := NewConsulService(logger, "127.0.0.1:8500", "", "", false, false, &structs.Node{})
Copy link
Contributor

Choose a reason for hiding this comment

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

It is worth looking into creating a ConsulConfig struct since the parameters of this constructor keep growing up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@c4milo Yeah makes sense.

@c4milo
Copy link
Contributor

c4milo commented Dec 11, 2015

Looks good to me overall @diptanu! Thanks for addressing this so quickly.

}

nomadServices := c.filterConsulServices(srvs)

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: extra line here

@cbednarski
Copy link
Contributor

LGTM!

Address: "10.10.1.11",
},
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The best practice is to create a new expected map and then use reflect.DeepEquals:

exp := map[string]*consul.AgentService{
   "nomad-2121212": {
            ID:      "nomad-2121212",
            Service: "identity-service",
            Tags:    []string{"global"},
            Port:    8080,
        Address: "10.10.1.11",
        },

   act :=  c.filterConsulServices(serves)
   if !reflect.DeepEquals(act, exp) {
       t.Fatalf(...)
   }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense.

@diptanu diptanu force-pushed the f-precise-consul-dereg branch from e155f94 to 57ff1a3 Compare December 11, 2015 22:07
diptanu added a commit that referenced this pull request Dec 11, 2015
Don't deregister services and checks which are not managed by Nomad
@diptanu diptanu merged commit 6df7f35 into master Dec 11, 2015
@diptanu diptanu deleted the f-precise-consul-dereg branch December 11, 2015 22:28
@c4milo
Copy link
Contributor

c4milo commented Dec 12, 2015

@diptanu, did this fix made it into 0.2.2? I'm still seeing the issue in 0.2.2

@diptanu
Copy link
Contributor Author

diptanu commented Dec 12, 2015

@c4milo yeah I had merged the PR, and you shouldn't see this in 0.2.2 anymore

@diptanu
Copy link
Contributor Author

diptanu commented Dec 12, 2015

@c4milo Do you see the issue with master too?

@diptanu
Copy link
Contributor Author

diptanu commented Dec 12, 2015

@c4milo I just used the 0.2.2 binary, added a service by running the command curl -X PUT -d '{"Datacenter": "dc1", "Node": "google", "Address": "www.google.com","Service": {"Service": "search", "Port": 80}}' http://127.0.0.1:8500/v1/catalog/register and then ran the example.nomad. I can still see the seach service, nomad hasn't taken it out.

@c4milo
Copy link
Contributor

c4milo commented Dec 12, 2015

hm, I just tested using master branch and a service definition for a Nomad server and I'm still able to reproduce the issue.

@c4milo
Copy link
Contributor

c4milo commented Dec 12, 2015

ah I think it is because I'm not assigning any ID to my service so Consul uses nomad by default as it is the name I'm giving it. And, your prefix ID conditional might be matching it.

@diptanu
Copy link
Contributor Author

diptanu commented Dec 12, 2015

@c4milo Yeah we are using the nomad prefix to determine if Nomad manages the services and their corresponding checks. Please use something else for the ID. We should probably document this behavior.

@c4milo
Copy link
Contributor

c4milo commented Dec 12, 2015

@diptanu, why not use an ID less likely to clash with users's IDs, such as a static random ID instead?

@diptanu
Copy link
Contributor Author

diptanu commented Dec 12, 2015

@c4milo Sure we can. This just needs to be the same between Nomad client restarts.

@c4milo
Copy link
Contributor

c4milo commented Dec 12, 2015

right, that's what I meant with static.

On Sat, Dec 12, 2015 at 2:20 PM Diptanu Choudhury [email protected]
wrote:

@c4milo https://github.com/c4milo Sure we can. This just needs to be
the same between Nomad client restarts.


Reply to this email directly or view it on GitHub
#568 (comment).

@antoineco
Copy link

antoineco commented Jun 6, 2016

@diptanu it seems that the current behaviour is not documented. It should be mentioned that the nomad prefix is reserved for services registered by Nomad, especially since this same documentation suggests to register Nomad servers in Consul for easier discovery by the clients, which makes it tempting to name that service... nomad :)

@cbednarski
Copy link
Contributor

@antoineco To make sure your issue is not lost since this PR is merged, please open a new issue. You can create a link to this thread for context. Thanks!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants