azure-sdk-for-go: Resource Group Create SDK should return an async poller - otherwise SDK users who create resources right after creating resource groups may see intermittent resource creation errors

Bug Report

Our Symptom

We are a team that runs frequent automated tests using the azure-sdk-for-go. Our test job does the following:

  1. Create a resource group in ARM
  2. Create a resource in that resource group in ARM
  3. Delete that resource in ARM
  4. Delete that resource group in ARM

Our tests recently started failing intermittently.

Based on our tests, we believe that ARM takes a few seconds for resource group creation to propagate in some cases and that those cases have recently become more common for us.

We have the following logs showing the calls we made to ARM:

TIMESTAMP operationName httpMethod httpStatusCode
2023-09-19T01:49:53.3022402Z PUT/SUBSCRIPTIONS/RESOURCEGROUPS/ PUT -1
2023-09-19T01:49:53.5115976Z PUT/SUBSCRIPTIONS/RESOURCEGROUPS/ PUT 201
2023-09-19T01:49:53.5385677Z PUT/SUBSCRIPTIONS/RESOURCEGROUPS/PROVIDERS/[REDACTED]/[REDACTED]/ PUT -1
2023-09-19T01:49:53.675967Z PUT/SUBSCRIPTIONS/RESOURCEGROUPS/PROVIDERS/[REDACTED]/[REDACTED]/ PUT 404
2023-09-19T01:49:53.6893615Z DELETE/SUBSCRIPTIONS/RESOURCEGROUPS/ DELETE -1
2023-09-19T01:49:53.7077024Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET -1
2023-09-19T01:49:53.7208683Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET 200
2023-09-19T01:49:53.8012578Z DELETE/SUBSCRIPTIONS/RESOURCEGROUPS/ DELETE 202
2023-09-19T01:49:57.5268868Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET -1
2023-09-19T01:49:57.5407255Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET 404
2023-09-19T01:49:59.8134708Z
2023-09-19T01:50:54.3947647Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET -1
2023-09-19T01:50:54.4134174Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET 404
2023-09-19T01:50:58.6345241Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET -1
2023-09-19T01:50:58.6453696Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET 404
2023-09-19T01:54:54.4810864Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET -1
2023-09-19T01:54:54.4928623Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET 404
2023-09-19T01:54:57.8525784Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET -1
2023-09-19T01:54:57.8741165Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET 404
2023-09-19T01:59:55.1376881Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET -1
2023-09-19T01:59:55.1507581Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET 404
2023-09-19T01:59:56.3132961Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET -1
2023-09-19T01:59:56.3257017Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET 404
2023-09-19T02:19:59.0603705Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET -1
2023-09-19T02:19:59.0735594Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET 404
2023-09-19T02:49:54.5073409Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET -1
2023-09-19T02:49:54.5207871Z GET/SUBSCRIPTIONS/RESOURCEGROUPS/ GET 404

The Problem in azure-sdk-for-go

Here’s the call signature for creation of a resource group in the track 2 azure-sdk-for-go from azresources.ResourceGroupsClient:

CreateOrUpdate(
		ctx context.Context,
		resourceGroupName string,
		parameters azresources.ResourceGroup,
		options *azresources.ResourceGroupsClientCreateOrUpdateOptions,
) (response azresources.ResourceGroupsClientCreateOrUpdateResponse, err error)

Link: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/resourcemanager/resources/armresources/resourcegroups_client.go

That type is simply a resource group:

// ResourceGroupsClientCreateOrUpdateResponse contains the response from method ResourceGroupsClient.CreateOrUpdate.
type ResourceGroupsClientCreateOrUpdateResponse struct {
	// Resource group information.
	ResourceGroup
}

Link: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/resourcemanager/resources/armresources/response_types.go

This makes it easy for clients of the sdk to write code like this:

rg, err := resourceGroupClient.CreateOrUpdate(ctx, params.Name, azresources.ResourceGroup{
				Location: to.Ptr(params.Location),
				Name:     to.Ptr(params.Name),
			}, nil)

someOtherResource, err := resourceClient.CreateOrUpdate(ctx, params.Name, rg.Name, // other params)

However, this code will have some small chance of failing if ARM encounters the same delay we encountered. Customers of the SDK will go through a difficult and confusing troubleshooting process before either adding their own custom polling or a delay to their code like this:

rg, err := resourceGroupClient.CreateOrUpdate(ctx, params.Name, azresources.ResourceGroup{
				Location: to.Ptr(params.Location),
				Name:     to.Ptr(params.Name),
			}, nil)

time.Sleep(10 * time.Second)

someOtherResource, err := resourceClient.CreateOrUpdate(ctx, params.Name, rg.Name, // other params)

We added a custom poller to our code to get around this issue.

Can the resource group client be updated to return an async poller to reflect this delay and to avoid duplicating the troubleshooting we did?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

@serbrech This fix did not work for us. We continue to see the issue with the correlation id set.

It looks like even with the correlation id being the same, it is possible for traffic to be routed to different regions in quick succession.

PreciseTimeStamp httpMethod operationName httpStatusCode correlationId Location
2024-02-29T16:23:52.4732221Z PUT PUT/SUBSCRIPTIONS/RESOURCEGROUPS/ -1 5309fae3-d2d3-49ae-8e59-776c19847c89 Japan East
2024-02-29T16:23:52.5997332Z PUT PUT/SUBSCRIPTIONS/RESOURCEGROUPS/ 201 5309fae3-d2d3-49ae-8e59-776c19847c89 Japan East
2024-02-29T16:23:52.6111353Z GET GET/SUBSCRIPTIONS/RESOURCEGROUPS/ -1 5309fae3-d2d3-49ae-8e59-776c19847c89 Japan East
2024-02-29T16:23:52.6316374Z GET GET/SUBSCRIPTIONS/RESOURCEGROUPS/ 200 5309fae3-d2d3-49ae-8e59-776c19847c89 Japan East
2024-02-29T16:23:52.6604192Z PUT PUT/SUBSCRIPTIONS/RESOURCEGROUPS/PROVIDERS/MICROSOFT.EXTENDEDLOCATION/CUSTOMLOCATIONS/ -1 5309fae3-d2d3-49ae-8e59-776c19847c89 Japan West
2024-02-29T16:23:52.777555Z PUT PUT/SUBSCRIPTIONS/RESOURCEGROUPS/PROVIDERS/MICROSOFT.EXTENDEDLOCATION/CUSTOMLOCATIONS/ 404 5309fae3-d2d3-49ae-8e59-776c19847c89 Japan West

@serbrech I confirmed with ARM team that this behavior is currently expected.

I have reached out to the devs owning resource group. I’ll see what they say