Skip to content

Commit

Permalink
merge with base branch and fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Nov 5, 2024
2 parents dcedfa7 + d42af76 commit 7297c0c
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 134 deletions.
2 changes: 1 addition & 1 deletion datatypes/emergency_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package datatypes
type HeartbeatType string

const (
HeartbeatTypeNotSet HeartbeatType = "Heartbeat_type_not_set"
HeartbeatTypeNotSet HeartbeatType = "heartbeat_type_not_set"
HeartbeatNotifier HeartbeatType = "heartbeat_notifier"
HeartbeatDatabase HeartbeatType = "heartbeat_database"
HeartbeatLocalChecker HeartbeatType = "heartbeat_local_checker"
Expand Down
14 changes: 7 additions & 7 deletions mock/heartbeat/heartbeat.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions notifier/selfstate/heartbeat/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ func (heartbeater *databaseHeartbeater) Check() (State, error) {
return StateOK, err
}

// NeedTurnOffNotifier is a function that checks to see if the notifier needs to be turned off.
func (heartbeater databaseHeartbeater) NeedTurnOffNotifier() bool {
return heartbeater.cfg.NeedTurnOffNotifier
}

// Type is a function that returns the current heartbeat type.
func (databaseHeartbeater) Type() datatypes.HeartbeatType {
return datatypes.HeartbeatDatabase
Expand Down
19 changes: 0 additions & 19 deletions notifier/selfstate/heartbeat/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,6 @@ func TestDatabaseHeartbeaterCheck(t *testing.T) {
})
}

func TestDatabaseHeartbeaterNeedTurnOffNotifier(t *testing.T) {
_, _, _, heartbeaterBase := heartbeaterHelper(t)

Convey("Test databaseHeartbeater.TurnOffNotifier", t, func() {
cfg := DatabaseHeartbeaterConfig{
HeartbeaterBaseConfig: HeartbeaterBaseConfig{
NeedTurnOffNotifier: true,
},
RedisDisconnectDelay: defaultRedisDisconnectDelay,
}

databaseHeartbeater, err := NewDatabaseHeartbeater(cfg, heartbeaterBase)
So(err, ShouldBeNil)

needTurnOffNotifier := databaseHeartbeater.NeedTurnOffNotifier()
So(needTurnOffNotifier, ShouldBeTrue)
})
}

