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

fix filechecker in health with precondition check #2072

Merged
merged 1 commit into from
Dec 9, 2016
Merged

fix filechecker in health with precondition check #2072

merged 1 commit into from
Dec 9, 2016

Conversation

andyxning
Copy link
Contributor

This PR is a migration of #2049

FileChecker can not work properly when the specified file can not be Stat because the app has no proper permission (read and execute permission for directory along with the specified file path). This should be make clear to end users and under such circumstance, FileChecker should return error instead nil to make the precondition ready. Otherwise, we can not actually disable the app by touch the disable file.

We should also add more document about the usage of FileChecker.

FileChecker only accepts absolute or relative file path. It does not work properly with tilde(~). You should make sure that the application has proper permission(read and execute permission for directory along with the specified file path). Otherwise, the FileChecker will report error and file health check is not ok.
Also, this PR will add support for relative path. And, if it can not be expanded to the corresponding absolute path, an error will be returned by FileChecker. This is also one precondition that can make FileChecker work when we want to disable one app by touching a disable file. :)

@codecov-io
Copy link

codecov-io commented Nov 17, 2016

Current coverage is 51.24% (diff: 62.50%)

Merging #2072 into master will decrease coverage by 8.58%

@@             master      #2072   diff @@
==========================================
  Files           128        128           
  Lines         11402      11328     -74   
  Methods           0          0           
  Messages          0          0           
  Branches          0          0           
==========================================
- Hits           6822       5805   -1017   
- Misses         3714       4776   +1062   
+ Partials        866        747    -119   

Powered by Codecov. Last update 314144a...658cda6

} else if os.IsNotExist(err) {
return nil
} else {
return fmt.Errorf("%s", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this does not need to be wrapped by fmt.Errorf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, later to change this.

return fmt.Errorf("get absolute path for %q error. %s", f, err)
}
_, err = os.Stat(absoluteFilePath)
if os.IsPermission(err) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This error check is not necessary, the else case already covers returning an error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, later to change this, too.

@dmcgowan dmcgowan added this to the Registry/2.7 milestone Nov 21, 2016
@andyxning
Copy link
Contributor Author

andyxning commented Nov 22, 2016

@dmcgowan Adjusts has been done. PTAL.

if _, err := os.Stat(f); err == nil {
absoluteFilePath, err := filepath.Abs(f)
if err != nil {
return fmt.Errorf("get absolute path for %q error. %s", f, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

to be more consistent with other errors maybe failed to get absolute path for %q: %v

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. PTAL.

return fmt.Errorf("get absolute path for %q error. %s", f, err)
}
_, err = os.Stat(absoluteFilePath)

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: blank line should be before call which returns checked error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@andyxning
Copy link
Contributor Author

@dmcgowan PTAL.

@andyxning
Copy link
Contributor Author

Can anybody review this?

} else if os.IsNotExist(err) {
return nil
} else {
return err
Copy link
Collaborator

Choose a reason for hiding this comment

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

putting this in else is not needed, just have return err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. PTAL.

@dmcgowan
Copy link
Collaborator

dmcgowan commented Dec 5, 2016

one nit, otherwise LGTM

@andyxning
Copy link
Contributor Author

@dmcgowan PTAL.

@dmcgowan dmcgowan merged commit 923c776 into distribution:master Dec 9, 2016
@andyxning andyxning deleted the fix_filechecker_in_health branch December 9, 2016 21:55
@@ -122,6 +122,11 @@
// # curl localhost:5001/debug/health
// {"fileChecker":"file exists"}
//
// FileChecker only accepts absolute or relative file path. It does not work properly with tilde(~).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we please get this formatted properly?

@stevvooe
Copy link
Collaborator

@andyxning Please fix the formatting in the doc comment.

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.

5 participants