From 77ec575b46d2b3518c7554509a72d95246c20bea Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 23 May 2016 14:51:41 +0200 Subject: [PATCH] tech(alerting): fixes broken unit-tests --- pkg/models/alerts.go | 12 +++++++++--- pkg/services/alerting/alerting.go | 12 ++++++++++-- pkg/services/alerting/alerting_test.go | 4 ++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pkg/models/alerts.go b/pkg/models/alerts.go index c5cba44022d..6f4fce87f09 100644 --- a/pkg/models/alerts.go +++ b/pkg/models/alerts.go @@ -30,10 +30,16 @@ type AlertRule struct { Updated time.Time `json:"updated"` } -type HeartBeat struct { +type AlertingClusterInfo struct { + ServerId string + ClusterSize int + UptimePosition int +} + +type HeartBeatCommand struct { ServerId string - Updated time.Time - Created time.Time + + Result AlertingClusterInfo } type AlertRuleChange struct { diff --git a/pkg/services/alerting/alerting.go b/pkg/services/alerting/alerting.go index fb434385c78..ca3f11efec5 100644 --- a/pkg/services/alerting/alerting.go +++ b/pkg/services/alerting/alerting.go @@ -5,6 +5,7 @@ import ( "strconv" "time" + "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/log" m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/setting" @@ -47,9 +48,16 @@ func (this *Scheduler) heartBeat() { //write heartBeat to db. //get the modulus position of active servers + cmd := &m.HeartBeatCommand{ServerId: this.serverId} log.Info("Heartbeat: Sending heartbeat from " + this.serverId) - this.clusterSize = 1 - this.serverPosition = 1 + err := bus.Dispatch(cmd) + + if err != nil { + log.Error(1, "Failed to send heartbeat.") + } else { + this.clusterSize = cmd.Result.ClusterSize + this.serverPosition = cmd.Result.UptimePosition + } } func (this *Scheduler) Dispatch(reader RuleReader) { diff --git a/pkg/services/alerting/alerting_test.go b/pkg/services/alerting/alerting_test.go index e3f199a16a3..8e6b118ed40 100644 --- a/pkg/services/alerting/alerting_test.go +++ b/pkg/services/alerting/alerting_test.go @@ -43,7 +43,7 @@ func TestAlertingScheduler(t *testing.T) { scheduler.updateJobs(mockFn) So(len(scheduler.jobs), ShouldEqual, 3) - So(scheduler.jobs[0].id, ShouldEqual, 1) + So(scheduler.jobs[0].rule.Id, ShouldEqual, 1) }) Convey("six servers", func() { @@ -57,7 +57,7 @@ func TestAlertingScheduler(t *testing.T) { scheduler.updateJobs(mockFn) So(len(scheduler.jobs), ShouldEqual, 1) - So(scheduler.jobs[0].id, ShouldEqual, 6) + So(scheduler.jobs[0].rule.Id, ShouldEqual, 6) }) Convey("more servers then alerts", func() {