Azure-Samples / azure-samples-python-management

This repo contains sample code for management libraries of Azure SDK for Python
MIT License
171 stars 137 forks source link

Not able to get partition_id in cosmosdb #124

Open patwapro opened 1 year ago

patwapro commented 1 year ago

Hi, I am using CollectionPartitionOperations -> list_metrics.

metrics = client.collection_partition.list_metrics(
        resource_group,
        account_name,
        database_rid,
        container_rid,
        "(name.value eq 'Data Size') and timeGrain eq duration'P1D' and startTime eq '2023-01-01T13:53:55.2780000Z' and endTime eq '2023-01-31T15:58:55.2780000Z'"
    )

for metric in metrics:
        print(metric)

Not printing anything.

I set 80,000 throughputs in my container.

We are using: Python Azure SDK - azure-mgmt-cosmosdb==6.4.0 The document we follow: https://learn.microsoft.com/en-us/python/api/azure-mgmt-cosmosdb/azure.mgmt.cosmosdb.operations.collectionpartitionoperations?view=azure-python

aayush3011 commented 1 year ago

Please follow the below sample to correctly get the list_metrics.

https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/cosmos/azure-mgmt-cosmosdb/generated_samples/cosmos_db_collection_get_metrics.py

The code should be like this:

metrics = client.collection_partition.list_metrics(
        resource_group,
        account_name,
        database_rid,
        container_rid,
        "$filter=(name.value eq 'Data Size') and timeGrain eq duration'P1D' and startTime eq '2023-01-01T13:53:55.2780000Z' and endTime eq '2023-01-31T15:58:55.2780000Z'"
    )

for metric in metrics:
        print(metric)

You have to include the "$filter=" in the filter string.

patwapro commented 1 year ago

I got this issue:

HttpResponseError: (BadRequest) Failed to parse query $filter=(value eq 'data size') and timegrain eq 'p1d' and starttime eq '2023-01-01t13:53:55.2780000z' and endtime eq '2023-01-31t15:58:55.2780000z' ActivityId: c6a9ae91-a912-11ed-b4cf-5414f357addb, Microsoft.Azure.Documents.Common/2.14.0 Code: BadRequest Message: Failed to parse query $filter=(value eq 'data size') and timegrain eq 'p1d' and starttime eq '2023-01-01t13:53:55.2780000z' and endtime eq '2023-01-31t15:58:55.2780000z' ActivityId: c6a9ae91-a912-11ed-b4cf-5414f357addb, Microsoft.Azure.Documents.Common/2.14.0