1package documentdb 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// CollectionPartitionRegionClient is the azure Cosmos DB Database Service Resource Provider REST API 19type CollectionPartitionRegionClient struct { 20 BaseClient 21} 22 23// NewCollectionPartitionRegionClient creates an instance of the CollectionPartitionRegionClient client. 24func NewCollectionPartitionRegionClient(subscriptionID string, subscriptionID1 string) CollectionPartitionRegionClient { 25 return NewCollectionPartitionRegionClientWithBaseURI(DefaultBaseURI, subscriptionID, subscriptionID1) 26} 27 28// NewCollectionPartitionRegionClientWithBaseURI creates an instance of the CollectionPartitionRegionClient client 29// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 30// clouds, Azure stack). 31func NewCollectionPartitionRegionClientWithBaseURI(baseURI string, subscriptionID string, subscriptionID1 string) CollectionPartitionRegionClient { 32 return CollectionPartitionRegionClient{NewWithBaseURI(baseURI, subscriptionID, subscriptionID1)} 33} 34 35// ListMetrics retrieves the metrics determined by the given filter for the given collection and region, split by 36// partition. 37// Parameters: 38// resourceGroupName - name of an Azure resource group. 39// accountName - cosmos DB database account name. 40// region - cosmos DB region, with spaces between words and each word capitalized. 41// databaseRid - cosmos DB database rid. 42// collectionRid - cosmos DB collection rid. 43// filter - an OData filter expression that describes a subset of metrics to return. The parameters that can be 44// filtered are name.value (name of the metric, can have an or of multiple names), startTime, endTime, and 45// timeGrain. The supported operator is eq. 46func (client CollectionPartitionRegionClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, region string, databaseRid string, collectionRid string, filter string) (result PartitionMetricListResult, err error) { 47 if tracing.IsEnabled() { 48 ctx = tracing.StartSpan(ctx, fqdn+"/CollectionPartitionRegionClient.ListMetrics") 49 defer func() { 50 sc := -1 51 if result.Response.Response != nil { 52 sc = result.Response.Response.StatusCode 53 } 54 tracing.EndSpan(ctx, sc, err) 55 }() 56 } 57 if err := validation.Validate([]validation.Validation{ 58 {TargetValue: resourceGroupName, 59 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 60 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 61 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 62 {TargetValue: accountName, 63 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 64 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 65 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil { 66 return result, validation.NewError("documentdb.CollectionPartitionRegionClient", "ListMetrics", err.Error()) 67 } 68 69 req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, region, databaseRid, collectionRid, filter) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionRegionClient", "ListMetrics", nil, "Failure preparing request") 72 return 73 } 74 75 resp, err := client.ListMetricsSender(req) 76 if err != nil { 77 result.Response = autorest.Response{Response: resp} 78 err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionRegionClient", "ListMetrics", resp, "Failure sending request") 79 return 80 } 81 82 result, err = client.ListMetricsResponder(resp) 83 if err != nil { 84 err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionRegionClient", "ListMetrics", resp, "Failure responding to request") 85 return 86 } 87 88 return 89} 90 91// ListMetricsPreparer prepares the ListMetrics request. 92func (client CollectionPartitionRegionClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, region string, databaseRid string, collectionRid string, filter string) (*http.Request, error) { 93 pathParameters := map[string]interface{}{ 94 "accountName": autorest.Encode("path", accountName), 95 "collectionRid": autorest.Encode("path", collectionRid), 96 "databaseRid": autorest.Encode("path", databaseRid), 97 "region": autorest.Encode("path", region), 98 "resourceGroupName": autorest.Encode("path", resourceGroupName), 99 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 100 } 101 102 const APIVersion = "2019-12-12" 103 queryParameters := map[string]interface{}{ 104 "$filter": autorest.Encode("query", filter), 105 "api-version": APIVersion, 106 } 107 108 preparer := autorest.CreatePreparer( 109 autorest.AsGet(), 110 autorest.WithBaseURL(client.BaseURI), 111 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/region/{region}/databases/{databaseRid}/collections/{collectionRid}/partitions/metrics", pathParameters), 112 autorest.WithQueryParameters(queryParameters)) 113 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 114} 115 116// ListMetricsSender sends the ListMetrics request. The method will close the 117// http.Response Body if it receives an error. 118func (client CollectionPartitionRegionClient) ListMetricsSender(req *http.Request) (*http.Response, error) { 119 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 120} 121 122// ListMetricsResponder handles the response to the ListMetrics request. The method always 123// closes the http.Response Body. 124func (client CollectionPartitionRegionClient) ListMetricsResponder(resp *http.Response) (result PartitionMetricListResult, err error) { 125 err = autorest.Respond( 126 resp, 127 azure.WithErrorUnlessStatusCode(http.StatusOK), 128 autorest.ByUnmarshallingJSON(&result), 129 autorest.ByClosing()) 130 result.Response = autorest.Response{Response: resp} 131 return 132} 133