...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-06-15/documentdb/percentile.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-06-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  // PercentileClient is the client for the Percentile methods of the Documentdb service.
    19  type PercentileClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPercentileClient creates an instance of the PercentileClient client.
    24  func NewPercentileClient(subscriptionID string) PercentileClient {
    25  	return NewPercentileClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewPercentileClientWithBaseURI creates an instance of the PercentileClient client using a custom endpoint.  Use this
    29  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewPercentileClientWithBaseURI(baseURI string, subscriptionID string) PercentileClient {
    31  	return PercentileClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // ListMetrics retrieves the metrics determined by the given filter for the given database account. This url is only
    35  // for PBS and Replication Latency data
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // accountName - cosmos DB database account name.
    39  // filter - an OData filter expression that describes a subset of metrics to return. The parameters that can be
    40  // filtered are name.value (name of the metric, can have an or of multiple names), startTime, endTime, and
    41  // timeGrain. The supported operator is eq.
    42  func (client PercentileClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, filter string) (result PercentileMetricListResult, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/PercentileClient.ListMetrics")
    45  		defer func() {
    46  			sc := -1
    47  			if result.Response.Response != nil {
    48  				sc = result.Response.Response.StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	if err := validation.Validate([]validation.Validation{
    54  		{TargetValue: client.SubscriptionID,
    55  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    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  		{TargetValue: accountName,
    60  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    61  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
    62  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
    63  		return result, validation.NewError("documentdb.PercentileClient", "ListMetrics", err.Error())
    64  	}
    65  
    66  	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, filter)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "documentdb.PercentileClient", "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.PercentileClient", "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.PercentileClient", "ListMetrics", resp, "Failure responding to request")
    82  		return
    83  	}
    84  
    85  	return
    86  }
    87  
    88  // ListMetricsPreparer prepares the ListMetrics request.
    89  func (client PercentileClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, filter string) (*http.Request, error) {
    90  	pathParameters := map[string]interface{}{
    91  		"accountName":       autorest.Encode("path", accountName),
    92  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    93  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    94  	}
    95  
    96  	const APIVersion = "2021-06-15"
    97  	queryParameters := map[string]interface{}{
    98  		"$filter":     autorest.Encode("query", filter),
    99  		"api-version": APIVersion,
   100  	}
   101  
   102  	preparer := autorest.CreatePreparer(
   103  		autorest.AsGet(),
   104  		autorest.WithBaseURL(client.BaseURI),
   105  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/percentile/metrics", pathParameters),
   106  		autorest.WithQueryParameters(queryParameters))
   107  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   108  }
   109  
   110  // ListMetricsSender sends the ListMetrics request. The method will close the
   111  // http.Response Body if it receives an error.
   112  func (client PercentileClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
   113  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   114  }
   115  
   116  // ListMetricsResponder handles the response to the ListMetrics request. The method always
   117  // closes the http.Response Body.
   118  func (client PercentileClient) ListMetricsResponder(resp *http.Response) (result PercentileMetricListResult, err error) {
   119  	err = autorest.Respond(
   120  		resp,
   121  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   122  		autorest.ByUnmarshallingJSON(&result),
   123  		autorest.ByClosing())
   124  	result.Response = autorest.Response{Response: resp}
   125  	return
   126  }
   127  

View as plain text