Azure / Azure/azure-rest-api-specs-examples

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

Open
#6,156 1 comment 0 reactions 1 assignee Claimed by @JiaqiZhang-Dev View on GitHub
customer-reported question
Dominant language
No language data
Stars
40
Forks
23
Avg merge
23h 36m
Merged PRs (30d)
172

Description

### 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
- [x] Golang
- [ ] Other - Please specify in Issue details field

### Sample Issue Type

- [x] 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.