Skip to content

Commit 5b2859e

Browse files
author
f.bouzghaia
committed
Add metrics for Node disruption type [#64]
Signed-off-by: f.bouzghaia <[email protected]>
1 parent e9dea84 commit 5b2859e

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

internal/controller/metrics.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,49 @@ var (
1717
Name: METIC_PREFIX + "node_disruption_granted_total",
1818
Help: "Total number of granted node disruptions",
1919
},
20-
[]string{},
20+
[]string{"type"},
2121
)
2222
NodeDisruptionRejectedTotal = promauto.With(metrics.Registry).NewCounterVec(
2323
prometheus.CounterOpts{
2424
Name: METIC_PREFIX + "node_disruption_rejected_total",
2525
Help: "Total number of rejected node disruptions",
2626
},
27-
[]string{},
27+
[]string{"type"},
2828
)
2929
NodeDisruptionStateAsValue = promauto.With(metrics.Registry).NewGaugeVec(
3030
prometheus.GaugeOpts{
3131
Name: METIC_PREFIX + "node_disruption_state_value",
3232
Help: "State of node disruption: pending=0, rejected=-1, accepted=1",
3333
},
34-
[]string{"node_disruption_name"},
34+
[]string{"node_disruption_name", "type"},
3535
)
3636
NodeDisruptionStateAsLabel = promauto.With(metrics.Registry).NewGaugeVec(
3737
prometheus.GaugeOpts{
3838
Name: METIC_PREFIX + "node_disruption_state_label",
3939
Help: "State of node disruption: 0 not in this state; 1 is in state",
4040
},
41-
[]string{"node_disruption_name", "state"},
41+
[]string{"node_disruption_name", "state", "type"},
4242
)
4343
NodeDisruptionCreated = promauto.With(metrics.Registry).NewGaugeVec(
4444
prometheus.GaugeOpts{
4545
Name: METIC_PREFIX + "node_disruption_created",
4646
Help: "Date of create of the node disruption",
4747
},
48-
[]string{"node_disruption_name"},
48+
[]string{"node_disruption_name", "type"},
4949
)
5050
NodeDisruptionDeadline = promauto.With(metrics.Registry).NewGaugeVec(
5151
prometheus.GaugeOpts{
5252
Name: METIC_PREFIX + "node_disruption_deadline",
5353
Help: "Date of the deadline of the node disruption (0 if unset)",
5454
},
55-
[]string{"node_disruption_name"},
55+
[]string{"node_disruption_name", "type"},
5656
)
5757
NodeDisruptionImpactedNodes = promauto.With(metrics.Registry).NewGaugeVec(
5858
prometheus.GaugeOpts{
5959
Name: METIC_PREFIX + "node_disruption_impacted_node",
6060
Help: "high cardinality: create a metric for each node impacted by a given node disruption",
6161
},
62-
[]string{"node_disruption_name", "node_name"},
62+
[]string{"node_disruption_name", "node_name", "type"},
6363
)
6464
NodeDisruptionType = promauto.With(metrics.Registry).NewGaugeVec(
6565
prometheus.GaugeOpts{

internal/controller/nodedisruption_controller.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,33 +127,32 @@ func UpdateNodeDisruptionMetrics(nd *nodedisruptionv1alpha1.NodeDisruption) {
127127
nd_state := 0
128128
if nd.Status.State == nodedisruptionv1alpha1.Pending {
129129
nd_state = 0
130-
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Pending)).Set(1)
131-
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Granted)).Set(0)
132-
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Rejected)).Set(0)
130+
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Pending), nd.Spec.Type).Set(1)
131+
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Granted), nd.Spec.Type).Set(0)
132+
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Rejected), nd.Spec.Type).Set(0)
133133
} else if nd.Status.State == nodedisruptionv1alpha1.Rejected {
134134
nd_state = -1
135-
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Pending)).Set(0)
136-
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Rejected)).Set(1)
137-
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Granted)).Set(0)
135+
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Pending), nd.Spec.Type).Set(0)
136+
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Rejected), nd.Spec.Type).Set(1)
137+
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Granted), nd.Spec.Type).Set(0)
138138
} else if nd.Status.State == nodedisruptionv1alpha1.Granted {
139139
nd_state = 1
140-
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Pending)).Set(0)
141-
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Rejected)).Set(0)
142-
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Granted)).Set(1)
140+
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Pending), nd.Spec.Type).Set(0)
141+
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Rejected), nd.Spec.Type).Set(0)
142+
NodeDisruptionStateAsLabel.WithLabelValues(nd.Name, string(nodedisruptionv1alpha1.Granted), nd.Spec.Type).Set(1)
143143
}
144-
NodeDisruptionStateAsValue.WithLabelValues(nd.Name).Set(float64(nd_state))
145-
NodeDisruptionCreated.WithLabelValues(nd.Name).Set(float64(nd.CreationTimestamp.Unix()))
144+
NodeDisruptionStateAsValue.WithLabelValues(nd.Name, nd.Spec.Type).Set(float64(nd_state))
145+
NodeDisruptionCreated.WithLabelValues(nd.Name, nd.Spec.Type).Set(float64(nd.CreationTimestamp.Unix()))
146146
// Deadline might not be set so it will be 0 but timestamp in Go are not Unix epoch
147147
// so converting a 0 timestamp will not result in epoch 0. We override this to have nice values
148148
deadline := nd.Spec.Retry.Deadline.Unix()
149149
if nd.Spec.Retry.Deadline.IsZero() {
150150
deadline = 0
151151
}
152-
NodeDisruptionDeadline.WithLabelValues(nd.Name).Set(float64(deadline))
153-
NodeDisruptionType.WithLabelValues(nd.Name, nd.Spec.Type).Set(1)
152+
NodeDisruptionDeadline.WithLabelValues(nd.Name, nd.Spec.Type).Set(float64(deadline))
154153

155154
for _, node_name := range nd.Status.DisruptedNodes {
156-
NodeDisruptionImpactedNodes.WithLabelValues(nd.Name, node_name).Set(1)
155+
NodeDisruptionImpactedNodes.WithLabelValues(nd.Name, node_name, nd.Spec.Type).Set(1)
157156
}
158157
}
159158

@@ -200,9 +199,9 @@ func (ndr *SingleNodeDisruptionReconciler) TryTransitionState(ctx context.Contex
200199
return err
201200
}
202201
if ndr.NodeDisruption.Status.State == nodedisruptionv1alpha1.Granted {
203-
NodeDisruptionGrantedTotal.WithLabelValues().Inc()
202+
NodeDisruptionGrantedTotal.WithLabelValues(ndr.NodeDisruption.Spec.Type).Inc()
204203
} else if ndr.NodeDisruption.Status.State == nodedisruptionv1alpha1.Rejected {
205-
NodeDisruptionRejectedTotal.WithLabelValues().Inc()
204+
NodeDisruptionRejectedTotal.WithLabelValues(ndr.NodeDisruption.Spec.Type).Inc()
206205
}
207206
}
208207
// If the disruption is not Pending nor unknown, the state is final

0 commit comments

Comments
 (0)