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

Do not log 'unable to read rules directory' at startup if directory hasn't been created yet #7434

Merged
merged 1 commit into from
Oct 17, 2022
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
6 changes: 6 additions & 0 deletions pkg/ruler/base/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package base
import (
"crypto/md5"
"net/url"
"os"
"path/filepath"
"sort"

Expand Down Expand Up @@ -60,6 +61,11 @@ func (m *mapper) users() ([]string, error) {
var result []string

dirs, err := afero.ReadDir(m.FS, m.Path)
if os.IsNotExist(err) {
// The directory may have not been created yet. With regards to this function
// it's like the ruler has no tenants and it shouldn't be considered an error.
return nil, nil
}
for _, u := range dirs {
if u.IsDir() {
result = append(result, u.Name())
Expand Down
12 changes: 12 additions & 0 deletions pkg/ruler/base/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,15 @@ func TestYamlFormatting(t *testing.T) {

require.Equal(t, expected, string(data))
}

func Test_mapper_CleanupShouldNotFailIfPathDoesNotExist(t *testing.T) {
m := &mapper{
Path: "/path-does-not-exist",
FS: afero.NewMemMapFs(),
logger: log.NewNopLogger(),
}

actual, err := m.users()
require.NoError(t, err)
require.Empty(t, actual)
}