Skip to content

*: Fix issue #7550 - Check correct error when opening rule files in tools #7552

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cmd/thanos/testdata/rules-files/unreadable_valid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
groups:
- name: test-alert-group
partial_response_strategy: "warn"
interval: 2m
rules:
- alert: TestAlert
expr: 1
labels:
key: value
annotations:
key: value

- name: test-rule-group
partial_response_strategy: "warn"
interval: 2m
rules:
- record: test_metric
expr: 1
5 changes: 1 addition & 4 deletions cmd/thanos/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func checkRulesFiles(logger log.Logger, patterns *[]string) error {
if err != nil || matches == nil {
err = errors.New("matching file not found")
level.Error(logger).Log("result", "FAILED", "error", err)
level.Info(logger).Log()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are just empty logs, Its output is - level=info, So I removed all level.Info(logger).Log()

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 it might be intended to leave some spaces between lines.

Copy link
Contributor Author

@NishantBansal2003 NishantBansal2003 Jul 20, 2024

Choose a reason for hiding this comment

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

Ok, Should I reintroduce all instances of level.Info(logger).Log() throughout the tools.go, or only in this specific part(line 58) of the code?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have strong preference. I am ok either way to keep them or remove them.

failed.Add(err)
continue
}
Expand All @@ -64,8 +63,7 @@ func checkRulesFiles(logger log.Logger, patterns *[]string) error {
f, er := os.Open(fn)
if er != nil {
level.Error(logger).Log("result", "FAILED", "error", er)
level.Info(logger).Log()
failed.Add(err)
failed.Add(er)
continue
}
defer func() { _ = f.Close() }()
Expand All @@ -77,7 +75,6 @@ func checkRulesFiles(logger log.Logger, patterns *[]string) error {
level.Error(logger).Log("error", e.Error())
failed.Add(e)
}
level.Info(logger).Log()
continue
}
level.Info(logger).Log("result", "SUCCESS", "rules found", n)
Expand Down
8 changes: 8 additions & 0 deletions cmd/thanos/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"os"
"testing"

"github.com/go-kit/log"
Expand Down Expand Up @@ -44,4 +45,11 @@ func Test_CheckRules_Glob(t *testing.T) {
// invalid path
files = &[]string{"./testdata/rules-files/*.yamlaaa"}
testutil.NotOk(t, checkRulesFiles(logger, files), "expected err for file %s", files)

// Unreadble path
files = &[]string{"./testdata/rules-files/unreadable_valid.yaml"}
filename := (*files)[0]
testutil.Ok(t, os.Chmod(filename, 0000), "failed to change file permissions of %s to 0000", filename)
testutil.NotOk(t, checkRulesFiles(logger, files), "expected err for file %s", files)
testutil.Ok(t, os.Chmod(filename, 0777), "failed to change file permissions of %s to 0777", filename)
}
Loading