@@ -61,7 +61,7 @@ func randomState() int {
6161 return firing
6262}
6363
64- func createAlert (probability float64 , name , resourceName string , threshold int , targetLabels , resourceNames []string , annotations , labels model.LabelSet ) (* Alert , int ) {
64+ func createAlert (probability float64 , name , resourceName string , threshold , upperBound int , targetLabels , resourceNames []string , annotations , labels model.LabelSet ) (* Alert , int ) {
6565 if rand .Float64 () < probability {
6666 alertLabels := labels .Clone ()
6767 alertState := randomState ()
@@ -75,7 +75,7 @@ func createAlert(probability float64, name, resourceName string, threshold int,
7575 alertLabels [model .LabelName (lbl )] = model .LabelValue (resourceNames [idx ])
7676 }
7777 }
78- val := float64 (threshold ) + rand .Float64 ()* float64 (100 - threshold )
78+ val := float64 (threshold ) + rand .Float64 ()* float64 (upperBound - threshold )
7979 return & Alert {
8080 Annotations : annotations ,
8181 Labels : alertLabels ,
@@ -86,19 +86,19 @@ func createAlert(probability float64, name, resourceName string, threshold int,
8686 return nil , 0
8787}
8888
89- func createAlerts (probability float64 , name string , threshold int , targetLabels , resourceNames []string , annotations , labels model.LabelSet ) ([]* Alert , int ) {
89+ func createAlerts (probability float64 , name string , threshold , upperBound int , targetLabels , resourceNames []string , annotations , labels model.LabelSet ) ([]* Alert , int ) {
9090 alerts := []* Alert {}
9191 var ruleState int
9292 for _ , resourceName := range resourceNames {
93- if alert , state := createAlert (probability , name , resourceName , threshold , targetLabels , resourceNames , annotations , labels ); alert != nil {
93+ if alert , state := createAlert (probability , name , resourceName , threshold , upperBound , targetLabels , resourceNames , annotations , labels ); alert != nil {
9494 ruleState |= state
9595 alerts = append (alerts , alert )
9696 }
9797 }
9898 return alerts , ruleState
9999}
100100
101- func createRule (probability float64 , name , severity string , threshold int , bynetobs bool , nsLbl , nodeLbl []string ) AlertingRule {
101+ func createRule (probability float64 , name , severity string , threshold , upperBound int , bynetobs bool , nsLbl , nodeLbl []string ) AlertingRule {
102102 labels := model.LabelSet {
103103 "severity" : model .LabelValue (severity ),
104104 }
@@ -126,23 +126,24 @@ func createRule(probability float64, name, severity string, threshold int, bynet
126126 jsonNodeLbl = fmt .Sprintf (`"nodeLabels":[%s],` , strings .Join (quotedLbl , "," ))
127127 }
128128 annotations ["netobserv_io_network_health" ] = model .LabelValue (fmt .Sprintf (
129- `{%s%s"threshold":"%d","unit":"%%"}` ,
129+ `{%s%s"threshold":"%d","upperBound":"%d"," unit":"%%"}` ,
130130 jsonNsLbl ,
131131 jsonNodeLbl ,
132132 threshold ,
133+ upperBound ,
133134 ))
134135 ruleLabels := labels .Clone ()
135136 ruleLabels ["prometheus" ] = "openshift-monitoring/k8s"
136137 var alerts []* Alert
137138 var ruleState int
138139 if len (nsLbl ) > 0 {
139- alerts , ruleState = createAlerts (probability , name , threshold , nsLbl , namespaces , annotations , labels )
140+ alerts , ruleState = createAlerts (probability , name , threshold , upperBound , nsLbl , namespaces , annotations , labels )
140141 } else if len (nodeLbl ) > 0 {
141- alerts , ruleState = createAlerts (probability , name , threshold , nodeLbl , nodes , annotations , labels )
142+ alerts , ruleState = createAlerts (probability , name , threshold , upperBound , nodeLbl , nodes , annotations , labels )
142143 } else {
143144 // global
144145 alerts = []* Alert {}
145- if alert , state := createAlert (probability , name , "" , threshold , nil , nil , annotations , labels ); alert != nil {
146+ if alert , state := createAlert (probability , name , "" , threshold , upperBound , nil , nil , annotations , labels ); alert != nil {
146147 ruleState |= state
147148 alerts = append (alerts , alert )
148149 }
@@ -159,12 +160,13 @@ func createRule(probability float64, name, severity string, threshold int, bynet
159160func GetRules () func (w http.ResponseWriter , r * http.Request ) {
160161 return func (w http.ResponseWriter , _ * http.Request ) {
161162 alertingRules := []AlertingRule {
162- createRule (0.4 , "Packet delivery failed" , "info" , 5 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
163- createRule (0.3 , "You have reached your hourly rate limit" , "info" , 5 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
164- createRule (0.1 , "It's always DNS" , "warning" , 15 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
165- createRule (0.1 , "We're under attack" , "warning" , 20 , true , []string {}, []string {}),
166- createRule (0.1 , "Sh*t - Famous last words" , "critical" , 5 , true , []string {}, []string {"SrcK8S_Hostname" , "DstK8S_Hostname" }),
167- createRule (0.3 , "FromIngress" , "info" , 10 , false , []string {"exported_namespace" }, []string {}),
163+ createRule (0.4 , "Packet delivery failed" , "info" , 5 , 100 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
164+ createRule (0.3 , "You have reached your hourly rate limit" , "info" , 5 , 100 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
165+ createRule (0.1 , "It's always DNS" , "warning" , 15 , 100 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
166+ createRule (0.1 , "We're under attack" , "warning" , 20 , 100 , true , []string {}, []string {}),
167+ createRule (0.1 , "Sh*t - Famous last words" , "critical" , 5 , 100 , true , []string {}, []string {"SrcK8S_Hostname" , "DstK8S_Hostname" }),
168+ createRule (0.3 , "FromIngress" , "info" , 10 , 100 , false , []string {"exported_namespace" }, []string {}),
169+ createRule (0.3 , "Degraded latency" , "info" , 100 , 1000 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
168170 }
169171 res := map [string ]any {
170172 "status" : "success" ,
0 commit comments