...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2022-05-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  // DatabaseAccountRegionClient is the client for the DatabaseAccountRegion methods of the Documentdb service.
    19  type DatabaseAccountRegionClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewDatabaseAccountRegionClient creates an instance of the DatabaseAccountRegionClient client.
    24  func 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).
    31  func 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 - 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  // 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.
    43  func (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  		{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},
    63  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
    64  		return result, validation.NewError("documentdb.DatabaseAccountRegionClient", "ListMetrics", err.Error())
    65  	}
    66  
    67  	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, region, filter)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseAccountRegionClient", "ListMetrics", nil, "Failure preparing request")
    70  		return
    71  	}
    72  
    73  	resp, err := client.ListMetricsSender(req)
    74  	if err != nil {
    75  		result.Response = autorest.Response{Response: resp}
    76  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseAccountRegionClient", "ListMetrics", resp, "Failure sending request")
    77  		return
    78  	}
    79  
    80  	result, err = client.ListMetricsResponder(resp)
    81  	if err != nil {
    82  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseAccountRegionClient", "ListMetrics", resp, "Failure responding to request")
    83  		return
    84  	}
    85  
    86  	return
    87  }
    88  
    89  // ListMetricsPreparer prepares the ListMetrics request.
    90  func (client DatabaseAccountRegionClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, region string, filter string) (*http.Request, error) {
    91  	pathParameters := map[string]interface{}{
    92  		"accountName":       autorest.Encode("path", accountName),
    93  		"region":            autorest.Encode("path", region),
    94  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    95  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    96  	}
    97  
    98  	const APIVersion = "2022-05-15"
    99  	queryParameters := map[string]interface{}{
   100  		"$filter":     autorest.Encode("query", filter),
   101  		"api-version": APIVersion,
   102  	}
   103  
   104  	preparer := autorest.CreatePreparer(
   105  		autorest.AsGet(),
   106  		autorest.WithBaseURL(client.BaseURI),
   107  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/region/{region}/metrics", pathParameters),
   108  		autorest.WithQueryParameters(queryParameters))
   109  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   110  }
   111  
   112  // ListMetricsSender sends the ListMetrics request. The method will close the
   113  // http.Response Body if it receives an error.
   114  func (client DatabaseAccountRegionClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
   115  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   116  }
   117  
   118  // ListMetricsResponder handles the response to the ListMetrics request. The method always
   119  // closes the http.Response Body.
   120  func (client DatabaseAccountRegionClient) ListMetricsResponder(resp *http.Response) (result MetricListResult, err error) {
   121  	err = autorest.Respond(
   122  		resp,
   123  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   124  		autorest.ByUnmarshallingJSON(&result),
   125  		autorest.ByClosing())
   126  	result.Response = autorest.Response{Response: resp}
   127  	return
   128  }
   129  

View as plain text