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