Просмотр исходного кода

tech(alerting): fixes broken unit-tests

bergquist 9 лет назад
Родитель
Сommit
77ec575b46
3 измененных файлов с 21 добавлено и 7 удалено
  1. 9 3
      pkg/models/alerts.go
  2. 10 2
      pkg/services/alerting/alerting.go
  3. 2 2
      pkg/services/alerting/alerting_test.go

+ 9 - 3
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 {

+ 10 - 2
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) {

+ 2 - 2
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() {