Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OperatorConditionsUnhealthy alert expression metric value #3181

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions hack/prom-rule-ci/prom-rules-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -774,22 +774,21 @@ tests:
# Test OperatorConditionsUnhealthy
- interval: 1m
input_series:
- series: 'kubevirt_hco_system_health_status{reason="healthy"}'
- values: "stale 1 stale stale stale"

- series: 'kubevirt_hco_system_health_status{reason="SOME_ERROR"}'
values: "stale stale 2 stale"
values: "stale stale stale 3 stale"

- series: 'kubevirt_hco_system_health_status{reason="SOME_WARNING"}'
values: "stale stale stale stale 1 stale"
values: "stale stale stale stale stale 2 stale"

alert_rule_test:
- eval_time: 1m
alertname: OperatorConditionsUnhealthy
exp_alerts: [ ]

- eval_time: 1m
alertname: OperatorConditionsUnhealthy
exp_alerts: [ ]

- eval_time: 2m
- eval_time: 3m
alertname: OperatorConditionsUnhealthy
exp_alerts:
- exp_annotations:
Expand All @@ -803,7 +802,7 @@ tests:
kubernetes_operator_component: "hyperconverged-cluster-operator"
reason: "SOME_ERROR"

- eval_time: 4m
- eval_time: 5m
alertname: OperatorConditionsUnhealthy
exp_alerts:
- exp_annotations:
Expand Down
9 changes: 4 additions & 5 deletions pkg/monitoring/metrics/operator_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const (
)

const (
SystemHealthStatusUnknown float64 = 0
SystemHealthStatusHealthy float64 = iota
SystemHealthStatusUnknown float64 = iota
SystemHealthStatusHealthy
Comment on lines +19 to +20
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

SystemHealthStatusWarning
SystemHealthStatusError
)
Expand Down Expand Up @@ -138,12 +138,11 @@ func SetHCOSystemError(reason string) {
func GetHCOMetricSystemHealthStatus(reason string) (float64, error) {
dto := &ioprometheusclient.Metric{}
err := systemHealthStatus.WithLabelValues(reason).Write(dto)
value := dto.Gauge.GetValue()

if err != nil {
return SystemHealthStatusUnknown, err
}
return value, nil

return dto.Gauge.GetValue(), nil
}

func getLabelsForObj(kind string, name string) string {
Expand Down
8 changes: 6 additions & 2 deletions pkg/monitoring/rules/alerts/health_alerts.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package alerts

import (
"fmt"

promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/kubevirt/hyperconverged-cluster-operator/pkg/monitoring/metrics"
)

func healthAlerts() []promv1.Rule {
return []promv1.Rule{
{
Alert: "OperatorConditionsUnhealthy",
Expr: intstr.FromString("kubevirt_hco_system_health_status == 2"),
Expr: intstr.FromString(fmt.Sprintf("kubevirt_hco_system_health_status == %f", metrics.SystemHealthStatusError)),
Annotations: map[string]string{
"description": "HCO and its secondary resources are in a critical state due to {{ $labels.reason }}.",
"summary": "HCO and its secondary resources are in a critical state.",
Expand All @@ -21,7 +25,7 @@ func healthAlerts() []promv1.Rule {
},
{
Alert: "OperatorConditionsUnhealthy",
Expr: intstr.FromString("kubevirt_hco_system_health_status == 1"),
Expr: intstr.FromString(fmt.Sprintf("kubevirt_hco_system_health_status == %f", metrics.SystemHealthStatusWarning)),
Annotations: map[string]string{
"description": "HCO and its secondary resources are in a warning state due to {{ $labels.reason }}.",
"summary": "HCO and its secondary resources are in a warning state.",
Expand Down
Loading