Skip to content

Commit

Permalink
Rule: Fix temporary rule filename composition issue (#4468)
Browse files Browse the repository at this point in the history
* Adjust rule filename composition

Signed-off-by: Matej Gera <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Matej Gera <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Giedrius Statkevičius <[email protected]>

Co-authored-by: Giedrius Statkevičius <[email protected]>
Co-authored-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
3 people authored Jul 29, 2021
1 parent b7735a6 commit aa148f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

### Fixed

- [#4468](https://github.com/thanos-io/thanos/pull/4468) Rule: Fix temporary rule filename composition issue.
- [#4476](https://github.com/thanos-io/thanos/pull/4476) UI: fix incorrect html escape sequence used for '>' symbol.

### Changed
Expand Down
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 aa148f8

Please sign in to comment.