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

DO NOT MERGE: Add per pod/namespace eviction counter to assess impact #495

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/registry/core/pod/storage/eviction.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var EvictionsRetry = wait.Backoff{
}

func newEvictionStorage(store rest.StandardStorage, podDisruptionBudgetClient policyclient.PodDisruptionBudgetsGetter) *EvictionREST {
registerMetrics()
return &EvictionREST{store: store, podDisruptionBudgetClient: podDisruptionBudgetClient}
}

Expand Down Expand Up @@ -161,6 +162,9 @@ func (r *EvictionREST) Create(ctx context.Context, name string, obj runtime.Obje
if err != nil {
return err
}
if pod.DeletionTimestamp == nil {
evictionsTotal.Inc()
}
deletedPod = true
return nil
})
Expand Down Expand Up @@ -267,6 +271,9 @@ func (r *EvictionREST) Create(ctx context.Context, name string, obj runtime.Obje
return nil, err
}

evictionsTotal.Inc()
//evictionsTotal.WithLabelValues(pod.Namespace, pod.Name).Inc()

// Success!
return &metav1.Status{Status: metav1.StatusSuccess}, nil
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/registry/core/pod/storage/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package storage

import (
"sync"

"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
)

const metricsSubsystem = "kube_apiserver"

var (
// EvictionsTotal is the number of successful evictions performed.
// This metric is incremented exactly one time per pod.
evictionsTotal = metrics.NewGauge(
&metrics.GaugeOpts{
Subsystem: metricsSubsystem,
Name: "evictions_total",
Help: "The number of successful evictions performed for each pod. This is incremented exactly once when a pod is marked deleted.",
StabilityLevel: metrics.ALPHA,
},
)
)

var registerMetricsOnce sync.Once

// registerMetrics registers storage metrics.
func registerMetrics() {
registerMetricsOnce.Do(func() {
legacyregistry.MustRegister(evictionsTotal)
})
}