func TestDatabaseHeartbeaterType(t *testing.T) {
_, _, _, heartbeaterBase := heartbeaterHelper(t)

Expand Down
7 changes: 1 addition & 6 deletions notifier/selfstate/heartbeat/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
type FilterHeartbeaterConfig struct {
HeartbeaterBaseConfig

MetricReceivedDelay time.Duration `validate:"required_if=Enabled true,gte=00"`
MetricReceivedDelay time.Duration `validate:"required_if=Enabled true,gte=0"`
}

type filterHeartbeater struct {
Expand Down Expand Up @@ -67,11 +67,6 @@ func (heartbeater *filterHeartbeater) Check() (State, error) {
return StateOK, nil
}

// NeedTurnOffNotifier is a function that checks to see if the notifier needs to be turned off.
func (heartbeater filterHeartbeater) NeedTurnOffNotifier() bool {
return heartbeater.cfg.NeedTurnOffNotifier
}

// Type is a function that returns the current heartbeat type.
func (filterHeartbeater) Type() datatypes.HeartbeatType {
return datatypes.HeartbeatFilter
Expand Down
19 changes: 0 additions & 19 deletions notifier/selfstate/heartbeat/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,6 @@ func TestFilterHeartbeaterCheck(t *testing.T) {
})
}

func TestFilterHeartbeaterNeedTurnOffNotifier(t *testing.T) {
_, _, _, heartbeaterBase := heartbeaterHelper(t)

Convey("Test filterHeartbeater.TurnOffNotifier", t, func() {
cfg := FilterHeartbeaterConfig{
HeartbeaterBaseConfig: HeartbeaterBaseConfig{
NeedTurnOffNotifier: true,
},
MetricReceivedDelay: defaultMetricReceivedDelay,
}

filterHeartbeater, err := NewFilterHeartbeater(cfg, heartbeaterBase)
So(err, ShouldBeNil)

needTurnOffNotifier := filterHeartbeater.NeedTurnOffNotifier()
So(needTurnOffNotifier, ShouldBeTrue)
})
}

func TestFilterHeartbeaterType(t *testing.T) {
_, _, _, heartbeaterBase := heartbeaterHelper(t)

Expand Down
5 changes: 2 additions & 3 deletions notifier/selfstate/heartbeat/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const (
StateError State = "heartbeat_state_error"
)

// IsDegraded checks if the condition is still degraded.
func (State) IsDegraded(newState State) bool {
// IsDegraded checks if the condition has degraded.
func (lastState State) IsDegraded(newState State) bool {
return newState == StateError
}

Expand All @@ -28,7 +28,6 @@ func (lastState State) IsRecovered(newState State) bool {
// Heartbeater is the interface for simplified events verification.
type Heartbeater interface {
Check() (State, error)
NeedTurnOffNotifier() bool
AlertSettings() AlertConfig
Type() datatypes.HeartbeatType
}
Expand Down
38 changes: 35 additions & 3 deletions notifier/selfstate/heartbeat/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,38 @@ func heartbeaterHelper(t *testing.T) (*mock_moira_alert.MockDatabase, *mock_cloc
}

func TestStateIsDegradated(t *testing.T) {
Convey("Test state.IsDegradated", t, func() {
Convey("With degradated state", func() {
Convey("Test state.IsDegraded", t, func() {
Convey("With continue degraded", func() {
lastState := StateError
newState := StateError

degradated := lastState.IsDegraded(newState)
So(degradated, ShouldBeTrue)
})

Convey("With degraded state", func() {
lastState := StateOK
newState := StateError

degradated := lastState.IsDegraded(newState)
So(degradated, ShouldBeTrue)
})

Convey("Without degradated state", func() {
Convey("Without degraded state", func() {
lastState := StateError
newState := StateOK

degradated := lastState.IsDegraded(newState)
So(degradated, ShouldBeFalse)
})

Convey("With continue recovered", func() {
lastState := StateOK
newState := StateOK

degradated := lastState.IsDegraded(newState)
So(degradated, ShouldBeFalse)
})
})
}

Expand All @@ -67,6 +83,22 @@ func TestStateIsRecovered(t *testing.T) {
recovered := lastState.IsRecovered(newState)
So(recovered, ShouldBeFalse)
})

Convey("With continue recovered", func() {
lastState := StateOK
newState := StateOK

recovered := lastState.IsRecovered(newState)
So(recovered, ShouldBeFalse)
})

Convey("With continue degraded", func() {
lastState := StateError
newState := StateError

recovered := lastState.IsRecovered(newState)
So(recovered, ShouldBeFalse)
})
})
}

Expand Down
5 changes: 0 additions & 5 deletions notifier/selfstate/heartbeat/local_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ func (heartbeater *localCheckerHeartbeater) Check() (State, error) {
return StateOK, nil
}

// NeedTurnOffNotifier is a function that checks to see if the notifier needs to be turned off.
func (heartbeater localCheckerHeartbeater) NeedTurnOffNotifier() bool {
return heartbeater.cfg.NeedTurnOffNotifier
}

// Type is a function that returns the current heartbeat type.
func (localCheckerHeartbeater) Type() datatypes.HeartbeatType {
return datatypes.HeartbeatLocalChecker
Expand Down
19 changes: 0 additions & 19 deletions notifier/selfstate/heartbeat/local_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,6 @@ func TestLocalCheckerHeartbeaterCheck(t *testing.T) {
})
}

func TestLocalCheckerHeartbeaterNeedTurnOffNotifier(t *testing.T) {
_, _, _, heartbeaterBase := heartbeaterHelper(t)

Convey("Test localCheckerHeartbeater.TurnOffNotifier", t, func() {
cfg := LocalCheckerHeartbeaterConfig{
HeartbeaterBaseConfig: HeartbeaterBaseConfig{
NeedTurnOffNotifier: true,
},
LocalCheckDelay: defaultLocalCheckDelay,
}

localCheckerHeartbeater, err := NewLocalCheckerHeartbeater(cfg, heartbeaterBase)
So(err, ShouldBeNil)

needTurnOffNotifier := localCheckerHeartbeater.NeedTurnOffNotifier()
So(needTurnOffNotifier, ShouldBeTrue)
})
}

func TestLocalCheckerHeartbeaterType(t *testing.T) {
_, _, _, heartbeaterBase := heartbeaterHelper(t)

Expand Down
5 changes: 0 additions & 5 deletions notifier/selfstate/heartbeat/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ func (heartbeater *notifierHeartbeater) Check() (State, error) {
return StateOK, nil
}

// NeedTurnOffNotifier is a function that checks to see if the notifier needs to be turned off.
func (heartbeater *notifierHeartbeater) NeedTurnOffNotifier() bool {
return heartbeater.cfg.NeedTurnOffNotifier
}

// Type is a function that returns the current heartbeat type.
func (notifierHeartbeater) Type() datatypes.HeartbeatType {
return datatypes.HeartbeatNotifier
Expand Down
18 changes: 0 additions & 18 deletions notifier/selfstate/heartbeat/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,6 @@ func TestNotifierHeartbeaterCheck(t *testing.T) {
})
}

func TestNotifierHeartbeaterNeedTurnOffNotifier(t *testing.T) {
_, _, _, heartbeaterBase := heartbeaterHelper(t)

Convey("Test notifierHeartbeater.TurnOffNotifier", t, func() {
cfg := NotifierHeartbeaterConfig{
HeartbeaterBaseConfig: HeartbeaterBaseConfig{
NeedTurnOffNotifier: true,
},
}

notifierHeartbeater, err := NewNotifierHeartbeater(cfg, heartbeaterBase)
So(err, ShouldBeNil)

needTurnOffNotifier := notifierHeartbeater.NeedTurnOffNotifier()
So(needTurnOffNotifier, ShouldBeTrue)
})
}

func TestNotifierHeartbeaterType(t *testing.T) {
_, _, _, heartbeaterBase := heartbeaterHelper(t)

Expand Down
5 changes: 0 additions & 5 deletions notifier/selfstate/heartbeat/remote_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ func (heartbeater remoteCheckerHeartbeater) Check() (State, error) {
return StateOK, nil
}

// NeedTurnOffNotifier is a function that checks to see if the notifier needs to be turned off.
func (heartbeater remoteCheckerHeartbeater) NeedTurnOffNotifier() bool {
return heartbeater.cfg.NeedTurnOffNotifier
}

// Type is a function that returns the current heartbeat type.
func (remoteCheckerHeartbeater) Type() datatypes.HeartbeatType {
return datatypes.HeartbeatRemoteChecker
Expand Down
19 changes: 0 additions & 19 deletions notifier/selfstate/heartbeat/remote_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,6 @@ func TestRemoteCheckerHeartbeaterCheck(t *testing.T) {
})
}

func TestRemoteCheckerHeartbeaterNeedTurnOffNotifier(t *testing.T) {
_, _, _, heartbeaterBase := heartbeaterHelper(t)

Convey("Test remoteCheckerHeartbeater.TurnOffNotifier", t, func() {
cfg := RemoteCheckerHeartbeaterConfig{
HeartbeaterBaseConfig: HeartbeaterBaseConfig{
NeedTurnOffNotifier: true,
},
RemoteCheckDelay: defaultRemoteCheckDelay,
}

remoteCheckerHeartbeater, err := NewRemoteCheckerHeartbeater(cfg, heartbeaterBase)
So(err, ShouldBeNil)

needTurnOffNotifier := remoteCheckerHeartbeater.NeedTurnOffNotifier()
So(needTurnOffNotifier, ShouldBeTrue)
})
}

func TestRemoteCheckerHeartbeaterType(t *testing.T) {
_, _, _, heartbeaterBase := heartbeaterHelper(t)

Expand Down

0 comments on commit 7297c0c

Please sign in to comment.