Skip to content

[Sample Issue] Go CosmosDBDatabaseAccountGetMetrics yields "Bad Request: Failed to parse query" #6156

@mrbonezy

Description

@mrbonezy

Link to sample

https://learn.microsoft.com/en-us/rest/api/cosmos-db-resource-provider/database-accounts/list-metrics?view=rest-cosmos-db-resource-provider-2025-04-15&tabs=Go#cosmosdbdatabaseaccountgetmetrics

Library name and version

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos/v3" or
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos/v4"

Language of the Sample

  • C#/.NET
  • Java
  • JavaScript/TypedScript
  • Python
  • Golang
  • Other - Please specify in Issue details field

Sample Issue Type

  • Sample not working
  • Sample missing
  • Do not understand sample

Issue details

Filter parsing seem to fail.
Additionally, the $filter param is duplicated as the library seems to add it (but it doesn't work also when omitting it).

Expected behavior

Return list of metrics.

Actual behavior

2025/07/01 15:57:16 GET https://management.azure.com/subscriptions/[subId]/resourceGroups/[rg]/providers/Microsoft.DocumentDB/databaseAccounts/[cosmosAccount]/metrics
--------------------------------------------------------------------------------
RESPONSE 400: 400 Bad Request
ERROR CODE: BadRequest
--------------------------------------------------------------------------------
{
  "code": "BadRequest",
  "message": "Failed to parse query $filter=(value eq 'total requests') and timegrain eq 'pt5m' and starttime eq '2017-11-19t23:53:55.2780000z' and endtime eq '2017-11-20t00:13:55.2780000z\r\nActivityId: d317192a-2135-4546-9193-df3e49dd7ff8, Microsoft.Azure.Documents.Common/2.14.0"
}
--------------------------------------------------------------------------------
exit status 1

Reproduction Steps

cosmosClientFactory, err = armcosmos.NewClientFactory(subscriptionID, cred, nil)
	if err != nil {
		log.Fatal(err)
	}

	databaseAccountsClient = cosmosClientFactory.NewDatabaseAccountsClient()

	resourceGroupName := ...
	accountName := ...
	databaseId := ...
	containerId := ...

	metricsPager := databaseAccountsClient.NewListMetricsPager(resourceGroupName, accountName, "$filter=(name.value eq 'Total Requests') and timeGrain eq duration'PT5M' and startTime eq '2017-11-19T23:53:55.2780000Z' and endTime eq '2017-11-20T00:13:55.2780000Z", nil)
	for metricsPager.More() {
		page, err := metricsPager.NextPage(ctx)
		if err != nil {
			log.Fatal(err)
		}
		for _, metric := range page.Value {
			// Before reading a value, you MUST check that the pointer is not nil
			if metric.Name != nil && metric.Name.Value != nil {
				// Dereference the pointers with * to get the actual values
				metricName := *metric.Name.Value
				fmt.Printf("Metric: %s\n", metricName)
			}
		}
	}

Environment

MacOS, Silicon M4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions