Skip to content

Commit

Permalink
Adjust rule filename composition
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Gera <matejgera@gmail.com>
  • Loading branch information
matej-g committed Jul 20, 2021
1 parent 0058003 commit 44d880d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/rules/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (m *Manager) Update(evalInterval time.Duration, files []string) error {

// Use full file name appending to work dir, so we can differentiate between different dirs and same filenames(!).
// This will be also used as key for file group name.
newFn := filepath.Join(m.workDir, s.String(), strings.TrimLeft(fn, m.workDir))
newFn := filepath.Join(m.workDir, s.String(), fn)
if err := os.MkdirAll(filepath.Dir(newFn), os.ModePerm); err != nil {
errs.Add(errors.Wrapf(err, "create %s", filepath.Dir(newFn)))
continue
Expand Down
23 changes: 14 additions & 9 deletions pkg/rules/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ groups:
func TestUpdate_Error_UpdatePartial(t *testing.T) {
dir, err := ioutil.TempDir("", "test_rule_rule_groups")
testutil.Ok(t, err)
defer func() { testutil.Ok(t, os.RemoveAll(dir)) }()
dataDir, err := ioutil.TempDir("", "test_rule_data")
testutil.Ok(t, err)
defer func() {
testutil.Ok(t, os.RemoveAll(dir))
testutil.Ok(t, os.RemoveAll(dataDir))
}()
err = os.MkdirAll(filepath.Join(dir, "subdir"), 0775)
testutil.Ok(t, err)

Expand Down Expand Up @@ -171,7 +176,7 @@ groups:
thanosRuleMgr := NewManager(
context.Background(),
reg,
dir,
dataDir,
rules.ManagerOptions{
Logger: log.NewLogfmtLogger(os.Stderr),
Queryable: nopQueryable{},
Expand Down Expand Up @@ -200,13 +205,13 @@ groups:
// Also, check metrics: Regression test: https://github.com/thanos-io/thanos/issues/3083
testutil.Equals(t,
map[string]float64{
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/ABORT/abort.yaml;something2,strategy=abort}", dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/ABORT/bdir/no_strategy.yaml;something8,strategy=abort}", dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/ABORT/combined.yaml;something6,strategy=abort}", dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/ABORT/combined.yaml;something7,strategy=abort}", dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/ABORT/no_strategy.yaml;something1,strategy=abort}", dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/WARN/combined.yaml;something5,strategy=warn}", dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/WARN/warn.yaml;something3,strategy=warn}", dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/ABORT%s/abort.yaml;something2,strategy=abort}", dataDir, dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/ABORT%s/subdir/no_strategy.yaml;something8,strategy=abort}", dataDir, dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/ABORT%s/combined.yaml;something6,strategy=abort}", dataDir, dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/ABORT%s/combined.yaml;something7,strategy=abort}", dataDir, dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/ABORT%s/no_strategy.yaml;something1,strategy=abort}", dataDir, dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/WARN%s/combined.yaml;something5,strategy=warn}", dataDir, dir): 1,
fmt.Sprintf("prometheus_rule_group_rules{rule_group=%s/.tmp-rules/WARN%s/warn.yaml;something3,strategy=warn}", dataDir, dir): 1,
},
extprom.CurrentGaugeValuesFor(t, reg, "prometheus_rule_group_rules"),
)
Expand Down

0 comments on commit 44d880d

Please sign in to comment.