mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 06:47:28 -08:00
cmd/promtool: resolve relative paths in alert test files (#5336)
Like `promtool check config <path/to/foo.yaml>`, which resolves relative paths inside foo.yaml to be relative to `path/to`, this now makes `promtool test rules <path/to/test.yaml>` do the same thing. Signed-off-by: David Symonds <dsymonds@gmail.com>
This commit is contained in:
parent
8fdfa8abea
commit
7a60e22c2d
|
@ -18,6 +18,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -68,6 +69,7 @@ func ruleUnitTest(filename string) []error {
|
||||||
if err := yaml.UnmarshalStrict(b, &unitTestInp); err != nil {
|
if err := yaml.UnmarshalStrict(b, &unitTestInp); err != nil {
|
||||||
return []error{err}
|
return []error{err}
|
||||||
}
|
}
|
||||||
|
resolveFilepaths(filepath.Dir(filename), &unitTestInp)
|
||||||
|
|
||||||
if unitTestInp.EvaluationInterval == 0 {
|
if unitTestInp.EvaluationInterval == 0 {
|
||||||
unitTestInp.EvaluationInterval = 1 * time.Minute
|
unitTestInp.EvaluationInterval = 1 * time.Minute
|
||||||
|
@ -125,6 +127,16 @@ func (utf *unitTestFile) maxEvalTime() time.Duration {
|
||||||
return maxd
|
return maxd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolveFilepaths joins all relative paths in a configuration
|
||||||
|
// with a given base directory.
|
||||||
|
func resolveFilepaths(baseDir string, utf *unitTestFile) {
|
||||||
|
for i, rf := range utf.RuleFiles {
|
||||||
|
if rf != "" && !filepath.IsAbs(rf) {
|
||||||
|
utf.RuleFiles[i] = filepath.Join(baseDir, rf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// testGroup is a group of input series and tests associated with it.
|
// testGroup is a group of input series and tests associated with it.
|
||||||
type testGroup struct {
|
type testGroup struct {
|
||||||
Interval time.Duration `yaml:"interval"`
|
Interval time.Duration `yaml:"interval"`
|
||||||
|
|
Loading…
Reference in a new issue