...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-04-01-preview/documentdb/partitionkeyrangeid.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-04-01-preview/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  // PartitionKeyRangeIDClient is the client for the PartitionKeyRangeID methods of the Documentdb service.
    19  type PartitionKeyRangeIDClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPartitionKeyRangeIDClient creates an instance of the PartitionKeyRangeIDClient client.
    24  func NewPartitionKeyRangeIDClient(subscriptionID string) PartitionKeyRangeIDClient {
    25  	return NewPartitionKeyRangeIDClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewPartitionKeyRangeIDClientWithBaseURI creates an instance of the PartitionKeyRangeIDClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewPartitionKeyRangeIDClientWithBaseURI(baseURI string, subscriptionID string) PartitionKeyRangeIDClient {
    32  	return PartitionKeyRangeIDClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // ListMetrics retrieves the metrics determined by the given filter for the given partition key range id.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // accountName - cosmos DB database account name.
    39  // databaseRid - cosmos DB database rid.
    40  // collectionRid - cosmos DB collection rid.
    41  // partitionKeyRangeID - partition Key Range Id for which to get data.
    42  // filter - an OData filter expression that describes a subset of metrics to return. The parameters that can be
    43  // filtered are name.value (name of the metric, can have an or of multiple names), startTime, endTime, and
    44  // timeGrain. The supported operator is eq.
    45  func (client PartitionKeyRangeIDClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string, partitionKeyRangeID string, filter string) (result PartitionMetricListResult, err error) {
    46  	if tracing.IsEnabled() {
    47  		ctx = tracing.StartSpan(ctx, fqdn+"/PartitionKeyRangeIDClient.ListMetrics")
    48  		defer func() {
    49  			sc := -1
    50  			if result.Response.Response != nil {
    51  				sc = result.Response.Response.StatusCode
    52  			}
    53  			tracing.EndSpan(ctx, sc, err)
    54  		}()
    55  	}
    56  	if err := validation.Validate([]validation.Validation{
    57  		{TargetValue: client.SubscriptionID,
    58  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    59  		{TargetValue: resourceGroupName,
    60  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    61  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
    62  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, 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.PartitionKeyRangeIDClient", "ListMetrics", err.Error())
    68  	}
    69  
    70  	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, databaseRid, collectionRid, partitionKeyRangeID, filter)
    71  	if err != nil {
    72  		err = autorest.NewErrorWithError(err, "documentdb.PartitionKeyRangeIDClient", "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.PartitionKeyRangeIDClient", "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.PartitionKeyRangeIDClient", "ListMetrics", resp, "Failure responding to request")
    86  		return
    87  	}
    88  
    89  	return
    90  }
    91  
    92  // ListMetricsPreparer prepares the ListMetrics request.
    93  func (client PartitionKeyRangeIDClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName 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  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
   100  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
   101  	}
   102  
   103  	const APIVersion = "2021-04-01-preview"
   104  	queryParameters := map[string]interface{}{
   105  		"$filter":     autorest.Encode("query", filter),
   106  		"api-version": APIVersion,
   107  	}
   108  
   109  	preparer := autorest.CreatePreparer(
   110  		autorest.AsGet(),
   111  		autorest.WithBaseURL(client.BaseURI),
   112  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/databases/{databaseRid}/collections/{collectionRid}/partitionKeyRangeId/{partitionKeyRangeId}/metrics", pathParameters),
   113  		autorest.WithQueryParameters(queryParameters))
   114  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   115  }
   116  
   117  // ListMetricsSender sends the ListMetrics request. The method will close the
   118  // http.Response Body if it receives an error.
   119  func (client PartitionKeyRangeIDClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
   120  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   121  }
   122  
   123  // ListMetricsResponder handles the response to the ListMetrics request. The method always
   124  // closes the http.Response Body.
   125  func (client PartitionKeyRangeIDClient) ListMetricsResponder(resp *http.Response) (result PartitionMetricListResult, err error) {
   126  	err = autorest.Respond(
   127  		resp,
   128  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   129  		autorest.ByUnmarshallingJSON(&result),
   130  		autorest.ByClosing())
   131  	result.Response = autorest.Response{Response: resp}
   132  	return
   133  }
   134  

View as plain text