From 7d247b51f171a57f1c3bfd9f7e4b55a0fc107d84 Mon Sep 17 00:00:00 2001 From: Rishabh Patel Date: Mon, 27 Mar 2023 18:29:04 +0530 Subject: [PATCH 1/3] remove use of defer in printing logs --- pkg/azure/core.go | 49 +++++++++++++++++++++++++++++++++------------- pkg/azure/utils.go | 15 ++++++++------ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/pkg/azure/core.go b/pkg/azure/core.go index 9c3167cac..2d7945520 100644 --- a/pkg/azure/core.go +++ b/pkg/azure/core.go @@ -79,24 +79,25 @@ func NewAzureDriver(spi spi.SessionProviderInterface) *MachinePlugin { // It is optionally expected by the safety controller to use an identification mechanisms to map the VM Created by a providerSpec. // These could be done using tag(s)/resource-groups etc. // This logic is used by safety controller to delete orphan VMs which are not backed by any machine CRD -// func (d *MachinePlugin) CreateMachine(ctx context.Context, req *driver.CreateMachineRequest) (*driver.CreateMachineResponse, error) { // Log messages to track request - klog.V(2).Infof("Machine creation request has been recieved for %q", req.Machine.Name) - defer klog.V(2).Infof("Machine creation request has been processed for %q", req.Machine.Name) + klog.V(2).Infof("Machine creation request has been received for %q", req.Machine.Name) // Check if provider in the MachineClass is the provider we support if req.MachineClass.Provider != ProviderAzure { err := fmt.Errorf("requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderAzure) + klog.V(2).Infof("Machine creation request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.InvalidArgument, err.Error()) } virtualMachine, err := d.createVMNicDisk(req) if err != nil { + klog.V(2).Infof("Machine creation request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.Internal, err.Error()) } providerID := encodeMachineID(*virtualMachine.Location, *virtualMachine.Name) + klog.V(2).Infof("Machine creation request has been processed successfully for %q", req.Machine.Name) return &driver.CreateMachineResponse{ProviderID: providerID, NodeName: *virtualMachine.Name}, nil } @@ -114,17 +115,18 @@ func (d *MachinePlugin) CreateMachine(ctx context.Context, req *driver.CreateMac // func (d *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMachineRequest) (*driver.DeleteMachineResponse, error) { // Log messages to track delete request - klog.V(2).Infof("Machine deletion request has been recieved for %q", req.Machine.Name) - defer klog.V(2).Infof("Machine deletion request has been processed for %q", req.Machine.Name) + klog.V(2).Infof("Machine deletion request has been received for %q", req.Machine.Name) // Check if provider in the MachineClass is the provider we support if req.MachineClass.Provider != ProviderAzure { err := fmt.Errorf("requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderAzure) + klog.V(2).Infof("Machine deletion request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.InvalidArgument, err.Error()) } providerSpec, err := DecodeProviderSpecAndSecret(req.MachineClass, req.Secret) if err != nil { + klog.V(2).Infof("Machine deletion request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.Internal, err.Error()) } @@ -138,11 +140,13 @@ func (d *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMac clients, err := d.SPI.Setup(req.Secret) if err != nil { + klog.V(2).Infof("Machine deletion request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.Internal, err.Error()) } // Check if the underlying resource group still exists. If not, skip the deletion, as all resources are gone. if _, err := clients.GetGroup().Get(ctx, resourceGroupName); err != nil { + klog.V(2).Infof("Machine deletion request failed for %q, Error: %v", req.Machine.Name, err) if NotFound(err) { return nil, status.Error(codes.NotFound, err.Error()) } @@ -155,9 +159,11 @@ func (d *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMac err = d.deleteVMNicDisks(ctx, clients, resourceGroupName, vmName, nicName, diskName, dataDiskNames) if err != nil { + klog.V(2).Infof("Machine deletion request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.Internal, err.Error()) } + klog.V(2).Infof("Machine deletion request has been processed successfully for %q", req.Machine.Name) return &driver.DeleteMachineResponse{}, nil } @@ -179,12 +185,12 @@ func (d *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMac // The request should return a NOT_FOUND (5) status error code if the machine is not existing func (d *MachinePlugin) GetMachineStatus(ctx context.Context, req *driver.GetMachineStatusRequest) (*driver.GetMachineStatusResponse, error) { // Log messages to track start and end of request - klog.V(4).Infof("Get request has been recieved for %q", req.Machine.Name) - defer klog.V(2).Infof("Machine get request has been processed successfully for %q", req.Machine.Name) + klog.V(4).Infof("Machine get request has been received for %q", req.Machine.Name) // Check if provider in the MachineClass is the provider we support if req.MachineClass.Provider != ProviderAzure { err := fmt.Errorf("requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderAzure) + klog.V(2).Infof("Machine Get request has failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.InvalidArgument, err.Error()) } @@ -194,16 +200,20 @@ func (d *MachinePlugin) GetMachineStatus(ctx context.Context, req *driver.GetMac machines, err := d.ListMachines(ctx, listMachineRequest) if err != nil { + klog.V(2).Infof("Machine get request has failed for %q, Error: %v", req.Machine.Name, err) return nil, err } for providerID, VMName := range machines.MachineList { if VMName == req.Machine.Name { machineStatusResponse.NodeName = VMName machineStatusResponse.ProviderID = providerID + klog.V(2).Infof("Machine get request has been processed successfully for %q", req.Machine.Name) return machineStatusResponse, nil } } err = fmt.Errorf("machine '%s' not found", req.Machine.Name) + klog.V(2).Infof("Machine get request has failed for %q, Error: %v", req.Machine.Name, err) + return nil, status.Error(codes.NotFound, err.Error()) } @@ -222,17 +232,18 @@ func (d *MachinePlugin) GetMachineStatus(ctx context.Context, req *driver.GetMac // func (d *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachinesRequest) (*driver.ListMachinesResponse, error) { // Log messages to track start and end of request - klog.V(2).Infof("List machines request has been recieved for %q", req.MachineClass.Name) - defer klog.V(2).Infof("List machines request has been recieved for %q", req.MachineClass.Name) + klog.V(2).Infof("List machines request has been received for %q", req.MachineClass.Name) // Check if provider in the MachineClass is the provider we support if req.MachineClass.Provider != ProviderAzure { err := fmt.Errorf("requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderAzure) + klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.InvalidArgument, err.Error()) } providerSpec, err := DecodeProviderSpecAndSecret(req.MachineClass, req.Secret) if err != nil { + klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.InvalidArgument, err.Error()) } @@ -245,6 +256,7 @@ func (d *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachin clients, err := d.SPI.Setup(req.Secret) if err != nil { + klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.Internal, err.Error()) } @@ -253,6 +265,7 @@ func (d *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachin klog.V(2).Infof("resource group %q does not exists thus no machines can be listed", resourceGroupName) return &driver.ListMachinesResponse{MachineList: listOfVMs}, nil } + klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.Internal, err.Error()) } @@ -264,23 +277,27 @@ func (d *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachin listOfVMs, err = getRelevantVMs(ctx, clients, resourceGroupName, location, tags) if err != nil { + klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.Internal, err.Error()) } mergeIntoResult(listOfVMs) listOfVMsByNIC, err := getRelevantNICs(ctx, clients, resourceGroupName, location, tags) if err != nil { + klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.Internal, err.Error()) } mergeIntoResult(listOfVMsByNIC) listOfVMsByDisk, err := getRelevantDisks(ctx, clients, resourceGroupName, location, tags) if err != nil { + klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.Internal, err.Error()) } mergeIntoResult(listOfVMsByDisk) OnARMAPISuccess(prometheusServiceVM, "VM.List") + klog.V(2).Infof("List machines request has been processed successfully for %q", req.MachineClass.Name) return &driver.ListMachinesResponse{MachineList: listOfVMs}, nil } @@ -291,11 +308,9 @@ func (d *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachin // // RESPONSE PARAMETERS (driver.GetVolumeIDsResponse) // VolumeIDs []string VolumeIDs is a repeated list of VolumeIDs. -// func (d *MachinePlugin) GetVolumeIDs(ctx context.Context, req *driver.GetVolumeIDsRequest) (*driver.GetVolumeIDsResponse, error) { // Log messages to track start and end of request klog.V(2).Infof("GetVolumeIDs request recieved for %q", req.PVSpecs) - defer klog.V(2).Infof("GetVolumeIDs request processed successfully for %q", req.PVSpecs) names := []string{} specs := req.PVSpecs @@ -311,6 +326,7 @@ func (d *MachinePlugin) GetVolumeIDs(ctx context.Context, req *driver.GetVolumeI } } + klog.V(2).Infof("GetVolumeIDs request processed successfully for %q", req.PVSpecs) return &driver.GetVolumeIDsResponse{VolumeIDs: names}, nil } @@ -332,11 +348,9 @@ func (d *MachinePlugin) GetVolumeIDs(ctx context.Context, req *driver.GetVolumeI // // RESPONSE PARAMETERS (driver.GenerateMachineClassForMigration) // NONE -// func (d *MachinePlugin) GenerateMachineClassForMigration(ctx context.Context, req *driver.GenerateMachineClassForMigrationRequest) (*driver.GenerateMachineClassForMigrationResponse, error) { // Log messages to track start and end of request klog.V(2).Infof("MigrateMachineClass request has been recieved for %q", req.ClassSpec) - defer klog.V(2).Infof("MigrateMachineClass request has been processed successfully for %q", req.ClassSpec) azureMachineClass := req.ProviderSpecificMachineClass.(*v1alpha1.AzureMachineClass) @@ -346,5 +360,12 @@ func (d *MachinePlugin) GenerateMachineClassForMigration(ctx context.Context, re return nil, status.Error(codes.Internal, "Migration cannot be done for this machineClass kind") } - return &driver.GenerateMachineClassForMigrationResponse{}, fillUpMachineClass(azureMachineClass, req.MachineClass) + err := fillUpMachineClass(azureMachineClass, req.MachineClass) + if err == nil { + klog.V(2).Infof("MigrateMachineClass request has been processed successfully for %q", req.ClassSpec) + } else { + klog.V(2).Infof("MigrateMachineClass request has failed for %q, Error: %v", req.ClassSpec, err) + } + + return &driver.GenerateMachineClassForMigrationResponse{}, err } diff --git a/pkg/azure/utils.go b/pkg/azure/utils.go index bf5097438..76e988359 100644 --- a/pkg/azure/utils.go +++ b/pkg/azure/utils.go @@ -650,10 +650,8 @@ func fillUpMachineClass(azureMachineClass *v1alpha1.AzureMachineClass, machineCl // WaitForDataDiskDetachment is function that ensures all the data disks are detached from the VM func waitForDataDiskDetachment(ctx context.Context, clients spi.AzureDriverClientsInterface, resourceGroupName string, vm compute.VirtualMachine) error { - klog.V(2).Infof("Data disk detachment began for %q", *vm.Name) - defer klog.V(2).Infof("Data disk detached for %q", *vm.Name) - if len(*vm.StorageProfile.DataDisks) > 0 { + klog.V(2).Infof("Data disk detachment began for %q", *vm.Name) // There are disks attached hence need to detach them vm.StorageProfile.DataDisks = &[]compute.DataDisk{} @@ -666,6 +664,9 @@ func waitForDataDiskDetachment(ctx context.Context, clients spi.AzureDriverClien return OnARMAPIErrorFail(prometheusServiceVM, err, "Failed to CreateOrUpdate. Error Message - %s", err) } OnARMAPISuccess(prometheusServiceVM, "VM CreateOrUpdate was successful for %s", *vm.Name) + klog.V(2).Infof("Data disk detached for %q", *vm.Name) + } else { + klog.V(2).Infof("No data disk to detach from %q", *vm.Name) } return nil @@ -687,7 +688,6 @@ func FetchAttachedVMfromNIC(ctx context.Context, clients spi.AzureDriverClientsI func DeleteNIC(ctx context.Context, clients spi.AzureDriverClientsInterface, resourceGroupName string, nicName string) error { klog.V(2).Infof("NIC delete started for %q", nicName) - defer klog.V(2).Infof("NIC deleted for %q", nicName) nicDeletionCtx, cancel := context.WithTimeout(ctx, nicDeletionTimeout) defer cancel() @@ -715,13 +715,14 @@ func DeleteNIC(ctx context.Context, clients spi.AzureDriverClientsInterface, res } OnARMAPISuccess(prometheusServiceNIC, "NIC deletion was successful for %s", nicName) + klog.V(2).Infof("NIC deleted for %q", nicName) + return nil } // DeleteVM is the helper function to acknowledge the VM deletion func DeleteVM(ctx context.Context, clients spi.AzureDriverClientsInterface, resourceGroupName string, vmName string) error { klog.V(2).Infof("VM deletion has began for %q", vmName) - defer klog.V(2).Infof("VM deleted for %q", vmName) forceDeletion := false future, err := clients.GetVM().Delete(ctx, resourceGroupName, vmName, &forceDeletion) @@ -733,6 +734,8 @@ func DeleteVM(ctx context.Context, clients spi.AzureDriverClientsInterface, reso return OnARMAPIErrorFail(prometheusServiceVM, err, "vm.Delete") } OnARMAPISuccess(prometheusServiceVM, "VM deletion was successful for %s", vmName) + klog.V(2).Infof("VM deleted for %q", vmName) + return nil } @@ -749,7 +752,6 @@ func fetchAttachedVMfromDisk(ctx context.Context, clients spi.AzureDriverClients func deleteDisk(ctx context.Context, clients spi.AzureDriverClientsInterface, resourceGroupName string, diskName string) error { klog.V(2).Infof("Disk delete started for %q", diskName) - defer klog.V(2).Infof("Disk deleted for %q", diskName) future, err := clients.GetDisk().Delete(ctx, resourceGroupName, diskName) if err != nil { @@ -759,6 +761,7 @@ func deleteDisk(ctx context.Context, clients spi.AzureDriverClientsInterface, re return OnARMAPIErrorFail(prometheusServiceDisk, err, "disk.Delete") } OnARMAPISuccess(prometheusServiceDisk, "Disk deletion was successful for %s", diskName) + klog.V(2).Infof("Disk deleted for %q", diskName) return nil } From d5d27b393645ba4258aaa137527b8c96fd095975 Mon Sep 17 00:00:00 2001 From: Rishabh Patel Date: Tue, 28 Mar 2023 20:58:29 +0530 Subject: [PATCH 2/3] address review comments --- pkg/azure/core.go | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/pkg/azure/core.go b/pkg/azure/core.go index 2d7945520..7ae705e9b 100644 --- a/pkg/azure/core.go +++ b/pkg/azure/core.go @@ -82,22 +82,20 @@ func NewAzureDriver(spi spi.SessionProviderInterface) *MachinePlugin { func (d *MachinePlugin) CreateMachine(ctx context.Context, req *driver.CreateMachineRequest) (*driver.CreateMachineResponse, error) { // Log messages to track request klog.V(2).Infof("Machine creation request has been received for %q", req.Machine.Name) + defer klog.V(2).Infof("Machine creation request has been processed for %q", req.Machine.Name) // Check if provider in the MachineClass is the provider we support if req.MachineClass.Provider != ProviderAzure { err := fmt.Errorf("requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderAzure) - klog.V(2).Infof("Machine creation request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.InvalidArgument, err.Error()) } virtualMachine, err := d.createVMNicDisk(req) if err != nil { - klog.V(2).Infof("Machine creation request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.Internal, err.Error()) } providerID := encodeMachineID(*virtualMachine.Location, *virtualMachine.Name) - klog.V(2).Infof("Machine creation request has been processed successfully for %q", req.Machine.Name) return &driver.CreateMachineResponse{ProviderID: providerID, NodeName: *virtualMachine.Name}, nil } @@ -116,17 +114,16 @@ func (d *MachinePlugin) CreateMachine(ctx context.Context, req *driver.CreateMac func (d *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMachineRequest) (*driver.DeleteMachineResponse, error) { // Log messages to track delete request klog.V(2).Infof("Machine deletion request has been received for %q", req.Machine.Name) + defer klog.V(2).Infof("Machine deletion request has been processed for %q", req.Machine.Name) // Check if provider in the MachineClass is the provider we support if req.MachineClass.Provider != ProviderAzure { err := fmt.Errorf("requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderAzure) - klog.V(2).Infof("Machine deletion request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.InvalidArgument, err.Error()) } providerSpec, err := DecodeProviderSpecAndSecret(req.MachineClass, req.Secret) if err != nil { - klog.V(2).Infof("Machine deletion request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.Internal, err.Error()) } @@ -140,13 +137,11 @@ func (d *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMac clients, err := d.SPI.Setup(req.Secret) if err != nil { - klog.V(2).Infof("Machine deletion request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.Internal, err.Error()) } // Check if the underlying resource group still exists. If not, skip the deletion, as all resources are gone. if _, err := clients.GetGroup().Get(ctx, resourceGroupName); err != nil { - klog.V(2).Infof("Machine deletion request failed for %q, Error: %v", req.Machine.Name, err) if NotFound(err) { return nil, status.Error(codes.NotFound, err.Error()) } @@ -159,11 +154,9 @@ func (d *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMac err = d.deleteVMNicDisks(ctx, clients, resourceGroupName, vmName, nicName, diskName, dataDiskNames) if err != nil { - klog.V(2).Infof("Machine deletion request failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.Internal, err.Error()) } - klog.V(2).Infof("Machine deletion request has been processed successfully for %q", req.Machine.Name) return &driver.DeleteMachineResponse{}, nil } @@ -185,12 +178,12 @@ func (d *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMac // The request should return a NOT_FOUND (5) status error code if the machine is not existing func (d *MachinePlugin) GetMachineStatus(ctx context.Context, req *driver.GetMachineStatusRequest) (*driver.GetMachineStatusResponse, error) { // Log messages to track start and end of request - klog.V(4).Infof("Machine get request has been received for %q", req.Machine.Name) + klog.V(2).Infof("Machine get request has been received for %q", req.Machine.Name) + defer klog.V(2).Infof("Machine get request has been processed for %q", req.Machine.Name) // Check if provider in the MachineClass is the provider we support if req.MachineClass.Provider != ProviderAzure { err := fmt.Errorf("requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderAzure) - klog.V(2).Infof("Machine Get request has failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.InvalidArgument, err.Error()) } @@ -200,19 +193,16 @@ func (d *MachinePlugin) GetMachineStatus(ctx context.Context, req *driver.GetMac machines, err := d.ListMachines(ctx, listMachineRequest) if err != nil { - klog.V(2).Infof("Machine get request has failed for %q, Error: %v", req.Machine.Name, err) return nil, err } for providerID, VMName := range machines.MachineList { if VMName == req.Machine.Name { machineStatusResponse.NodeName = VMName machineStatusResponse.ProviderID = providerID - klog.V(2).Infof("Machine get request has been processed successfully for %q", req.Machine.Name) return machineStatusResponse, nil } } err = fmt.Errorf("machine '%s' not found", req.Machine.Name) - klog.V(2).Infof("Machine get request has failed for %q, Error: %v", req.Machine.Name, err) return nil, status.Error(codes.NotFound, err.Error()) } @@ -233,17 +223,16 @@ func (d *MachinePlugin) GetMachineStatus(ctx context.Context, req *driver.GetMac func (d *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachinesRequest) (*driver.ListMachinesResponse, error) { // Log messages to track start and end of request klog.V(2).Infof("List machines request has been received for %q", req.MachineClass.Name) + defer klog.V(2).Infof("List machines request has been processed for %q", req.MachineClass.Name) // Check if provider in the MachineClass is the provider we support if req.MachineClass.Provider != ProviderAzure { err := fmt.Errorf("requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderAzure) - klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.InvalidArgument, err.Error()) } providerSpec, err := DecodeProviderSpecAndSecret(req.MachineClass, req.Secret) if err != nil { - klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.InvalidArgument, err.Error()) } @@ -256,7 +245,6 @@ func (d *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachin clients, err := d.SPI.Setup(req.Secret) if err != nil { - klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.Internal, err.Error()) } @@ -265,7 +253,6 @@ func (d *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachin klog.V(2).Infof("resource group %q does not exists thus no machines can be listed", resourceGroupName) return &driver.ListMachinesResponse{MachineList: listOfVMs}, nil } - klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.Internal, err.Error()) } @@ -277,27 +264,24 @@ func (d *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachin listOfVMs, err = getRelevantVMs(ctx, clients, resourceGroupName, location, tags) if err != nil { - klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.Internal, err.Error()) } mergeIntoResult(listOfVMs) listOfVMsByNIC, err := getRelevantNICs(ctx, clients, resourceGroupName, location, tags) if err != nil { - klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.Internal, err.Error()) } mergeIntoResult(listOfVMsByNIC) listOfVMsByDisk, err := getRelevantDisks(ctx, clients, resourceGroupName, location, tags) if err != nil { - klog.V(2).Infof("List machines request has failed for %q, Error: %v", req.MachineClass.Name, err) return nil, status.Error(codes.Internal, err.Error()) } mergeIntoResult(listOfVMsByDisk) OnARMAPISuccess(prometheusServiceVM, "VM.List") - klog.V(2).Infof("List machines request has been processed successfully for %q", req.MachineClass.Name) + return &driver.ListMachinesResponse{MachineList: listOfVMs}, nil } @@ -310,7 +294,8 @@ func (d *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachin // VolumeIDs []string VolumeIDs is a repeated list of VolumeIDs. func (d *MachinePlugin) GetVolumeIDs(ctx context.Context, req *driver.GetVolumeIDsRequest) (*driver.GetVolumeIDsResponse, error) { // Log messages to track start and end of request - klog.V(2).Infof("GetVolumeIDs request recieved for %q", req.PVSpecs) + klog.V(2).Infof("GetVolumeIDs request received for %q", req.PVSpecs) + defer klog.V(2).Infof("GetVolumeIDs request processed successfully for %q", req.PVSpecs) names := []string{} specs := req.PVSpecs @@ -326,7 +311,6 @@ func (d *MachinePlugin) GetVolumeIDs(ctx context.Context, req *driver.GetVolumeI } } - klog.V(2).Infof("GetVolumeIDs request processed successfully for %q", req.PVSpecs) return &driver.GetVolumeIDsResponse{VolumeIDs: names}, nil } @@ -351,6 +335,7 @@ func (d *MachinePlugin) GetVolumeIDs(ctx context.Context, req *driver.GetVolumeI func (d *MachinePlugin) GenerateMachineClassForMigration(ctx context.Context, req *driver.GenerateMachineClassForMigrationRequest) (*driver.GenerateMachineClassForMigrationResponse, error) { // Log messages to track start and end of request klog.V(2).Infof("MigrateMachineClass request has been recieved for %q", req.ClassSpec) + defer klog.V(2).Infof("MigrateMachineClass request has been processed for %q", req.ClassSpec) azureMachineClass := req.ProviderSpecificMachineClass.(*v1alpha1.AzureMachineClass) @@ -360,12 +345,5 @@ func (d *MachinePlugin) GenerateMachineClassForMigration(ctx context.Context, re return nil, status.Error(codes.Internal, "Migration cannot be done for this machineClass kind") } - err := fillUpMachineClass(azureMachineClass, req.MachineClass) - if err == nil { - klog.V(2).Infof("MigrateMachineClass request has been processed successfully for %q", req.ClassSpec) - } else { - klog.V(2).Infof("MigrateMachineClass request has failed for %q, Error: %v", req.ClassSpec, err) - } - - return &driver.GenerateMachineClassForMigrationResponse{}, err + return &driver.GenerateMachineClassForMigrationResponse{}, fillUpMachineClass(azureMachineClass, req.MachineClass) } From d463096bc79ee76d39d6914e25ab1184d910aad2 Mon Sep 17 00:00:00 2001 From: Rishabh Patel Date: Tue, 28 Mar 2023 21:06:25 +0530 Subject: [PATCH 3/3] revert log to higher level --- pkg/azure/core.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/azure/core.go b/pkg/azure/core.go index 7ae705e9b..c2278edda 100644 --- a/pkg/azure/core.go +++ b/pkg/azure/core.go @@ -178,7 +178,7 @@ func (d *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMac // The request should return a NOT_FOUND (5) status error code if the machine is not existing func (d *MachinePlugin) GetMachineStatus(ctx context.Context, req *driver.GetMachineStatusRequest) (*driver.GetMachineStatusResponse, error) { // Log messages to track start and end of request - klog.V(2).Infof("Machine get request has been received for %q", req.Machine.Name) + klog.V(4).Infof("Machine get request has been received for %q", req.Machine.Name) defer klog.V(2).Infof("Machine get request has been processed for %q", req.Machine.Name) // Check if provider in the MachineClass is the provider we support