Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
fix: prevent errors from being overwritten by metric report function (#…
Browse files Browse the repository at this point in the history
…967)

Signed-off-by: Ernest Wong <[email protected]>
  • Loading branch information
Ernest Wong authored Feb 10, 2021
1 parent ba80f8f commit 26c121f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 61 deletions.
48 changes: 24 additions & 24 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func GetServicePrincipalTokenFromMSI(resource string) (*adal.Token, error) {

defer func() {
if err != nil {
err = reporter.ReportIMDSOperationError(metrics.AdalTokenFromMSIOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := reporter.ReportIMDSOperationError(metrics.AdalTokenFromMSIOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
return
}
err = reporter.ReportIMDSOperationDuration(metrics.AdalTokenFromMSIOperationName, time.Since(begin))
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := reporter.ReportIMDSOperationDuration(metrics.AdalTokenFromMSIOperationName, time.Since(begin))
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
}()

Expand Down Expand Up @@ -65,15 +65,15 @@ func GetServicePrincipalTokenFromMSIWithUserAssignedID(clientID, resource string

defer func() {
if err != nil {
err = reporter.ReportIMDSOperationError(metrics.AdalTokenFromMSIWithUserAssignedIDOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := reporter.ReportIMDSOperationError(metrics.AdalTokenFromMSIWithUserAssignedIDOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
return
}
err = reporter.ReportIMDSOperationDuration(metrics.AdalTokenFromMSIWithUserAssignedIDOperationName, time.Since(begin))
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := reporter.ReportIMDSOperationDuration(metrics.AdalTokenFromMSIWithUserAssignedIDOperationName, time.Since(begin))
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
}()

Expand Down Expand Up @@ -105,15 +105,15 @@ func GetServicePrincipalToken(adEndpointFromSpec, tenantID, clientID, secret, re

defer func() {
if err != nil {
err = reporter.ReportIMDSOperationError(metrics.AdalTokenOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := reporter.ReportIMDSOperationError(metrics.AdalTokenOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
return
}
err = reporter.ReportIMDSOperationDuration(metrics.AdalTokenOperationName, time.Since(begin))
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := reporter.ReportIMDSOperationDuration(metrics.AdalTokenOperationName, time.Since(begin))
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
}()

Expand Down Expand Up @@ -185,15 +185,15 @@ func GetServicePrincipalTokenWithCertificate(adEndpointFromSpec, tenantID, clien

defer func() {
if err != nil {
err = reporter.ReportIMDSOperationError(metrics.AdalTokenOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := reporter.ReportIMDSOperationError(metrics.AdalTokenOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
return
}
err = reporter.ReportIMDSOperationDuration(metrics.AdalTokenOperationName, time.Since(begin))
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := reporter.ReportIMDSOperationDuration(metrics.AdalTokenOperationName, time.Since(begin))
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
}()

Expand Down
24 changes: 12 additions & 12 deletions pkg/cloudprovider/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func (c *VMClient) Get(rgName string, nodeName string) (compute.VirtualMachine,

defer func() {
if err != nil {
err = c.reporter.ReportCloudProviderOperationError(metrics.GetVMOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportCloudProviderOperationError(metrics.GetVMOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
return
}
err = c.reporter.ReportCloudProviderOperationDuration(metrics.GetVMOperationName, time.Since(begin))
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportCloudProviderOperationDuration(metrics.GetVMOperationName, time.Since(begin))
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
}()

Expand Down Expand Up @@ -111,15 +111,15 @@ func (c *VMClient) UpdateIdentities(rg, nodeName string, vm compute.VirtualMachi

defer func() {
if err != nil {
err = c.reporter.ReportCloudProviderOperationError(metrics.UpdateVMOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportCloudProviderOperationError(metrics.UpdateVMOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
return
}
err = c.reporter.ReportCloudProviderOperationDuration(metrics.UpdateVMOperationName, time.Since(begin))
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportCloudProviderOperationDuration(metrics.UpdateVMOperationName, time.Since(begin))
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
}()

Expand Down
22 changes: 11 additions & 11 deletions pkg/cloudprovider/vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ func (c *VMSSClient) UpdateIdentities(rg, vmssName string, vmss compute.VirtualM

defer func() {
if err != nil {
err = c.reporter.ReportCloudProviderOperationError(metrics.UpdateVMSSOperationName)
merr := c.reporter.ReportCloudProviderOperationError(metrics.UpdateVMSSOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
klog.Warningf("failed to report metrics, error: %+v", merr)
}
return
}
err = c.reporter.ReportCloudProviderOperationDuration(metrics.UpdateVMSSOperationName, time.Since(begin))
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportCloudProviderOperationDuration(metrics.UpdateVMSSOperationName, time.Since(begin))
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
}()

Expand Down Expand Up @@ -119,15 +119,15 @@ func (c *VMSSClient) Get(rgName string, vmssName string) (ret compute.VirtualMac

defer func() {
if err != nil {
err = c.reporter.ReportCloudProviderOperationError(metrics.GetVmssOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportCloudProviderOperationError(metrics.GetVmssOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
return
}
err = c.reporter.ReportCloudProviderOperationDuration(metrics.GetVmssOperationName, time.Since(begin))
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportCloudProviderOperationDuration(metrics.GetVmssOperationName, time.Since(begin))
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
}()

Expand Down
22 changes: 11 additions & 11 deletions pkg/crd/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ func (c *Client) RemoveAssignedIdentity(assignedIdentity *aadpodid.AzureAssigned

defer func() {
if err != nil {
err = c.reporter.ReportKubernetesAPIOperationError(metrics.AssignedIdentityDeletionOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportKubernetesAPIOperationError(metrics.AssignedIdentityDeletionOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
return
}
Expand Down Expand Up @@ -517,9 +517,9 @@ func (c *Client) CreateAssignedIdentity(assignedIdentity *aadpodid.AzureAssigned

defer func() {
if err != nil {
err = c.reporter.ReportKubernetesAPIOperationError(metrics.AssignedIdentityAdditionOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportKubernetesAPIOperationError(metrics.AssignedIdentityAdditionOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
return
}
Expand Down Expand Up @@ -551,8 +551,8 @@ func (c *Client) UpdateAssignedIdentity(assignedIdentity *aadpodid.AzureAssigned

defer func() {
if err != nil {
err = c.reporter.ReportKubernetesAPIOperationError(metrics.AssignedIdentityUpdateOperationName)
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportKubernetesAPIOperationError(metrics.AssignedIdentityUpdateOperationName)
klog.Warningf("failed to report metrics, error: %+v", merr)
return
}
c.reporter.Report(
Expand Down Expand Up @@ -783,9 +783,9 @@ func (c *Client) UpdateAzureAssignedIdentityStatus(assignedIdentity *aadpodid.Az

defer func() {
if err != nil {
err = c.reporter.ReportKubernetesAPIOperationError(metrics.UpdateAzureAssignedIdentityStatusOperationName)
if err != nil {
klog.Warningf("failed to report metrics, error: %+v", err)
merr := c.reporter.ReportKubernetesAPIOperationError(metrics.UpdateAzureAssignedIdentityStatusOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}
}
}()
Expand Down
6 changes: 3 additions & 3 deletions pkg/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ func (c *KubeClient) getPodListRetry(podip string, retries int, sleeptime time.D
if err == nil {
return podList, nil
}
metricErr := c.reporter.ReportKubernetesAPIOperationError(metrics.GetPodListOperationName)
if metricErr != nil {
klog.Warningf("failed to report metrics, error: %+v", metricErr)
merr := c.reporter.ReportKubernetesAPIOperationError(metrics.GetPodListOperationName)
if merr != nil {
klog.Warningf("failed to report metrics, error: %+v", merr)
}

if i >= retries {
Expand Down

0 comments on commit 26c121f

Please sign in to comment.