Skip to content

Commit 417d751

Browse files
authored
Add metrics for v2 hooks, add type to rejected/granted metrics (#88)
In a similar fashion to what we have for v1, add some metrics about ADB v2 hooks status codes, so we can track if some v2 hooks do not answer as expected. Add the type of the NodeDisruption to disruption budget grant and reject metrics to help understand if rejections are specific to a type.
1 parent 43e11a6 commit 417d751

3 files changed

Lines changed: 52 additions & 5 deletions

File tree

internal/controller/applicationdisruptionbudget_controller.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/criteo/node-disruption-controller/internal/appmgrcli/disruption"
3434
"github.com/criteo/node-disruption-controller/pkg/resolver"
3535

36+
openapiruntime "github.com/go-openapi/runtime"
3637
httptransport "github.com/go-openapi/runtime/client"
3738
"github.com/go-openapi/strfmt"
3839
"github.com/prometheus/client_golang/prometheus"
@@ -251,13 +252,20 @@ func (r *ApplicationDisruptionBudgetResolver) CallPrepareHook(ctx context.Contex
251252
return err
252253
}
253254

255+
statusCode := 200
256+
defer func() {
257+
DisruptionBudgetCheckPrepareHookStatusCodeTotal.WithLabelValues(r.ApplicationDisruptionBudget.Namespace, r.ApplicationDisruptionBudget.Name, r.ApplicationDisruptionBudget.Kind, strconv.Itoa(statusCode)).Inc()
258+
}()
254259
_, err = svc.PrepareApplication(&disruption.PrepareApplicationParams{
255260
Body: r.hookBody(nd),
256261
HTTPClient: &http.Client{Timeout: timeout},
257262
})
258263
if err == nil {
259264
return nil
260265
}
266+
if e, ok := err.(*openapiruntime.APIError); ok {
267+
statusCode = e.Code
268+
}
261269
if e, ok := err.(*disruption.PrepareApplicationStatus425); ok {
262270
return fmt.Errorf("retry later, in %v seconds", e.RetryAfter)
263271
}
@@ -270,13 +278,20 @@ func (r *ApplicationDisruptionBudgetResolver) CallReadyHook(ctx context.Context,
270278
return err
271279
}
272280

281+
statusCode := 200
282+
defer func() {
283+
DisruptionBudgetCheckReadyHookStatusCodeTotal.WithLabelValues(r.ApplicationDisruptionBudget.Namespace, r.ApplicationDisruptionBudget.Name, r.ApplicationDisruptionBudget.Kind, strconv.Itoa(statusCode)).Inc()
284+
}()
273285
_, err = svc.CheckReadiness(&disruption.CheckReadinessParams{
274286
Body: r.hookBody(nd),
275287
HTTPClient: &http.Client{Timeout: timeout},
276288
})
277289
if err == nil {
278290
return nil
279291
}
292+
if e, ok := err.(*openapiruntime.APIError); ok {
293+
statusCode = e.Code
294+
}
280295
if e, ok := err.(*disruption.CheckReadinessStatus425); ok {
281296
return fmt.Errorf("retry later, in %v seconds", e.RetryAfter)
282297
}
@@ -289,10 +304,17 @@ func (r *ApplicationDisruptionBudgetResolver) CallTerminateHook(ctx context.Cont
289304
return err
290305
}
291306

307+
statusCode := 200
308+
defer func() {
309+
DisruptionBudgetCheckTerminateHookStatusCodeTotal.WithLabelValues(r.ApplicationDisruptionBudget.Namespace, r.ApplicationDisruptionBudget.Name, r.ApplicationDisruptionBudget.Kind, strconv.Itoa(statusCode)).Inc()
310+
}()
292311
_, err = svc.TerminateDisruption(&disruption.TerminateDisruptionParams{
293312
Body: r.hookBody(nd),
294313
HTTPClient: &http.Client{Timeout: timeout},
295314
})
315+
if e, ok := err.(*openapiruntime.APIError); ok {
316+
statusCode = e.Code
317+
}
296318
return err
297319
}
298320

internal/controller/metrics.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ var (
7676
},
7777
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind", "status_code"},
7878
)
79+
// V2 Hooks
80+
DisruptionBudgetCheckPrepareHookStatusCodeTotal = promauto.With(metrics.Registry).NewCounterVec(
81+
prometheus.CounterOpts{
82+
Name: METIC_PREFIX + "disruption_budget_prepare_hook_status_code_total",
83+
Help: "Total number of request by HTTP status code",
84+
},
85+
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind", "status_code"},
86+
)
87+
DisruptionBudgetCheckReadyHookStatusCodeTotal = promauto.With(metrics.Registry).NewCounterVec(
88+
prometheus.CounterOpts{
89+
Name: METIC_PREFIX + "disruption_budget_ready_hook_status_code_total",
90+
Help: "Total number of request by HTTP status code",
91+
},
92+
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind", "status_code"},
93+
)
94+
DisruptionBudgetCheckTerminateHookStatusCodeTotal = promauto.With(metrics.Registry).NewCounterVec(
95+
prometheus.CounterOpts{
96+
Name: METIC_PREFIX + "disruption_budget_terminate_hook_status_code_total",
97+
Help: "Total number of request by HTTP status code",
98+
},
99+
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind", "status_code"},
100+
)
79101
DisruptionBudgetCheckHealthHookErrorTotal = promauto.With(metrics.Registry).NewCounterVec(
80102
prometheus.CounterOpts{
81103
Name: METIC_PREFIX + "disruption_budget_health_hook_error_total",
@@ -88,14 +110,14 @@ var (
88110
Name: METIC_PREFIX + "disruption_budget_rejected_total",
89111
Help: "Total number of rejected node disruption by the disruption budget",
90112
},
91-
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind"},
113+
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind", "type"},
92114
)
93115
DisruptionBudgetGrantedTotal = promauto.With(metrics.Registry).NewCounterVec(
94116
prometheus.CounterOpts{
95117
Name: METIC_PREFIX + "disruption_budget_granted_total",
96118
Help: "Total number of granted node disruption by the disruption budget",
97119
},
98-
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind"},
120+
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind", "type"},
99121
)
100122
DisruptionBudgetMaxDisruptions = promauto.With(metrics.Registry).NewGaugeVec(
101123
prometheus.GaugeOpts{

internal/controller/nodedisruption_controller.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func (ndr *SingleNodeDisruptionReconciler) ValidateWithBudgetConstraints(ctx con
508508
Ok: false,
509509
}
510510
statuses = append(statuses, status)
511-
DisruptionBudgetRejectedTotal.WithLabelValues(ref.Namespace, ref.Name, ref.Kind).Inc()
511+
DisruptionBudgetRejectedTotal.WithLabelValues(ref.Namespace, ref.Name, ref.Kind, ndr.NodeDisruption.Spec.Type).Inc()
512512
break
513513
}
514514
impactedBudgets = append(impactedBudgets, budget)
@@ -551,6 +551,7 @@ func (ndr *SingleNodeDisruptionReconciler) v2HookCheck(ctx context.Context, budg
551551
if !currentStatus.Ok && !currentStatus.Preparing {
552552
if err := budget.CallPrepareHook(ctx, ndr.NodeDisruption, ndr.Config.HealthHookTimeout); err != nil {
553553
logger.Error(err, "failed to call prepare hook")
554+
DisruptionBudgetRejectedTotal.WithLabelValues(ref.Namespace, ref.Name, ref.Kind, ndr.NodeDisruption.Spec.Type).Inc()
554555
return nodedisruptionv1alpha1.DisruptedBudgetStatus{
555556
Reference: ref,
556557
Reason: fmt.Sprintf("cannot prepare disruption: %s", err),
@@ -574,6 +575,8 @@ func (ndr *SingleNodeDisruptionReconciler) v2HookCheck(ctx context.Context, budg
574575
}
575576
}
576577
}
578+
579+
DisruptionBudgetGrantedTotal.WithLabelValues(ref.Namespace, ref.Name, ref.Kind, ndr.NodeDisruption.Spec.Type).Inc()
577580
return nodedisruptionv1alpha1.DisruptedBudgetStatus{
578581
Reference: ref,
579582
Ok: true,
@@ -590,10 +593,10 @@ func (ndr *SingleNodeDisruptionReconciler) legacyHookCheck(ctx context.Context,
590593
Reason: fmt.Sprintf("Unhealthy: %s", err),
591594
Ok: false,
592595
}
593-
DisruptionBudgetRejectedTotal.WithLabelValues(ref.Namespace, ref.Name, ref.Kind).Inc()
596+
DisruptionBudgetRejectedTotal.WithLabelValues(ref.Namespace, ref.Name, ref.Kind, ndr.NodeDisruption.Spec.Type).Inc()
594597
return status
595598
}
596-
DisruptionBudgetGrantedTotal.WithLabelValues(ref.Namespace, ref.Name, ref.Kind).Inc()
599+
DisruptionBudgetGrantedTotal.WithLabelValues(ref.Namespace, ref.Name, ref.Kind, ndr.NodeDisruption.Spec.Type).Inc()
597600
return nodedisruptionv1alpha1.DisruptedBudgetStatus{
598601
Reference: budget.GetNamespacedName(),
599602
Reason: "",

0 commit comments

Comments
 (0)