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

Log a better message on trying to deregister a nonexistent service #2492

Merged
merged 2 commits into from
Nov 9, 2016

Conversation

kyhavlov
Copy link
Contributor

@kyhavlov kyhavlov commented Nov 9, 2016

Improve the log message when attempting to deregister a service that doesn't exist, as shown here: #1188 (comment)

Copy link
Contributor

@slackpad slackpad left a comment

Choose a reason for hiding this comment

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

Put a few comments up on there.

@@ -1074,6 +1074,10 @@ func TestAgent_serviceTokens(t *testing.T) {
l := new(localState)
l.Init(config, nil)

l.AddService(&structs.NodeService{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this related to the log change?

Copy link
Contributor Author

@kyhavlov kyhavlov Nov 9, 2016

Choose a reason for hiding this comment

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

This is because if we don't add the service initially, it'll panic on trying to log the warning with the nil logger we initialize with above

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh makes sense - this test was kind of bogus w/o the registration.

l.serviceStatus[serviceID] = syncStatus{inSync: false}
l.changeMade()
} else {
l.logger.Printf("[WARN] agent: Tried to deregister nonexistent service '%s'", serviceID)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you'll want to add an error return to this function can compose the warning one level up. Otherwise you'll get this log message followed by "agent: removed service" which'll be confusing. I think up there we can return nil from RemoveService() and add a comment about how we are trying to keep the current idempotent behavior for now (probably a TODO to fix for 0.8).

l.serviceStatus[serviceID] = syncStatus{inSync: false}
l.changeMade()
} else {
l.logger.Printf("[WARN] agent: Tried to deregister nonexistent service '%s'", serviceID)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can drop the quote marks and use %q here.

@slackpad
Copy link
Contributor

slackpad commented Nov 9, 2016

LGTM

@kyhavlov kyhavlov merged commit b1760b2 into master Nov 9, 2016
@kyhavlov kyhavlov deleted the b-deregister-nonexistent branch November 9, 2016 21:57
tolitius pushed a commit to tolitius/consul that referenced this pull request Nov 11, 2016
)

Log a warning instead of a success message when attempting to deregister a nonexistent service. In Consul 0.8 this can be changed to giving an error outright, but for now we can keep the idempotent delete behavior.
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.

2 participants