1package 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
9import (
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 azure Cosmos DB Database Service Resource Provider REST API
19type PartitionKeyRangeIDRegionClient struct {
20	BaseClient
21}
22
23// NewPartitionKeyRangeIDRegionClient creates an instance of the PartitionKeyRangeIDRegionClient client.
24func 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).
31func 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.
46func (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				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
64		{TargetValue: accountName,
65			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
66				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
67				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
68		return result, validation.NewError("documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", err.Error())
69	}
70
71	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, region, databaseRid, collectionRid, partitionKeyRangeID, filter)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", nil, "Failure preparing request")
74		return
75	}
76
77	resp, err := client.ListMetricsSender(req)
78	if err != nil {
79		result.Response = autorest.Response{Response: resp}
80		err = autorest.NewErrorWithError(err, "documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", resp, "Failure sending request")
81		return
82	}
83
84	result, err = client.ListMetricsResponder(resp)
85	if err != nil {
86		err = autorest.NewErrorWithError(err, "documentdb.PartitionKeyRangeIDRegionClient", "ListMetrics", resp, "Failure responding to request")
87		return
88	}
89
90	return
91}
92
93// ListMetricsPreparer prepares the ListMetrics request.
94func (client PartitionKeyRangeIDRegionClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, region string, databaseRid string, collectionRid string, partitionKeyRangeID string, filter string) (*http.Request, error) {
95	pathParameters := map[string]interface{}{
96		"accountName":         autorest.Encode("path", accountName),
97		"collectionRid":       autorest.Encode("path", collectionRid),
98		"databaseRid":         autorest.Encode("path", databaseRid),
99		"partitionKeyRangeId": autorest.Encode("path", partitionKeyRangeID),
100		"region":              autorest.Encode("path", region),
101		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
102		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
103	}
104
105	const APIVersion = "2020-04-01"
106	queryParameters := map[string]interface{}{
107		"$filter":     autorest.Encode("query", filter),
108		"api-version": APIVersion,
109	}
110
111	preparer := autorest.CreatePreparer(
112		autorest.AsGet(),
113		autorest.WithBaseURL(client.BaseURI),
114		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/region/{region}/databases/{databaseRid}/collections/{collectionRid}/partitionKeyRangeId/{partitionKeyRangeId}/metrics", pathParameters),
115		autorest.WithQueryParameters(queryParameters))
116	return preparer.Prepare((&http.Request{}).WithContext(ctx))
117}
118
119// ListMetricsSender sends the ListMetrics request. The method will close the
120// http.Response Body if it receives an error.
121func (client PartitionKeyRangeIDRegionClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
122	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
123}
124
125// ListMetricsResponder handles the response to the ListMetrics request. The method always
126// closes the http.Response Body.
127func (client PartitionKeyRangeIDRegionClient) ListMetricsResponder(resp *http.Response) (result PartitionMetricListResult, err error) {
128	err = autorest.Respond(
129		resp,
130		azure.WithErrorUnlessStatusCode(http.StatusOK),
131		autorest.ByUnmarshallingJSON(&result),
132		autorest.ByClosing())
133	result.Response = autorest.Response{Response: resp}
134	return
135}
136