Skip to content

Commit ca6af5e

Browse files
authored
Merge pull request #441 from kubernetes-csi/revert-440-release-3.0_cherrypick_941821bf99ec8d30e7183d67decce4b5dd9bfee6
Revert "Cherry-pick:Add snapshot controller metrics"
2 parents b083035 + 9e44799 commit ca6af5e

File tree

7 files changed

+284
-659
lines changed

7 files changed

+284
-659
lines changed

cmd/snapshot-controller/main.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
"os"
2424
"os/signal"
25-
"sync"
2625
"time"
2726

2827
"k8s.io/client-go/kubernetes"
@@ -33,7 +32,6 @@ import (
3332

3433
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
3534
controller "github.com/kubernetes-csi/external-snapshotter/v3/pkg/common-controller"
36-
"github.com/kubernetes-csi/external-snapshotter/v3/pkg/metrics"
3735

3836
clientset "github.com/kubernetes-csi/external-snapshotter/client/v3/clientset/versioned"
3937
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/client/v3/clientset/versioned/scheme"
@@ -50,9 +48,6 @@ var (
5048

5149
leaderElection = flag.Bool("leader-election", false, "Enables leader election.")
5250
leaderElectionNamespace = flag.String("leader-election-namespace", "", "The namespace where the leader election resource exists. Defaults to the pod namespace if not set.")
53-
54-
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the HTTP server for diagnostics, including metrics, will listen (example: :8080). The default is empty string, which means the server is disabled.")
55-
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
5651
)
5752

5853
var (
@@ -92,28 +87,6 @@ func main() {
9287
factory := informers.NewSharedInformerFactory(snapClient, *resyncPeriod)
9388
coreFactory := coreinformers.NewSharedInformerFactory(kubeClient, *resyncPeriod)
9489

95-
// Create and register metrics manager
96-
metricsManager := metrics.NewMetricsManager()
97-
wg := &sync.WaitGroup{}
98-
wg.Add(1)
99-
if *httpEndpoint != "" {
100-
srv, err := metricsManager.StartMetricsEndpoint(*metricsPath, *httpEndpoint, promklog{}, wg)
101-
if err != nil {
102-
klog.Errorf("Failed to start metrics server: %s", err.Error())
103-
os.Exit(1)
104-
}
105-
defer func() {
106-
err := srv.Shutdown(context.Background())
107-
if err != nil {
108-
klog.Errorf("Failed to shutdown metrics server: %s", err.Error())
109-
}
110-
111-
klog.Infof("Metrics server successfully shutdown")
112-
wg.Done()
113-
}()
114-
klog.Infof("Metrics server successfully started on %s, %s", *httpEndpoint, *metricsPath)
115-
}
116-
11790
// Add Snapshot types to the default Kubernetes so events can be logged for them
11891
snapshotscheme.AddToScheme(scheme.Scheme)
11992

@@ -126,7 +99,6 @@ func main() {
12699
factory.Snapshot().V1beta1().VolumeSnapshotContents(),
127100
factory.Snapshot().V1beta1().VolumeSnapshotClasses(),
128101
coreFactory.Core().V1().PersistentVolumeClaims(),
129-
metricsManager,
130102
*resyncPeriod,
131103
)
132104

@@ -170,9 +142,3 @@ func buildConfig(kubeconfig string) (*rest.Config, error) {
170142
}
171143
return rest.InClusterConfig()
172144
}
173-
174-
type promklog struct{}
175-
176-
func (pl promklog) Println(v ...interface{}) {
177-
klog.Error(v...)
178-
}

pkg/common-controller/framework_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/client/v3/clientset/versioned/scheme"
3535
informers "github.com/kubernetes-csi/external-snapshotter/client/v3/informers/externalversions"
3636
storagelisters "github.com/kubernetes-csi/external-snapshotter/client/v3/listers/volumesnapshot/v1beta1"
37-
"github.com/kubernetes-csi/external-snapshotter/v3/pkg/metrics"
3837
"github.com/kubernetes-csi/external-snapshotter/v3/pkg/utils"
3938
v1 "k8s.io/api/core/v1"
4039
storagev1 "k8s.io/api/storage/v1"
@@ -751,10 +750,6 @@ func newTestController(kubeClient kubernetes.Interface, clientset clientset.Inte
751750
}
752751

753752
coreFactory := coreinformers.NewSharedInformerFactory(kubeClient, utils.NoResyncPeriodFunc())
754-
metricsManager := metrics.NewMetricsManager()
755-
wg := &sync.WaitGroup{}
756-
wg.Add(1)
757-
metricsManager.StartMetricsEndpoint("/metrics", "localhost:0", nil, wg)
758753

759754
ctrl := NewCSISnapshotCommonController(
760755
clientset,
@@ -763,7 +758,6 @@ func newTestController(kubeClient kubernetes.Interface, clientset clientset.Inte
763758
informerFactory.Snapshot().V1beta1().VolumeSnapshotContents(),
764759
informerFactory.Snapshot().V1beta1().VolumeSnapshotClasses(),
765760
coreFactory.Core().V1().PersistentVolumeClaims(),
766-
metricsManager,
767761
60*time.Second,
768762
)
769763

pkg/common-controller/snapshot_controller.go

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
klog "k8s.io/klog/v2"
3434

3535
crdv1 "github.com/kubernetes-csi/external-snapshotter/client/v3/apis/volumesnapshot/v1beta1"
36-
"github.com/kubernetes-csi/external-snapshotter/v3/pkg/metrics"
3736
"github.com/kubernetes-csi/external-snapshotter/v3/pkg/utils"
3837
)
3938

@@ -237,20 +236,6 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
237236
// 2. Call checkandRemoveSnapshotFinalizersAndCheckandDeleteContent() with information obtained from step 1. This function name is very long but the name suggests what it does. It determines whether to remove finalizers on snapshot and whether to delete content.
238237
func (ctrl *csiSnapshotCommonController) processSnapshotWithDeletionTimestamp(snapshot *crdv1.VolumeSnapshot) error {
239238
klog.V(5).Infof("processSnapshotWithDeletionTimestamp VolumeSnapshot[%s]: %s", utils.SnapshotKey(snapshot), utils.GetSnapshotStatusForLogging(snapshot))
240-
driverName, err := ctrl.getSnapshotDriverName(snapshot)
241-
if err != nil {
242-
klog.Errorf("failed to getSnapshotDriverName while recording metrics for snapshot %q: %v", utils.SnapshotKey(snapshot), err)
243-
}
244-
245-
snapshotProvisionType := metrics.DynamicSnapshotType
246-
if snapshot.Spec.Source.VolumeSnapshotContentName != nil {
247-
snapshotProvisionType = metrics.PreProvisionedSnapshotType
248-
}
249-
250-
// Processing delete, start operation metric
251-
deleteOperationKey := metrics.NewOperationKey(metrics.DeleteSnapshotOperationName, snapshot.UID)
252-
deleteOperationValue := metrics.NewOperationValue(driverName, snapshotProvisionType)
253-
ctrl.metricsManager.OperationStart(deleteOperationKey, deleteOperationValue)
254239

255240
var contentName string
256241
if snapshot.Status != nil && snapshot.Status.BoundVolumeSnapshotContentName != nil {
@@ -285,7 +270,6 @@ func (ctrl *csiSnapshotCommonController) processSnapshotWithDeletionTimestamp(sn
285270
}
286271

287272
klog.V(5).Infof("processSnapshotWithDeletionTimestamp[%s]: delete snapshot content and remove finalizer from snapshot if needed", utils.SnapshotKey(snapshot))
288-
289273
return ctrl.checkandRemoveSnapshotFinalizersAndCheckandDeleteContent(snapshot, content, deleteContent)
290274
}
291275

@@ -405,7 +389,6 @@ func (ctrl *csiSnapshotCommonController) syncReadySnapshot(snapshot *crdv1.Volum
405389
// snapshot is bound but content is not pointing to the snapshot
406390
return ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotMisbound", "VolumeSnapshotContent is not bound to the VolumeSnapshot correctly")
407391
}
408-
409392
// everything is verified, return
410393
return nil
411394
}
@@ -414,45 +397,20 @@ func (ctrl *csiSnapshotCommonController) syncReadySnapshot(snapshot *crdv1.Volum
414397
func (ctrl *csiSnapshotCommonController) syncUnreadySnapshot(snapshot *crdv1.VolumeSnapshot) error {
415398
uniqueSnapshotName := utils.SnapshotKey(snapshot)
416399
klog.V(5).Infof("syncUnreadySnapshot %s", uniqueSnapshotName)
417-
driverName, err := ctrl.getSnapshotDriverName(snapshot)
418-
if err != nil {
419-
klog.Errorf("failed to getSnapshotDriverName while recording metrics for snapshot %q: %s", utils.SnapshotKey(snapshot), err)
420-
}
421-
422-
snapshotProvisionType := metrics.DynamicSnapshotType
423-
if snapshot.Spec.Source.VolumeSnapshotContentName != nil {
424-
snapshotProvisionType = metrics.PreProvisionedSnapshotType
425-
}
426-
427-
// Start metrics operations
428-
if !utils.IsSnapshotCreated(snapshot) {
429-
// Only start CreateSnapshot operation if the snapshot has not been cut
430-
ctrl.metricsManager.OperationStart(
431-
metrics.NewOperationKey(metrics.CreateSnapshotOperationName, snapshot.UID),
432-
metrics.NewOperationValue(driverName, snapshotProvisionType),
433-
)
434-
}
435-
ctrl.metricsManager.OperationStart(
436-
metrics.NewOperationKey(metrics.CreateSnapshotAndReadyOperationName, snapshot.UID),
437-
metrics.NewOperationValue(driverName, snapshotProvisionType),
438-
)
439400

440401
// Pre-provisioned snapshot
441402
if snapshot.Spec.Source.VolumeSnapshotContentName != nil {
442403
content, err := ctrl.getPreprovisionedContentFromStore(snapshot)
443404
if err != nil {
444405
return err
445406
}
446-
447407
// if no content found yet, update status and return
448408
if content == nil {
449409
// can not find the desired VolumeSnapshotContent from cache store
450410
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotContentMissing", "VolumeSnapshotContent is missing")
451411
klog.V(4).Infof("syncUnreadySnapshot[%s]: snapshot content %q requested but not found, will try again", utils.SnapshotKey(snapshot), *snapshot.Spec.Source.VolumeSnapshotContentName)
452-
453412
return fmt.Errorf("snapshot %s requests an non-existing content %s", utils.SnapshotKey(snapshot), *snapshot.Spec.Source.VolumeSnapshotContentName)
454413
}
455-
456414
// Set VolumeSnapshotRef UID
457415
newContent, err := ctrl.checkandBindSnapshotContent(snapshot, content)
458416
if err != nil {
@@ -469,10 +427,8 @@ func (ctrl *csiSnapshotCommonController) syncUnreadySnapshot(snapshot *crdv1.Vol
469427
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotStatusUpdateFailed", fmt.Sprintf("Snapshot status update failed, %v", err))
470428
return err
471429
}
472-
473430
return nil
474431
}
475-
476432
// snapshot.Spec.Source.VolumeSnapshotContentName == nil - dynamically creating snapshot
477433
klog.V(5).Infof("getDynamicallyProvisionedContentFromStore for snapshot %s", uniqueSnapshotName)
478434
contentObj, err := ctrl.getDynamicallyProvisionedContentFromStore(snapshot)
@@ -1139,30 +1095,10 @@ func (ctrl *csiSnapshotCommonController) updateSnapshotStatus(snapshot *crdv1.Vo
11391095
if updated {
11401096
snapshotClone := snapshotObj.DeepCopy()
11411097
snapshotClone.Status = newStatus
1142-
1143-
// We need to record metrics before updating the status due to a bug causing cache entries after a failed UpdateStatus call.
1144-
// Must meet the following criteria to emit a successful CreateSnapshot status
1145-
// 1. Previous status was nil OR Previous status had a nil CreationTime
1146-
// 2. New status must be non-nil with a non-nil CreationTime
1147-
driverName := content.Spec.Driver
1148-
createOperationKey := metrics.NewOperationKey(metrics.CreateSnapshotOperationName, snapshot.UID)
1149-
if !utils.IsSnapshotCreated(snapshotObj) && utils.IsSnapshotCreated(snapshotClone) {
1150-
ctrl.metricsManager.RecordMetrics(createOperationKey, metrics.NewSnapshotOperationStatus(metrics.SnapshotStatusTypeSuccess), driverName)
1151-
}
1152-
1153-
// Must meet the following criteria to emit a successful CreateSnapshotAndReady status
1154-
// 1. Previous status was nil OR Previous status had a nil ReadyToUse OR Previous status had a false ReadyToUse
1155-
// 2. New status must be non-nil with a ReadyToUse as true
1156-
if !utils.IsSnapshotReady(snapshotObj) && utils.IsSnapshotReady(snapshotClone) {
1157-
createAndReadyOperation := metrics.NewOperationKey(metrics.CreateSnapshotAndReadyOperationName, snapshot.UID)
1158-
ctrl.metricsManager.RecordMetrics(createAndReadyOperation, metrics.NewSnapshotOperationStatus(metrics.SnapshotStatusTypeSuccess), driverName)
1159-
}
1160-
11611098
newSnapshotObj, err := ctrl.clientset.SnapshotV1beta1().VolumeSnapshots(snapshotClone.Namespace).UpdateStatus(context.TODO(), snapshotClone, metav1.UpdateOptions{})
11621099
if err != nil {
11631100
return nil, newControllerUpdateError(utils.SnapshotKey(snapshot), err.Error())
11641101
}
1165-
11661102
return newSnapshotObj, nil
11671103
}
11681104

@@ -1250,49 +1186,8 @@ func (ctrl *csiSnapshotCommonController) getSnapshotClass(className string) (*cr
12501186
return class, nil
12511187
}
12521188

1253-
// getSnapshotDriverName is a helper function to get snapshot driver from the VolumeSnapshot.
1254-
// We try to get the driverName in multiple ways, as snapshot controller metrics depend on the correct driverName.
1255-
func (ctrl *csiSnapshotCommonController) getSnapshotDriverName(vs *crdv1.VolumeSnapshot) (string, error) {
1256-
klog.V(5).Infof("getSnapshotDriverName: VolumeSnapshot[%s]", vs.Name)
1257-
var driverName string
1258-
1259-
// Pre-Provisioned snapshots have contentName as source
1260-
var contentName string
1261-
if vs.Spec.Source.VolumeSnapshotContentName != nil {
1262-
contentName = *vs.Spec.Source.VolumeSnapshotContentName
1263-
}
1264-
1265-
// Get Driver name from SnapshotContent if we found a contentName
1266-
if contentName != "" {
1267-
content, err := ctrl.contentLister.Get(contentName)
1268-
if err != nil {
1269-
klog.Errorf("getSnapshotDriverName: failed to get snapshotContent: %v", contentName)
1270-
} else {
1271-
driverName = content.Spec.Driver
1272-
}
1273-
1274-
if driverName != "" {
1275-
return driverName, nil
1276-
}
1277-
}
1278-
1279-
// Dynamic snapshots will have a snapshotclass with a driver
1280-
if vs.Spec.VolumeSnapshotClassName != nil {
1281-
class, err := ctrl.getSnapshotClass(*vs.Spec.VolumeSnapshotClassName)
1282-
if err != nil {
1283-
klog.Errorf("getSnapshotDriverName: failed to get snapshotClass: %v", *vs.Spec.VolumeSnapshotClassName)
1284-
} else {
1285-
driverName = class.Driver
1286-
}
1287-
}
1288-
1289-
return driverName, nil
1290-
}
1291-
1292-
// SetDefaultSnapshotClass is a helper function to figure out the default snapshot class.
1293-
// For pre-provisioned case, it's an no-op.
1294-
// For dynamic provisioning, it gets the default SnapshotClasses in the system if there is any(could be multiple),
1295-
// and finds the one with the same CSI Driver as the PV from which a snapshot will be taken.
1189+
// SetDefaultSnapshotClass is a helper function to figure out the default snapshot class from
1190+
// PVC/PV StorageClass and update VolumeSnapshot with this snapshot class name.
12961191
func (ctrl *csiSnapshotCommonController) SetDefaultSnapshotClass(snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshotClass, *crdv1.VolumeSnapshot, error) {
12971192
klog.V(5).Infof("SetDefaultSnapshotClass for snapshot [%s]", snapshot.Name)
12981193

pkg/common-controller/snapshot_controller_base.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
clientset "github.com/kubernetes-csi/external-snapshotter/client/v3/clientset/versioned"
2525
storageinformers "github.com/kubernetes-csi/external-snapshotter/client/v3/informers/externalversions/volumesnapshot/v1beta1"
2626
storagelisters "github.com/kubernetes-csi/external-snapshotter/client/v3/listers/volumesnapshot/v1beta1"
27-
"github.com/kubernetes-csi/external-snapshotter/v3/pkg/metrics"
2827
"github.com/kubernetes-csi/external-snapshotter/v3/pkg/utils"
2928

3029
v1 "k8s.io/api/core/v1"
@@ -61,8 +60,6 @@ type csiSnapshotCommonController struct {
6160
snapshotStore cache.Store
6261
contentStore cache.Store
6362

64-
metricsManager metrics.MetricsManager
65-
6663
resyncPeriod time.Duration
6764
}
6865

@@ -74,7 +71,6 @@ func NewCSISnapshotCommonController(
7471
volumeSnapshotContentInformer storageinformers.VolumeSnapshotContentInformer,
7572
volumeSnapshotClassInformer storageinformers.VolumeSnapshotClassInformer,
7673
pvcInformer coreinformers.PersistentVolumeClaimInformer,
77-
metricsManager metrics.MetricsManager,
7874
resyncPeriod time.Duration,
7975
) *csiSnapshotCommonController {
8076
broadcaster := record.NewBroadcaster()
@@ -84,15 +80,14 @@ func NewCSISnapshotCommonController(
8480
eventRecorder = broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: fmt.Sprintf("snapshot-controller")})
8581

8682
ctrl := &csiSnapshotCommonController{
87-
clientset: clientset,
88-
client: client,
89-
eventRecorder: eventRecorder,
90-
resyncPeriod: resyncPeriod,
91-
snapshotStore: cache.NewStore(cache.DeletionHandlingMetaNamespaceKeyFunc),
92-
contentStore: cache.NewStore(cache.DeletionHandlingMetaNamespaceKeyFunc),
93-
snapshotQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "snapshot-controller-snapshot"),
94-
contentQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "snapshot-controller-content"),
95-
metricsManager: metricsManager,
83+
clientset: clientset,
84+
client: client,
85+
eventRecorder: eventRecorder,
86+
resyncPeriod: resyncPeriod,
87+
snapshotStore: cache.NewStore(cache.DeletionHandlingMetaNamespaceKeyFunc),
88+
contentStore: cache.NewStore(cache.DeletionHandlingMetaNamespaceKeyFunc),
89+
snapshotQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "snapshot-controller-snapshot"),
90+
contentQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "snapshot-controller-content"),
9691
}
9792

9893
ctrl.pvcLister = pvcInformer.Lister()
@@ -368,7 +363,6 @@ func (ctrl *csiSnapshotCommonController) updateSnapshot(snapshot *crdv1.VolumeSn
368363
if !newSnapshot {
369364
return nil
370365
}
371-
372366
err = ctrl.syncSnapshot(snapshot)
373367
if err != nil {
374368
if errors.IsConflict(err) {
@@ -413,13 +407,6 @@ func (ctrl *csiSnapshotCommonController) updateContent(content *crdv1.VolumeSnap
413407
func (ctrl *csiSnapshotCommonController) deleteSnapshot(snapshot *crdv1.VolumeSnapshot) {
414408
_ = ctrl.snapshotStore.Delete(snapshot)
415409
klog.V(4).Infof("snapshot %q deleted", utils.SnapshotKey(snapshot))
416-
driverName, err := ctrl.getSnapshotDriverName(snapshot)
417-
if err != nil {
418-
klog.Errorf("failed to getSnapshotDriverName while recording metrics for snapshot %q: %s", utils.SnapshotKey(snapshot), err)
419-
} else {
420-
deleteOperationKey := metrics.NewOperationKey(metrics.DeleteSnapshotOperationName, snapshot.UID)
421-
ctrl.metricsManager.RecordMetrics(deleteOperationKey, metrics.NewSnapshotOperationStatus(metrics.SnapshotStatusTypeSuccess), driverName)
422-
}
423410

424411
snapshotContentName := ""
425412
if snapshot.Status != nil && snapshot.Status.BoundVolumeSnapshotContentName != nil {
@@ -429,7 +416,6 @@ func (ctrl *csiSnapshotCommonController) deleteSnapshot(snapshot *crdv1.VolumeSn
429416
klog.V(5).Infof("deleteSnapshot[%q]: content not bound", utils.SnapshotKey(snapshot))
430417
return
431418
}
432-
433419
// sync the content when its snapshot is deleted. Explicitly sync'ing the
434420
// content here in response to snapshot deletion prevents the content from
435421
// waiting until the next sync period for its Release.

0 commit comments

Comments
 (0)