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

pull/7436/head
李国忠 4 years ago committed by GitHub
parent 9c8a827576
commit 8dcc4b3ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      pkg/ruler/base/mapper.go
  2. 12
      pkg/ruler/base/mapper_test.go

@ -3,6 +3,7 @@ package base
import (
"crypto/md5"
"net/url"
"os"
"path/filepath"
"sort"
@ -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())

@ -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)
}

Loading…
Cancel
Save