-
Notifications
You must be signed in to change notification settings - Fork 178
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
add a field to indicate spotInstances in node.conditions metric #1928
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,13 @@ package cluster | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"strconv" | ||
|
||
"github.com/sirupsen/logrus" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
azureproviderv1beta1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1beta1" | ||
) | ||
|
||
var nodeConditionsExpected = map[corev1.NodeConditionType]corev1.ConditionStatus{ | ||
|
@@ -23,27 +27,34 @@ func (mon *Monitor) emitNodeConditions(ctx context.Context) error { | |
return err | ||
} | ||
|
||
spotInstances := mon.getSpotInstances(ctx) | ||
|
||
mon.emitGauge("node.count", int64(len(ns.Items)), nil) | ||
|
||
for _, n := range ns.Items { | ||
|
||
for _, c := range n.Status.Conditions { | ||
if c.Status == nodeConditionsExpected[c.Type] { | ||
continue | ||
} | ||
|
||
_, isSpotInstance := spotInstances[n.Name] | ||
|
||
mon.emitGauge("node.conditions", 1, map[string]string{ | ||
"nodeName": n.Name, | ||
"status": string(c.Status), | ||
"type": string(c.Type), | ||
"nodeName": n.Name, | ||
"status": string(c.Status), | ||
"type": string(c.Type), | ||
"spotInstance": strconv.FormatBool(isSpotInstance), | ||
}) | ||
|
||
if mon.hourlyRun { | ||
mon.log.WithFields(logrus.Fields{ | ||
"metric": "node.conditions", | ||
"name": n.Name, | ||
"status": c.Status, | ||
"type": c.Type, | ||
"message": c.Message, | ||
"metric": "node.conditions", | ||
"name": n.Name, | ||
"status": c.Status, | ||
"type": c.Type, | ||
"message": c.Message, | ||
"spotInstance": isSpotInstance, | ||
}).Print() | ||
} | ||
} | ||
|
@@ -57,3 +68,30 @@ func (mon *Monitor) emitNodeConditions(ctx context.Context) error { | |
|
||
return nil | ||
} | ||
|
||
// getSpotInstances returns a map where the keys are the machine name and only exist if the machine is a spot instance | ||
func (mon *Monitor) getSpotInstances(ctx context.Context) map[string]struct{} { | ||
spotInstances := make(map[string]struct{}) | ||
machines, err := mon.maocli.MachineV1beta1().Machines("openshift-machine-api").List(ctx, metav1.ListOptions{}) | ||
|
||
if err != nil { | ||
// when this call fails we may report spot vms as non spot until the next successful call | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to error here and exit from I'm on the fence here, but I think having incorrect data is worse than missing data. What do you and others think? Same question appleis to the code below (errors from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm on the fence as well and am open to suggestions for this. I agree that incorrect data is worse than missing data, but do we have an alert based on missing data? the worst case with incorrect data here is that we might fire a nodeready alert on a spot vm where as the worst case of missing data is we will not fire any alert when we would want one for nodeready. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After giving this more thought, I believe we should continue to not bail of out sending node.conditions when we fail to call the machine api operator. When we fail to call the mao there could be something wrong with some nodes, if we then don't report node.conditions then we may never know via this metric. By continuing to report node.conditions with the possibility that |
||
mon.log.Error(err) | ||
return spotInstances | ||
} | ||
|
||
for _, machine := range machines.Items { | ||
var spec azureproviderv1beta1.AzureMachineProviderSpec | ||
err = json.Unmarshal(machine.Spec.ProviderSpec.Value.Raw, &spec) | ||
if err != nil { | ||
mon.log.Error(err) | ||
continue | ||
} | ||
|
||
if spec.SpotVMOptions != nil { | ||
spotInstances[machine.Name] = struct{}{} | ||
} | ||
} | ||
|
||
return spotInstances | ||
} |
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.
this makes one api call to MAO to list machines to determine spot instance type for all VMs in a cluster