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

[Core] Utilize sys.exit in configcheck #3481

Merged
merged 4 commits into from
Aug 21, 2017

Conversation

nmuesch
Copy link
Contributor

@nmuesch nmuesch commented Aug 21, 2017

Note: Please remember to review the Datadog Contribution Guidelines
if you have not yet done so.

What does this PR do?

Utilizes the sys.exit() function in the configcheck command utility. This allows the exit code to be determined based on whether or not the yaml configs are good/bad.

Motivation

Customer Request. Now when running the one off config check script/command, you can utilize $? to determine if there are any bad yaml files.

Previously, if the configcheck finished and printed that there were errors in the yaml files, the following command:

echo $?

would output `0. Now this outputs 1, indicating there was a failure.

Testing Guidelines

An overview on testing
is available in our contribution guidelines.

Additional Notes

Anything else we should know when reviewing?

Copy link
Member

@olivielpeau olivielpeau left a comment

Choose a reason for hiding this comment

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

This fix makes a lot of sense, thanks!

I think the current behavior is actually a regression that was introduced way back in #1422.

I don't think exiting directly from the configcheck option is great though, there might be other callers of this function that just want to check if the configs are valid without exiting the process if they're not.

The caller of configcheck should use the returned value of the function and exit with that value if it makes sense to exit. Does that make sense?

Copy link
Member

@olivielpeau olivielpeau left a comment

Choose a reason for hiding this comment

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

Getting better, added one comment on the current changes

agent.py Outdated
@@ -602,8 +602,8 @@ def parent_func():
check.stop()

elif 'configcheck' == command or 'configtest' == command:
configcheck()
sd_configcheck(agentConfig)
if configcheck() or sd_configcheck(agentConfig):
Copy link
Member

Choose a reason for hiding this comment

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

sd_configcheck doesn't return anything so I don't think it makes sense to have it in the condition here. I'm not sure we could make that function return a sensible value that reflects the status of the service discovery confs...

So instead of this, I think we should simply make this code return the value that configcheck returns. The part of the code under __main__ will then exit with the correct status code.

@olivielpeau olivielpeau modified the milestones: 5.17, Triage Aug 21, 2017
@olivielpeau olivielpeau merged commit b1f9c62 into master Aug 21, 2017
@olivielpeau olivielpeau deleted the nick/use_exit_in_configcheck branch August 21, 2017 18:37
@olivielpeau
Copy link
Member

Thanks @nmuesch! Merged, this should be included in 5.17.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants