Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
handler: register metrics about the tainting logic (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienBalestra authored and Joseph-Irving committed Dec 16, 2019
1 parent c4e04be commit 90529bc
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion pkg/nidhogg/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,49 @@ import (
"reflect"
"strings"

"github.com/prometheus/client_golang/prometheus"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)

const taintKey = "nidhogg.uswitch.com"
const (
taintKey = "nidhogg.uswitch.com"
taintOperationAdded = "added"
taintOperationRemoved = "removed"
)

var (
taintOperations = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "taint_operations",
Help: "Total number of added/removed taints operations",
},
[]string{
"operation",
"taint",
},
)
taintOperationErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "taint_operation_errors",
Help: "Total number of errors during taint operations",
},
[]string{
"operation",
},
)
)

func init() {
metrics.Registry.MustRegister(
taintOperations,
taintOperationErrors,
)
}

// Handler performs the main business logic of the Wave controller
type Handler struct {
Expand Down Expand Up @@ -59,6 +92,7 @@ func (h *Handler) HandleNode(instance *corev1.Node) (reconcile.Result, error) {

copy, taintChanges, err := h.caclulateTaints(instance)
if err != nil {
taintOperationErrors.WithLabelValues("calculateTaints").Inc()
return reconcile.Result{}, fmt.Errorf("error caluclating taints for node: %v", err)
}

Expand All @@ -67,8 +101,15 @@ func (h *Handler) HandleNode(instance *corev1.Node) (reconcile.Result, error) {
log.Info("Updating Node taints", "instance", instance.Name, "taints added", taintChanges.taintsAdded, "taints removed", taintChanges.taintsRemoved)
err := h.Update(context.TODO(), instance)
if err != nil {
taintOperationErrors.WithLabelValues("nodeUpdate").Inc()
return reconcile.Result{}, err
}
for _, taintAdded := range taintChanges.taintsAdded {
taintOperations.WithLabelValues(taintOperationAdded, taintAdded).Inc()
}
for _, taintRemoved := range taintChanges.taintsRemoved {
taintOperations.WithLabelValues(taintOperationRemoved, taintRemoved).Inc()
}

// this is a hack to make the event work on a non-namespaced object
copy.UID = types.UID(copy.Name)
Expand Down

0 comments on commit 90529bc

Please sign in to comment.