...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-04-01-preview/documentdb/percentile.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  // 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  				{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},
    63  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
    64  		return result, validation.NewError("documentdb.PercentileClient", "ListMetrics", err.Error())
    65  	}
    66  
    67  	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, filter)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "documentdb.PercentileClient", "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.PercentileClient", "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.PercentileClient", "ListMetrics", resp, "Failure responding to request")
    83  		return
    84  	}
    85  
    86  	return
    87  }
    88  
    89  // ListMetricsPreparer prepares the ListMetrics request.
    90  func (client PercentileClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, filter string) (*http.Request, error) {
    91  	pathParameters := map[string]interface{}{
    92  		"accountName":       autorest.Encode("path", accountName),
    93  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    94  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    95  	}
    96  
    97  	const APIVersion = "2021-04-01-preview"
    98  	queryParameters := map[string]interface{}{
    99  		"$filter":     autorest.Encode("query", filter),
   100  		"api-version": APIVersion,
   101  	}
   102  
   103  	preparer := autorest.CreatePreparer(
   104  		autorest.AsGet(),
   105  		autorest.WithBaseURL(client.BaseURI),
   106  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/percentile/metrics", pathParameters),
   107  		autorest.WithQueryParameters(queryParameters))
   108  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   109  }
   110  
   111  // ListMetricsSender sends the ListMetrics request. The method will close the
   112  // http.Response Body if it receives an error.
   113  func (client PercentileClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
   114  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   115  }
   116  
   117  // ListMetricsResponder handles the response to the ListMetrics request. The method always
   118  // closes the http.Response Body.
   119  func (client PercentileClient) ListMetricsResponder(resp *http.Response) (result PercentileMetricListResult, err error) {
   120  	err = autorest.Respond(
   121  		resp,
   122  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   123  		autorest.ByUnmarshallingJSON(&result),
   124  		autorest.ByClosing())
   125  	result.Response = autorest.Response{Response: resp}
   126  	return
   127  }
   128  

View as plain text