-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Moira states to separate file, make types for it
- Loading branch information
1 parent
e476540
commit 8b27e38
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package moira | ||
|
||
type State string | ||
|
||
type TtlState string | ||
|
||
// Default moira triggers and metrics states | ||
const ( | ||
StateOK State = "OK" | ||
StateWARN State = "WARN" | ||
StateERROR State = "ERROR" | ||
StateNODATA State = "NODATA" | ||
// Use this for trigger check unexpected errors | ||
StateEXCEPTION State = "EXCEPTION" | ||
// Use this only for test notifications | ||
StateTEST State = "TEST" | ||
) | ||
|
||
// Moira ttl states | ||
const ( | ||
TTLStateOK TtlState = "OK" | ||
TTLStateWARN TtlState = "WARN" | ||
TTLStateERROR TtlState = "ERROR" | ||
TTLStateNODATA TtlState = "NODATA" | ||
TTLStateDEL TtlState = "DEL" | ||
) | ||
|
||
var ( | ||
eventStatesPriority = [...]State{StateOK, StateWARN, StateERROR, StateNODATA, StateEXCEPTION, StateTEST} | ||
stateScore = map[State]int64{ | ||
StateOK: 0, | ||
StateWARN: 1, | ||
StateERROR: 100, | ||
StateNODATA: 1000, | ||
StateEXCEPTION: 100000, | ||
} | ||
eventStateWeight1 = map[State]int{ | ||
StateOK: 0, | ||
StateWARN: 1, | ||
StateERROR: 100, | ||
StateNODATA: 10000, | ||
} | ||
) | ||
|
||
func (state TtlState) ToMetricState() State { | ||
if state == TTLStateDEL { | ||
return StateNODATA | ||
} | ||
return State(state) | ||
} | ||
|
||
// ToTriggerState is an auxiliary function to handle trigger state properly. | ||
func (state TtlState) ToTriggerState() State { | ||
if state == TTLStateDEL { | ||
return StateOK | ||
} | ||
return State(state) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package moira | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestTtlState_ToMetricState(t *testing.T) { | ||
Convey("ToMetricState test", t, func() { | ||
So(TTLStateDEL.ToMetricState(), ShouldResemble, StateNODATA) | ||
So(TTLStateOK.ToMetricState(), ShouldResemble, StateOK) | ||
So(TTLStateWARN.ToMetricState(), ShouldResemble, StateWARN) | ||
So(TTLStateERROR.ToMetricState(), ShouldResemble, StateERROR) | ||
So(TTLStateNODATA.ToMetricState(), ShouldResemble, StateNODATA) | ||
}) | ||
} | ||
|
||
func TestTtlState_ToTriggerState(t *testing.T) { | ||
Convey("ToTriggerState test", t, func() { | ||
So(TTLStateDEL.ToTriggerState(), ShouldResemble, StateOK) | ||
So(TTLStateOK.ToTriggerState(), ShouldResemble, StateOK) | ||
So(TTLStateWARN.ToTriggerState(), ShouldResemble, StateWARN) | ||
So(TTLStateERROR.ToTriggerState(), ShouldResemble, StateERROR) | ||
So(TTLStateNODATA.ToTriggerState(), ShouldResemble, StateNODATA) | ||
}) | ||
} |