...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2022-08-15/documentdb/partitionkeyrangeidregion.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2022-08-15/documentdb

     1  package 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  
     9  import (
    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  // PartitionKeyRangeIDRegionClient is the client for the PartitionKeyRangeIDRegion methods of the Documentdb service.
    19  type PartitionKeyRangeIDRegionClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPartitionKeyRangeIDRegionClient creates an instance of the PartitionKeyRangeIDRegionClient client.
    24  func NewPartitionKeyRangeIDRegionClient(subscriptionID string) PartitionKeyRangeIDRegionClient {
    25  	return NewPartitionKeyRangeIDRegionClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewPartitionKeyRangeIDRegionClientWithBaseURI creates an instance of the PartitionKeyRangeIDRegionClient 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).
    31  func NewPartitionKeyRangeIDRegionClientWithBaseURI(baseURI string, subscriptionID string) PartitionKeyRangeIDRegionClient {
    32  	return PartitionKeyRangeIDRegionClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // ListMetrics retrieves the metrics determined by the given filter for the given partition key range id and region.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // accountName - cosmos DB database account name.
    39  // region - cosmos DB region, with spaces between words and each word capitalized.
    40  // databaseRid - cosmos DB database rid.
    41  // collectionRid - cosmos DB collection rid.
    42  // partitionKeyRangeID - partition Key Range Id for which to get data.
    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.
    46  func (client PartitionKeyRangeIDRegionClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, region string, databaseRid string, collectionRid string, partitionKeyRangeID string, filter string) (result PartitionMetricListResult, err error) {
    47  	if tracing.IsEnabled() {
    48  		ctx = tracing.StartSpan(ctx, fqdn+"/PartitionKeyRangeIDRegionClient.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: client.SubscriptionID,
    59  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    60  		{TargetValue: resourceGroupName,
    61  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    62  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    63  		{TargetValue: accountName,
    64  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    65  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
    66  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
    67  		return result, validation.NewError("documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", err.Error())
    68  	}
    69  
    70  	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, region, databaseRid, collectionRid, partitionKeyRangeID, filter)
    71  	if err != nil {
    72  		err = autorest.NewErrorWithError(err, "documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", nil, "Failure preparing request")
    73  		return
    74  	}
    75  
    76  	resp, err := client.ListMetricsSender(req)
    77  	if err != nil {
    78  		result.Response = autorest.Response{Response: resp}
    79  		err = autorest.NewErrorWithError(err, "documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", resp, "Failure sending request")
    80  		return
    81  	}
    82  
    83  	result, err = client.ListMetricsResponder(resp)
    84  	if err != nil {
    85  		err = autorest.NewErrorWithError(err, "documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", resp, "Failure responding to request")
    86  		return
    87  	}
    88  
    89  	return
    90  }
    91  
    92  // ListMetricsPreparer prepares the ListMetrics request.
    93  func (client PartitionKeyRangeIDRegionClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, region string, databaseRid string, collectionRid string, partitionKeyRangeID string, filter string) (*http.Request, error) {
    94  	pathParameters := map[string]interface{}{
    95  		"accountName":         autorest.Encode("path", accountName),
    96  		"collectionRid":       autorest.Encode("path", collectionRid),
    97  		"databaseRid":         autorest.Encode("path", databaseRid),
    98  		"partitionKeyRangeId": autorest.Encode("path", partitionKeyRangeID),
    99  		"region":              autorest.Encode("path", region),
   100  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
   101  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
   102  	}
   103  
   104  	const APIVersion = "2022-08-15"
   105  	queryParameters := map[string]interface{}{
   106  		"$filter":     autorest.Encode("query", filter),
   107  		"api-version": APIVersion,
   108  	}
   109  
   110  	preparer := autorest.CreatePreparer(
   111  		autorest.AsGet(),
   112  		autorest.WithBaseURL(client.BaseURI),
   113  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/region/{region}/databases/{databaseRid}/collections/{collectionRid}/partitionKeyRangeId/{partitionKeyRangeId}/metrics", pathParameters),
   114  		autorest.WithQueryParameters(queryParameters))
   115  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   116  }
   117  
   118  // ListMetricsSender sends the ListMetrics request. The method will close the
   119  // http.Response Body if it receives an error.
   120  func (client PartitionKeyRangeIDRegionClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
   121  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   122  }
   123  
   124  // ListMetricsResponder handles the response to the ListMetrics request. The method always
   125  // closes the http.Response Body.
   126  func (client PartitionKeyRangeIDRegionClient) ListMetricsResponder(resp *http.Response) (result PartitionMetricListResult, err error) {
   127  	err = autorest.Respond(
   128  		resp,
   129  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   130  		autorest.ByUnmarshallingJSON(&result),
   131  		autorest.ByClosing())
   132  	result.Response = autorest.Response{Response: resp}
   133  	return
   134  }
   135  

View as plain text