Skip to content

Commit

Permalink
debugging: print ARM operation ID to improve debugging (#1080)
Browse files Browse the repository at this point in the history
* debugging: print ARM operation ID to improve debugging

* move var to azure.go
  • Loading branch information
akshaysngupta committed Dec 4, 2020
1 parent 183869d commit 1400bf2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
32 changes: 26 additions & 6 deletions pkg/azure/azure.go
Expand Up @@ -7,21 +7,28 @@ package azure

import (
"fmt"
"regexp"
"strings"

"github.com/golang/glog"

"github.com/Azure/application-gateway-kubernetes-ingress/pkg/controllererrors"
)

// SubscriptionID is the subscription of the resource in the resourceID
type SubscriptionID string
type (
// SubscriptionID is the subscription of the resource in the resourceID
SubscriptionID string

// ResourceGroup is the resource group in which resource is deployed in the resourceID
type ResourceGroup string
// ResourceGroup is the resource group in which resource is deployed in the resourceID
ResourceGroup string

// ResourceName is the resource name in the resourceID
type ResourceName string
// ResourceName is the resource name in the resourceID
ResourceName string
)

var (
operationIDRegex = regexp.MustCompile(`/operations/(.+)\?api-version`)
)

// ParseResourceID gets subscriptionId, resource group, resource name from resourceID
func ParseResourceID(ID string) (SubscriptionID, ResourceGroup, ResourceName) {
Expand Down Expand Up @@ -83,3 +90,16 @@ func ConvertToClusterResourceGroup(subscriptionID SubscriptionID, resourceGroup

return fmt.Sprintf("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", subscriptionID, split[1], split[2]), nil
}

// GetOperationIDFromPollingURL extracts operationID from pollingURL
func GetOperationIDFromPollingURL(pollingURL string) string {
operationID := ""
if pollingURL != "" {
matchGroup := operationIDRegex.FindStringSubmatch(pollingURL)
if len(matchGroup) == 2 {
operationID = matchGroup[1]
}
}

return operationID
}
14 changes: 14 additions & 0 deletions pkg/azure/azure_test.go
Expand Up @@ -157,5 +157,19 @@ var _ = Describe("Azure", func() {
Expect(subResource).To(Equal(ResourceName("")))
})
})

Context("test GetOperationIDFromPollingURL func", func() {
It("should be able to parse operationID", func() {
pollingURL := "https://management.azure.com/subscriptions/87654321-abcd-1234-b193-d305572e416f/providers/Microsoft.Network/locations/eastus2/operations/c24da597-9666-4950-a9f7-10bdfa17883d?api-version=2020-05-01"
expectedOperationID := "c24da597-9666-4950-a9f7-10bdfa17883d"
Expect(GetOperationIDFromPollingURL(pollingURL)).To(Equal(expectedOperationID))
})

It("should give empty string when unable to parse", func() {
pollingURL := "random"
expectedOperationID := ""
Expect(GetOperationIDFromPollingURL(pollingURL)).To(Equal(expectedOperationID))
})
})
})
})
4 changes: 4 additions & 0 deletions pkg/azure/client.go
Expand Up @@ -197,6 +197,10 @@ func (az *azClient) UpdateGateway(appGwObj *n.ApplicationGateway) (err error) {
return
}

if appGwFuture.PollingURL() != "" {
glog.V(3).Infof("OperationID='%s'", GetOperationIDFromPollingURL(appGwFuture.PollingURL()))
}

// Wait until deployment finshes and save the error message
err = appGwFuture.WaitForCompletionRef(az.ctx, az.appGatewaysClient.BaseClient.Client)
return
Expand Down

0 comments on commit 1400bf2

Please sign in to comment.