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

Add metrics for provisioning nodes #1572

Merged
merged 1 commit into from
Feb 22, 2023
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
24 changes: 20 additions & 4 deletions pkg/controller/machine/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,19 @@ type KubeconfigProvider interface {
// MetricsCollection is a struct of all metrics used in
// this controller.
type MetricsCollection struct {
Workers prometheus.Gauge
Errors prometheus.Counter
Workers prometheus.Gauge
Errors prometheus.Counter
Provisioning prometheus.Histogram
Deprovisioning prometheus.Histogram
}

func (mc *MetricsCollection) MustRegister(registerer prometheus.Registerer) {
registerer.MustRegister(mc.Errors, mc.Workers)
registerer.MustRegister(
mc.Errors,
mc.Workers,
mc.Provisioning,
mc.Deprovisioning,
)
}

func Add(
Expand Down Expand Up @@ -458,6 +465,9 @@ func (r *Reconciler) ensureMachineHasNodeReadyCondition(machine *clusterv1alpha1
return nil
}
}

r.metrics.Provisioning.Observe(time.Until(machine.CreationTimestamp.Time).Abs().Seconds())

return r.updateMachine(machine, func(m *clusterv1alpha1.Machine) {
m.Status.Conditions = append(m.Status.Conditions, corev1.NodeCondition{Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
Expand Down Expand Up @@ -595,7 +605,13 @@ func (r *Reconciler) deleteMachine(ctx context.Context, prov cloudprovidertypes.
return nil, err
}

return nil, r.deleteNodeForMachine(ctx, nodes, machine)
if err := r.deleteNodeForMachine(ctx, nodes, machine); err != nil {
return nil, err
}

r.metrics.Deprovisioning.Observe(time.Until(machine.DeletionTimestamp.Time).Abs().Seconds())

return nil, nil
}

func (r *Reconciler) retrieveNodesRelatedToMachine(ctx context.Context, machine *clusterv1alpha1.Machine) ([]*corev1.Node, error) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/machine/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ func NewMachineControllerMetrics() *MetricsCollection {
Name: metricsPrefix + "errors_total",
Help: "The total number or unexpected errors the controller encountered",
}),
Provisioning: prometheus.NewHistogram(prometheus.HistogramOpts{
Name: metricsPrefix + "provisioning_time_seconds",
Help: "Histogram of times spent from creating a Machine to ready state in the cluster",
Buckets: prometheus.ExponentialBuckets(32, 1.5, 10),
}),
Deprovisioning: prometheus.NewHistogram(prometheus.HistogramOpts{
Name: metricsPrefix + "deprovisioning_time_seconds",
Help: "Histogram of times spent from deleting a Machine to be removed from cluster and cloud provider",
Buckets: prometheus.ExponentialBuckets(32, 1.5, 10),
}),
}

// Set default values, so that these metrics always show up
Expand Down