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
Bug 1904503: Add prometheus alerts for vsphere #126
Merged
openshift-merge-robot
merged 2 commits into
openshift:master
from
gnufied:add-prometheus-alert-vsphere
Jan 18, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,25 @@ | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: PrometheusRule | ||
metadata: | ||
name: vsphere-problem-detector | ||
namespace: openshift-cluster-storage-operator | ||
labels: | ||
role: alert-rules | ||
spec: | ||
groups: | ||
- name: vsphere-problem-detector.rules | ||
rules: | ||
- alert: VSphereOpenshiftNodeHealthFail | ||
expr: vsphere_node_check_errors == 1 | ||
for: 10m | ||
labels: | ||
severity: warning | ||
annotations: | ||
message: "VSphere health check {{ $labels.check }} is failing on {{ $labels.node }}." | ||
- alert: VSphereOpenshiftClusterHealthFail | ||
expr: vsphere_cluster_check_errors == 1 | ||
for: 10m | ||
labels: | ||
severity: warning | ||
annotations: | ||
message: "VSphere cluster health checks are failing with {{ $labels.check }}" |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,91 @@ | ||
package vsphereproblemdetector | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/openshift/cluster-storage-operator/pkg/csoclients" | ||
"github.com/openshift/library-go/pkg/operator/events" | ||
promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func TestSyncPrometheusRule(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inititialRules []*promv1.PrometheusRule | ||
// we merely use this field as a marker in test to check if rule was applied properly | ||
expectedAlertCountInRule int | ||
modified bool | ||
}{ | ||
{ | ||
name: "for new rule creation", | ||
inititialRules: []*promv1.PrometheusRule{}, | ||
expectedAlertCountInRule: 2, | ||
modified: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
initialObjects := &csoclients.FakeTestObjects{} | ||
for _, r := range test.inititialRules { | ||
initialObjects.MonitoringObjects = append(initialObjects.MonitoringObjects, runtime.Object(r)) | ||
} | ||
|
||
client := csoclients.NewFakeClients(initialObjects) | ||
eventRecorder := events.NewInMemoryRecorder("vsphere-client") | ||
c := &monitoringController{ | ||
operatorClient: client.OperatorClient, | ||
kubeClient: client.KubeClient, | ||
dynamicClient: client.DynamicClient, | ||
eventRecorder: eventRecorder, | ||
monitoringClient: client.MonitoringClient, | ||
} | ||
ctx := context.TODO() | ||
rule, modified, err := c.syncPrometheusRule(ctx, getPrometheusRuleRaw()) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
if modified != test.modified { | ||
t.Errorf("expected rule modification to be %v got %v", test.modified, modified) | ||
} | ||
actualRules := rule.Spec.Groups[0].Rules | ||
if len(actualRules) != test.expectedAlertCountInRule { | ||
t.Errorf("expected alert count in rule to be %d got %d", test.expectedAlertCountInRule, len(actualRules)) | ||
} | ||
}) | ||
|
||
} | ||
} | ||
|
||
func getPrometheusRuleRaw() []byte { | ||
return []byte(` | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: PrometheusRule | ||
metadata: | ||
name: vsphere-problem-detector | ||
namespace: openshift-cluster-storage-operator | ||
labels: | ||
role: alert-rules | ||
spec: | ||
groups: | ||
- name: vsphere-problem-detector.rules | ||
rules: | ||
- alert: VSphereOpenshiftNodeHealthFail | ||
expr: vsphere_node_check_errors == 1 | ||
for: 10m | ||
labels: | ||
severity: warning | ||
annotations: | ||
message: "Vsphere node health checks are failing on {{ $labels.node }} with {{ $labels.check }}" | ||
- alert: VSphereOpenshiftClusterHealthFail | ||
expr: vsphere_cluster_check_errors == 1 | ||
for: 10m | ||
labels: | ||
severity: critical | ||
annotations: | ||
message: "VSpehre cluster health checks are failing with {{ $labels.check }}" | ||
`) | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What type is this metric? A counter or gauge? Quick search could not find it in the operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's gauge now, openshift/vsphere-problem-detector#24
(used to be counter yesterday, hard to alert on it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small comment to improve the alerting rule: in the current version, a failed scrape by Prometheus would resolve the alert if it was firing previously.
To protect against it, you can use
min_over_time()
like thissee https://www.robustperception.io/alerting-on-gauges-in-prometheus-2-0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice thanks!
Agreed with Simons suggestion, otherwise looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why
min_over_time
- shouldn't this bemax_over_time
? I would think if a scrape failed and a value is missing on time t1 then it would replace with some kind of sentinel value (0
? - I don't know prometheus very well and how it fills the holes in the data) .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the target is down (up == 0) then Prometheus will mark the
vsphere_node_check_errors
metric as stale (meaning it doesn't exist anymore). On the next evaluation of the alerting rule, the result from the rule's expression would be "no data" so Prometheus will consider that the alert is resolved.