From 44d880d4e1fa9e0f05f4b7b07c8243f2a45d363f Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Tue, 20 Jul 2021 10:25:54 +0200 Subject: [PATCH 1/3] Adjust rule filename composition Signed-off-by: Matej Gera --- pkg/rules/manager.go | 2 +- pkg/rules/manager_test.go | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/rules/manager.go b/pkg/rules/manager.go index b671abb207..d2500205bc 100644 --- a/pkg/rules/manager.go +++ b/pkg/rules/manager.go @@ -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 diff --git a/pkg/rules/manager_test.go b/pkg/rules/manager_test.go index d4230da74c..288abe729a 100644 --- a/pkg/rules/manager_test.go +++ b/pkg/rules/manager_test.go @@ -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) @@ -171,7 +176,7 @@ groups: thanosRuleMgr := NewManager( context.Background(), reg, - dir, + dataDir, rules.ManagerOptions{ Logger: log.NewLogfmtLogger(os.Stderr), Queryable: nopQueryable{}, @@ -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"), ) From 5a12db9a1ddec5c535b5666a70c8571cfb9f32e4 Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Thu, 22 Jul 2021 09:55:29 +0200 Subject: [PATCH 2/3] Update CHANGELOG.md Signed-off-by: Matej Gera --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfabd3cf3d..e5712ba024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Fixed - [#4442](https://github.com/thanos-io/thanos/pull/4442) rule: fix reload signal not working +- [#4468] (https://github.com/thanos-io/thanos/pull/4468) Rule: Fix temporary rule filename composition issue ### Changed From a1302e09e921a3feb6075c9466f5107987980335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Thu, 29 Jul 2021 18:22:32 +0300 Subject: [PATCH 3/3] Update CHANGELOG.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Giedrius Statkevičius --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cd62fb743..e6b49139e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Fixed -- [#4442](https://github.com/thanos-io/thanos/pull/4442) rule: fix reload signal not working -- [#4468](https://github.com/thanos-io/thanos/pull/4468) Rule: Fix temporary rule filename composition issue +- [#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