Skip to content

Commit c2b32d4

Browse files
Add clientgo metrics to node cleanup controlelr
1 parent 40504d1 commit c2b32d4

File tree

17 files changed

+1662
-15
lines changed

17 files changed

+1662
-15
lines changed

cmd/node-cleanup/main.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import (
3030
"k8s.io/client-go/rest"
3131
"k8s.io/client-go/tools/clientcmd"
3232

33+
"k8s.io/component-base/metrics/legacyregistry"
34+
_ "k8s.io/component-base/metrics/prometheus/clientgo" // for client metric registration
35+
3336
"k8s.io/klog/v2"
3437
metrics "sigs.k8s.io/sig-storage-local-static-provisioner/pkg/metrics/node-cleanup"
3538
"sigs.k8s.io/sig-storage-local-static-provisioner/pkg/node-cleanup/controller"
@@ -86,13 +89,19 @@ func main() {
8689

8790
// Prepare http endpoint for metrics
8891
if *listenAddress != "" {
89-
prometheus.MustRegister([]prometheus.Collector{
90-
metrics.APIServerRequestsTotal,
92+
reg := prometheus.NewRegistry()
93+
reg.MustRegister([]prometheus.Collector{
94+
metrics.PersistentVolumeDeleteTotal,
9195
metrics.PersistentVolumeDeleteFailedTotal,
9296
metrics.PersistentVolumeClaimDeleteTotal,
9397
metrics.PersistentVolumeClaimDeleteFailedTotal,
9498
}...)
95-
http.Handle(*metricsPath, promhttp.Handler())
99+
gatherers := prometheus.Gatherers{
100+
reg,
101+
legacyregistry.DefaultGatherer,
102+
}
103+
104+
http.Handle(*metricsPath, promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{}))
96105

97106
go func() {
98107
klog.Infof("Starting metrics server at %s\n", *listenAddress)

pkg/metrics/node-cleanup/metrics.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,25 @@ const (
2626
)
2727

2828
var (
29-
// APIServerRequestsTotal is used to collect accumulated count of apiserver requests.
30-
APIServerRequestsTotal = prometheus.NewCounterVec(
29+
// PersistentVolumeDeleteTotal is used to collect accumulated count of persistent volume delete attempts.
30+
// This metric will report as higher than the true amount of persistent volumes deleted if
31+
// the node-cleanup deleter has a short sync period.
32+
PersistentVolumeDeleteTotal = prometheus.NewCounterVec(
3133
prometheus.CounterOpts{
3234
Subsystem: LocalVolumeNodeCleanupSubsystem,
33-
Name: "apiserver_requests_total",
34-
Help: "Total number of apiserver requests. Broken down by method.",
35+
Name: "persistentvolume_delete_total",
36+
Help: "Total number of successful persistent volume delete *attempts*. Broken down by persistent volume phase.",
3537
},
36-
[]string{"method"},
38+
[]string{"phase"},
3739
)
3840
// PersistentVolumeDeleteFailedTotal is used to collect accumulated count of persistent volume delete failed attempts.
3941
PersistentVolumeDeleteFailedTotal = prometheus.NewCounterVec(
4042
prometheus.CounterOpts{
4143
Subsystem: LocalVolumeNodeCleanupSubsystem,
4244
Name: "persistentvolume_delete_failed_total",
43-
Help: "Total number of persistent volume delete failed attempts. Broken down by persistent volume status and reclaim policy.",
45+
Help: "Total number of persistent volume delete failed attempts. Broken down by persistent volume phase.",
4446
},
45-
[]string{"status", "reclaim"},
47+
[]string{"phase"},
4648
)
4749
// PersistentVolumeClaimDeleteTotal is used to collect accumulated count of persistent volume claims deleted.
4850
PersistentVolumeClaimDeleteTotal = prometheus.NewCounter(

pkg/node-cleanup/controller/controller.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"k8s.io/klog/v2"
3939

4040
"sigs.k8s.io/sig-storage-local-static-provisioner/pkg/common"
41-
"sigs.k8s.io/sig-storage-local-static-provisioner/pkg/metrics"
4241
cleanupmetrics "sigs.k8s.io/sig-storage-local-static-provisioner/pkg/metrics/node-cleanup"
4342
)
4443

@@ -300,7 +299,6 @@ func (c *CleanupController) deletePVC(ctx context.Context, pvc *v1.PersistentVol
300299
options := metav1.DeleteOptions{
301300
Preconditions: &metav1.Preconditions{UID: &pvc.UID},
302301
}
303-
cleanupmetrics.APIServerRequestsTotal.WithLabelValues(metrics.APIServerRequestDelete).Inc()
304302
err := c.client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(ctx, pvc.Name, options)
305303
if err != nil && errors.IsNotFound(err) {
306304
// The PVC could already be deleted by some other process

pkg/node-cleanup/deleter/deleter.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"k8s.io/klog/v2"
3131

3232
"sigs.k8s.io/sig-storage-local-static-provisioner/pkg/common"
33-
"sigs.k8s.io/sig-storage-local-static-provisioner/pkg/metrics"
3433
cleanupmetrics "sigs.k8s.io/sig-storage-local-static-provisioner/pkg/metrics/node-cleanup"
3534
)
3635

@@ -102,10 +101,13 @@ func (d *Deleter) DeletePVs(ctx context.Context) {
102101
if isReleasedWithDeleteReclaim || isAvailable {
103102
klog.Infof("Attempting to delete PV that has NodeAffinity to deleted Node, pv: %s", pv.Name)
104103
if err = d.deletePV(ctx, pv.Name); err != nil {
105-
cleanupmetrics.PersistentVolumeDeleteFailedTotal.WithLabelValues(string(phase), string(reclaimPolicy)).Inc()
104+
cleanupmetrics.PersistentVolumeDeleteFailedTotal.WithLabelValues(string(phase)).Inc()
106105
klog.Errorf("Error deleting PV: %s", pv.Name)
107106
continue
108107
}
108+
// TODO: Cache successful deletion to avoid multiple delete calls
109+
// when there is a short sync period
110+
cleanupmetrics.PersistentVolumeDeleteTotal.WithLabelValues(string(phase)).Inc()
109111
}
110112
}
111113
}
@@ -133,7 +135,6 @@ func (d *Deleter) referencesNonExistentNode(localPV *v1.PersistentVolume) (bool,
133135
}
134136

135137
func (d *Deleter) deletePV(ctx context.Context, pvName string) error {
136-
cleanupmetrics.APIServerRequestsTotal.WithLabelValues(metrics.APIServerRequestDelete).Inc()
137138
err := d.client.CoreV1().PersistentVolumes().Delete(ctx, pvName, metav1.DeleteOptions{})
138139
if err != nil && errors.IsNotFound(err) {
139140
klog.Warningf("PV %q no longer exists", pvName)

vendor/k8s.io/client-go/tools/leaderelection/OWNERS

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/k8s.io/client-go/tools/leaderelection/healthzadaptor.go

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)