mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Expose Group.CopyState() (#4304)
This makes the `rules` package more useful to projects that use Prometheus as a library. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
372e7652b7
commit
afdb66dfac
|
@ -277,11 +277,11 @@ func (g *Group) evalTimestamp() time.Time {
|
||||||
return time.Unix(0, base+offset)
|
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
|
// Rules are matched based on their name. If there are duplicates, the
|
||||||
// first is matched with the first, second with the second etc.
|
// 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
|
g.evaluationDuration = from.evaluationDuration
|
||||||
|
|
||||||
ruleMap := make(map[string][]int, len(from.rules))
|
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) {
|
go func(newg *Group) {
|
||||||
if ok {
|
if ok {
|
||||||
oldg.stop()
|
oldg.stop()
|
||||||
newg.copyState(oldg)
|
newg.CopyState(oldg)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
// Wait with starting evaluation until the rule manager
|
// Wait with starting evaluation until the rule manager
|
||||||
|
|
|
@ -271,7 +271,7 @@ func TestCopyState(t *testing.T) {
|
||||||
},
|
},
|
||||||
seriesInPreviousEval: make([]map[string]labels.Labels, 6),
|
seriesInPreviousEval: make([]map[string]labels.Labels, 6),
|
||||||
}
|
}
|
||||||
newGroup.copyState(oldGroup)
|
newGroup.CopyState(oldGroup)
|
||||||
|
|
||||||
want := []map[string]labels.Labels{
|
want := []map[string]labels.Labels{
|
||||||
map[string]labels.Labels{"r3a": nil},
|
map[string]labels.Labels{"r3a": nil},
|
||||||
|
|
Loading…
Reference in a new issue