Alerting: Fix bug not creating filepath for silences/nflog if it does not exist (#39174)

We created this filepath just as we're about persist the templates - with the latest change, we now need to create it sooner.
This commit is contained in:
gotjosh
2021-09-14 14:40:59 +01:00
committed by GitHub
parent 9b20a24989
commit 2b1d3d27e4
2 changed files with 27 additions and 0 deletions

View File

@@ -93,6 +93,12 @@ func (fs *FileStore) IsExists(fn string) bool {
// WriteFileToDisk writes a file with the provided name and contents to the Alertmanager working directory with the default grafana permission.
func (fs *FileStore) WriteFileToDisk(fn string, content []byte) error {
// Ensure the working directory is created
err := os.MkdirAll(fs.workingDirPath, 0750)
if err != nil {
return fmt.Errorf("unable to create the working directory %q: %s", fs.workingDirPath, err)
}
return os.WriteFile(fs.pathFor(fn), content, 0644)
}