Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule: Fix temporary rule filename composition issue #4468

Merged
merged 4 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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