From afdb66dfacb46a665a3008b85925093faa84295c Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 18 Jul 2018 14:14:38 +0100 Subject: [PATCH] Expose Group.CopyState() (#4304) This makes the `rules` package more useful to projects that use Prometheus as a library. Signed-off-by: Bryan Boreham --- rules/manager.go | 6 +++--- rules/manager_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rules/manager.go b/rules/manager.go index e89f0b633..4477bd6a6 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -277,11 +277,11 @@ func (g *Group) evalTimestamp() time.Time { return time.Unix(0, base+offset) } -// copyState copies the alerting rule and staleness related state from the given group. +// CopyState copies the alerting rule and staleness related state from the given group. // // Rules are matched based on their name. If there are duplicates, the // first is matched with the first, second with the second etc. -func (g *Group) copyState(from *Group) { +func (g *Group) CopyState(from *Group) { g.evaluationDuration = from.evaluationDuration ruleMap := make(map[string][]int, len(from.rules)) @@ -498,7 +498,7 @@ func (m *Manager) Update(interval time.Duration, files []string) error { go func(newg *Group) { if ok { oldg.stop() - newg.copyState(oldg) + newg.CopyState(oldg) } go func() { // Wait with starting evaluation until the rule manager diff --git a/rules/manager_test.go b/rules/manager_test.go index eade6e838..9860f098b 100644 --- a/rules/manager_test.go +++ b/rules/manager_test.go @@ -271,7 +271,7 @@ func TestCopyState(t *testing.T) { }, seriesInPreviousEval: make([]map[string]labels.Labels, 6), } - newGroup.copyState(oldGroup) + newGroup.CopyState(oldGroup) want := []map[string]labels.Labels{ map[string]labels.Labels{"r3a": nil},