Skip to content

Commit

Permalink
Do not log 'unable to read rules directory' at startup if directory h…
Browse files Browse the repository at this point in the history
…asn't been created yet (grafana#7434)
  • Loading branch information
liguozhong authored and changhyuni committed Nov 8, 2022
1 parent 9826e8e commit e25cef3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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)
}

0 comments on commit e25cef3

Please sign in to comment.