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

Adds glob support for filepath in tools command #4105

Merged
merged 5 commits into from Apr 30, 2021

Conversation

someshkoli
Copy link
Contributor

@someshkoli someshkoli commented Apr 24, 2021

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

Adds glob check for filepaths provided via cli. Checks for each matching file path and throws Matching file not found error if no file matches the pattern.

fixes #4082

Verification

Added a basic unit test

 - Adds glob check
 - Adds test and test files
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
cmd/thanos/tools.go Outdated Show resolved Hide resolved
@@ -39,26 +41,33 @@ func checkRulesFiles(logger log.Logger, files *[]string) error {

for _, fn := range *files {
level.Info(logger).Log("msg", "checking", "filename", fn)
f, err := os.Open(fn)
matches, err := filepath.Glob(fn)
if matches == nil {
Copy link
Member

Choose a reason for hiding this comment

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

We should check the err first and then matches, because matches will most likely be nil in case there is some other error and we will be overwriting that error with "Matching file not found".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right 🤔

Signed-off-by: someshkoli <kolisomesh27@gmail.com>
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
@someshkoli
Copy link
Contributor Author

someshkoli commented Apr 25, 2021

Also, I guess these change should not affect e2e 🤔, not sure why its failing :\

Copy link
Member

@GiedriusS GiedriusS left a comment

Choose a reason for hiding this comment

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

Just some suggestions/questions but overall LGTM! Thank you for your work on this feature (:

cmd/thanos/tools.go Outdated Show resolved Hide resolved
cmd/thanos/tools.go Outdated Show resolved Hide resolved
cmd/thanos/tools.go Outdated Show resolved Hide resolved
cmd/thanos/tools.go Outdated Show resolved Hide resolved
cmd/thanos/tools.go Outdated Show resolved Hide resolved
cmd/thanos/tools.go Outdated Show resolved Hide resolved
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
Copy link
Member

@GiedriusS GiedriusS left a comment

Choose a reason for hiding this comment

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

Awesome work! Thanks a lot

failed.Add(err)
continue
}
defer func() { _ = f.Close() }()
Copy link
Member

Choose a reason for hiding this comment

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

Typically we'd use rununtil.CloseWithLogOnErr but since at the end the process closes immediately, this is fine. Just something to keep in mind for future contributions 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, Thanks 🙌

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.

rules-check doesn't accept globs as described in the documentation
3 participants