1package documentdb 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "net/http" 26) 27 28// PartitionKeyRangeIDRegionClient is the azure Cosmos DB Database Service Resource Provider REST API 29type PartitionKeyRangeIDRegionClient struct { 30 BaseClient 31} 32 33// NewPartitionKeyRangeIDRegionClient creates an instance of the PartitionKeyRangeIDRegionClient client. 34func NewPartitionKeyRangeIDRegionClient(subscriptionID string) PartitionKeyRangeIDRegionClient { 35 return NewPartitionKeyRangeIDRegionClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewPartitionKeyRangeIDRegionClientWithBaseURI creates an instance of the PartitionKeyRangeIDRegionClient client. 39func NewPartitionKeyRangeIDRegionClientWithBaseURI(baseURI string, subscriptionID string) PartitionKeyRangeIDRegionClient { 40 return PartitionKeyRangeIDRegionClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// ListMetrics retrieves the metrics determined by the given filter for the given partition key range id and region. 44// Parameters: 45// resourceGroupName - name of an Azure resource group. 46// accountName - cosmos DB database account name. 47// region - cosmos DB region, with spaces between words and each word capitalized. 48// databaseRid - cosmos DB database rid. 49// collectionRid - cosmos DB collection rid. 50// partitionKeyRangeID - partition Key Range Id for which to get data. 51// filter - an OData filter expression that describes a subset of metrics to return. The parameters that can be 52// filtered are name.value (name of the metric, can have an or of multiple names), startTime, endTime, and 53// timeGrain. The supported operator is eq. 54func (client PartitionKeyRangeIDRegionClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, region string, databaseRid string, collectionRid string, partitionKeyRangeID string, filter string) (result PartitionMetricListResult, err error) { 55 if err := validation.Validate([]validation.Validation{ 56 {TargetValue: resourceGroupName, 57 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 58 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 59 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 60 {TargetValue: accountName, 61 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 62 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { 63 return result, validation.NewError("documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", err.Error()) 64 } 65 66 req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, region, databaseRid, collectionRid, partitionKeyRangeID, filter) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", nil, "Failure preparing request") 69 return 70 } 71 72 resp, err := client.ListMetricsSender(req) 73 if err != nil { 74 result.Response = autorest.Response{Response: resp} 75 err = autorest.NewErrorWithError(err, "documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", resp, "Failure sending request") 76 return 77 } 78 79 result, err = client.ListMetricsResponder(resp) 80 if err != nil { 81 err = autorest.NewErrorWithError(err, "documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", resp, "Failure responding to request") 82 } 83 84 return 85} 86 87// ListMetricsPreparer prepares the ListMetrics request. 88func (client PartitionKeyRangeIDRegionClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, region string, databaseRid string, collectionRid string, partitionKeyRangeID string, filter string) (*http.Request, error) { 89 pathParameters := map[string]interface{}{ 90 "accountName": autorest.Encode("path", accountName), 91 "collectionRid": autorest.Encode("path", collectionRid), 92 "databaseRid": autorest.Encode("path", databaseRid), 93 "partitionKeyRangeId": autorest.Encode("path", partitionKeyRangeID), 94 "region": autorest.Encode("path", region), 95 "resourceGroupName": autorest.Encode("path", resourceGroupName), 96 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 97 } 98 99 const APIVersion = "2015-04-08" 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}/databases/{databaseRid}/collections/{collectionRid}/partitionKeyRangeId/{partitionKeyRangeId}/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 PartitionKeyRangeIDRegionClient) ListMetricsSender(req *http.Request) (*http.Response, error) { 116 return autorest.SendWithSender(client, req, 117 azure.DoRetryWithRegistration(client.Client)) 118} 119 120// ListMetricsResponder handles the response to the ListMetrics request. The method always 121// closes the http.Response Body. 122func (client PartitionKeyRangeIDRegionClient) ListMetricsResponder(resp *http.Response) (result PartitionMetricListResult, err error) { 123 err = autorest.Respond( 124 resp, 125 client.ByInspecting(), 126 azure.WithErrorUnlessStatusCode(http.StatusOK), 127 autorest.ByUnmarshallingJSON(&result), 128 autorest.ByClosing()) 129 result.Response = autorest.Response{Response: resp} 130 return 131} 132