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

[FIXED] Override from command line not always working #578

Merged
merged 2 commits into from
Sep 7, 2017

Conversation

kozlovic
Copy link
Member

@kozlovic kozlovic commented Sep 6, 2017

There were some cases where override would not work. Any command
line parameter that would be set to the type default value (false
for boolean, "" for string, etc) would not be taken into account.

I moved all the flags parsing and options configuration into
a new function, which may help reduce code duplication in
NATS Streaming.

The other advantage of moving this in a function is that it
can now be unit tested.

I am also removing call to RemoveSelfReference() which attempted
to remove a route to self, which has been already solved at runtime
with detecting and ignoring a route to self.

This function would be invoked only when routes were defined in
the configuration file, not in the command line parameter.

Removing this call also solves an user issue (#577)

Resolves #574
Resolves #577

There were some cases where override would not work. Any command
line parameter that would be set to the type default value (false
for boolean, "" for string, etc) would not be taken into account.

I moved all the flags parsing and options configuration into
a new function, which may help reduce code duplication in
NATS Streaming.

The other advantage of moving this in a function is that it
can now be unit tested.

I am also removing call to `RemoveSelfReference()` which attempted
to remove a route to self, which has been already solved at runtime
with detecting and ignoring a route to self.

This function would be invoked only when routes were defined in
the configuration file, not in the command line parameter.

Removing this call also solves an user issue (#577)

Resolves #574
Resolves #577
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 91.881% when pulling 379a14b on add_configure_options into c7fc876 on master.

Copy link
Contributor

@tylertreat tylertreat left a comment

Choose a reason for hiding this comment

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

A couple minor comments but otherwise lgtm.

main.go Outdated
} else if showHelp {
// Create a FlagSet and sets the usage
fs := flag.NewFlagSet("nats-server", flag.ExitOnError)
fs.Usage = func() {
usage()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Very minor nitpick, but this could just be fs.Usage = usage

Copy link
Member Author

Choose a reason for hiding this comment

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

No we can't. It fails with Using usage() as a value otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

Odd, I don't know why that doesn't work as usage is a package-level function. https://play.golang.org/p/oDrPCpgOpj

Copy link
Member Author

Choose a reason for hiding this comment

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

Feeling stupid... this is because I did fs.Usage = usage() instead of fs.Usage = usage. Will fix that. Thanks.

} else if l > 2 {
return fmt.Errorf("invalid signal parameters: %v", commandAndPid[2:])
}
if err := ProcessSignal(Command(commandAndPid[0]), pid); err != nil {
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 the only reason ProcessSignal was exported was so it could be called from main.go. We could unexport it since it's not intended to be part of the public API, unless we consider that a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think anybody would have use that, but it was indeed an exported function that is present in a public release (1.0.0+). Let me think about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, I was passing the flagSet to this function because at one point during dev I needed it, which I don't right now. So will fix that for sure.

@kozlovic
Copy link
Member Author

kozlovic commented Sep 7, 2017

After discussion, we decided to leave ProcessSignal exported since it was included since public release 1.0.0.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 91.944% when pulling 684a2e4 on add_configure_options into c7fc876 on master.

@tylertreat
Copy link
Contributor

lgtm

@kozlovic kozlovic merged commit dbe9bc7 into master Sep 7, 2017
@kozlovic kozlovic deleted the add_configure_options branch September 7, 2017 15:46
kozlovic added a commit that referenced this pull request Sep 7, 2017
This is just for tests since from main.go, the FlagSet is set
with ExitOnError so Parse() would call os.Exit(2).
Regardless, I wanted to add error checking and a test for that.

Related to #578
kozlovic added a commit that referenced this pull request Sep 7, 2017
This is just for tests since from main.go, the FlagSet is set
with ExitOnError so Parse() would call os.Exit(2).
Regardless, I wanted to add error checking and a test for that.

Related to #578
kozlovic added a commit to nats-io/nats-streaming-server that referenced this pull request Sep 7, 2017
After upgrading vendor directory for gnatsd, we can now use
natsd.ConfigureOptions() from PR nats-io/nats-server#578
We follow this model for NATS Streaming and chain the two
configuration of options.
This will solve any issue that we had with options override.
kozlovic added a commit that referenced this pull request Sep 8, 2017
This will allow NATS Streaming to provide its own version of what
should be printed when various flags are set.

Related to #578
kozlovic added a commit to nats-io/nats-streaming-server that referenced this pull request Sep 8, 2017
After upgrading vendor directory for gnatsd, we can now use
natsd.ConfigureOptions() from PR nats-io/nats-server#578
We follow this model for NATS Streaming and chain the two
configuration of options.
This will solve any issue that we had with options override.
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.

3 participants