Skip to content

Commit

Permalink
Merge pull request #913 from feiskyer/logs
Browse files Browse the repository at this point in the history
chore: add warning logs for ARM request body on failures
  • Loading branch information
k8s-ci-robot committed Nov 26, 2021
2 parents 01fe5e6 + 8068f86 commit be76f79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pkg/azureclients/armclient/azure_armclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ func dumpResponse(resp *http.Response, v klog.Level) {
}

func dumpRequest(req *http.Request, v klog.Level) {
if req == nil {
return
}

requestDump, err := httputil.DumpRequest(req, true)
if err != nil {
klog.Errorf("Failed to dump request: %v", err)
Expand Down Expand Up @@ -412,14 +416,14 @@ func (c *Client) PutResources(ctx context.Context, resources map[string]interfac
autorest.WithJSON(parameters),
}
request, err := c.PreparePutRequest(ctx, decorators...)
dumpRequest(request, 10)
if err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "put.prepare", resourceID, err)
responses[resourceID] = &PutResourcesResponse{
Error: retry.NewError(false, err),
}
continue
}
dumpRequest(request, 10)

future, resp, clientErr := c.SendAsync(ctx, request)
defer c.CloseResponse(ctx, resp)
Expand Down Expand Up @@ -479,11 +483,11 @@ func (c *Client) PutResources(ctx context.Context, resources map[string]interfac
// PutResourceWithDecorators puts a resource by resource ID
func (c *Client) PutResourceWithDecorators(ctx context.Context, resourceID string, parameters interface{}, decorators []autorest.PrepareDecorator) (*http.Response, *retry.Error) {
request, err := c.PreparePutRequest(ctx, decorators...)
dumpRequest(request, 10)
if err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "put.prepare", resourceID, err)
return nil, retry.NewError(false, err)
}
dumpRequest(request, 10)

future, resp, clientErr := c.SendAsync(ctx, request)
defer c.CloseResponse(ctx, resp)
Expand Down Expand Up @@ -582,11 +586,11 @@ func (c *Client) PutResourceAsync(ctx context.Context, resourceID string, parame
}

request, err := c.PreparePutRequest(ctx, decorators...)
dumpRequest(request, 10)
if err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "put.prepare", resourceID, err)
return nil, retry.NewError(false, err)
}
dumpRequest(request, 10)

future, resp, rErr := c.SendAsync(ctx, request)
defer c.CloseResponse(ctx, resp)
Expand Down
13 changes: 12 additions & 1 deletion pkg/provider/azure_backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package provider

import (
"encoding/json"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -159,6 +160,9 @@ func (az *Cloud) CreateOrUpdateSecurityGroup(sg network.SecurityGroup) error {
return nil
}

nsgJSON, _ := json.Marshal(sg)
klog.Warningf("CreateOrUpdateSecurityGroup(%s) failed: %v, NSG request: %s", to.String(sg.Name), rerr.Error(), string(nsgJSON))

// Invalidate the cache because ETAG precondition mismatch.
if rerr.HTTPStatusCode == http.StatusPreconditionFailed {
klog.V(3).Infof("SecurityGroup cache for %s is cleanup because of http.StatusPreconditionFailed", *sg.Name)
Expand Down Expand Up @@ -217,6 +221,9 @@ func (az *Cloud) CreateOrUpdateLB(service *v1.Service, lb network.LoadBalancer)
return nil
}

lbJSON, _ := json.Marshal(lb)
klog.Warningf("LoadBalancerClient.CreateOrUpdate(%s) failed: %v, LoadBalancer request: %s", to.String(lb.Name), rerr.Error(), string(lbJSON))

// Invalidate the cache because ETAG precondition mismatch.
if rerr.HTTPStatusCode == http.StatusPreconditionFailed {
klog.V(3).Infof("LoadBalancer cache for %s is cleanup because of http.StatusPreconditionFailed", to.String(lb.Name))
Expand Down Expand Up @@ -339,7 +346,8 @@ func (az *Cloud) CreateOrUpdatePIP(service *v1.Service, pipResourceGroup string,
rerr := az.PublicIPAddressesClient.CreateOrUpdate(ctx, pipResourceGroup, to.String(pip.Name), pip)
klog.V(10).Infof("PublicIPAddressesClient.CreateOrUpdate(%s, %s): end", pipResourceGroup, to.String(pip.Name))
if rerr != nil {
klog.Errorf("PublicIPAddressesClient.CreateOrUpdate(%s, %s) failed: %s", pipResourceGroup, to.String(pip.Name), rerr.Error().Error())
pipJSON, _ := json.Marshal(pip)
klog.Warningf("PublicIPAddressesClient.CreateOrUpdate(%s, %s) failed: %s, PublicIP request: %s", pipResourceGroup, to.String(pip.Name), rerr.Error().Error(), string(pipJSON))
az.Event(service, v1.EventTypeWarning, "CreateOrUpdatePublicIPAddress", rerr.Error().Error())
return rerr.Error()
}
Expand Down Expand Up @@ -413,6 +421,9 @@ func (az *Cloud) CreateOrUpdateRouteTable(routeTable network.RouteTable) error {
return nil
}

rtJSON, _ := json.Marshal(routeTable)
klog.Warningf("RouteTablesClient.CreateOrUpdate(%s) failed: %v, RouteTable request: %s", to.String(routeTable.Name), rerr.Error(), string(rtJSON))

// Invalidate the cache because etag mismatch.
if rerr.HTTPStatusCode == http.StatusPreconditionFailed {
klog.V(3).Infof("Route table cache for %s is cleanup because of http.StatusPreconditionFailed", *routeTable.Name)
Expand Down

0 comments on commit be76f79

Please sign in to comment.