1 package diagnostics
2
3
4
5
6
7
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
19 type PredictiveMetricClient struct {
20 BaseClient
21 }
22
23
24 func NewPredictiveMetricClient(subscriptionID string) PredictiveMetricClient {
25 return NewPredictiveMetricClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30
31 func NewPredictiveMetricClientWithBaseURI(baseURI string, subscriptionID string) PredictiveMetricClient {
32 return PredictiveMetricClient{NewWithBaseURI(baseURI, subscriptionID)}
33 }
34
35
36
37
38
39
40
41
42
43
44
45
46 func (client PredictiveMetricClient) Get(ctx context.Context, resourceGroupName string, autoscaleSettingName string, timespan string, interval string, metricNamespace string, metricName string, aggregation string) (result PredictiveResponse, err error) {
47 if tracing.IsEnabled() {
48 ctx = tracing.StartSpan(ctx, fqdn+"/PredictiveMetricClient.Get")
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}}}}); err != nil {
63 return result, validation.NewError("diagnostics.PredictiveMetricClient", "Get", err.Error())
64 }
65
66 req, err := client.GetPreparer(ctx, resourceGroupName, autoscaleSettingName, timespan, interval, metricNamespace, metricName, aggregation)
67 if err != nil {
68 err = autorest.NewErrorWithError(err, "diagnostics.PredictiveMetricClient", "Get", nil, "Failure preparing request")
69 return
70 }
71
72 resp, err := client.GetSender(req)
73 if err != nil {
74 result.Response = autorest.Response{Response: resp}
75 err = autorest.NewErrorWithError(err, "diagnostics.PredictiveMetricClient", "Get", resp, "Failure sending request")
76 return
77 }
78
79 result, err = client.GetResponder(resp)
80 if err != nil {
81 err = autorest.NewErrorWithError(err, "diagnostics.PredictiveMetricClient", "Get", resp, "Failure responding to request")
82 return
83 }
84
85 return
86 }
87
88
89 func (client PredictiveMetricClient) GetPreparer(ctx context.Context, resourceGroupName string, autoscaleSettingName string, timespan string, interval string, metricNamespace string, metricName string, aggregation string) (*http.Request, error) {
90 pathParameters := map[string]interface{}{
91 "autoscaleSettingName": autorest.Encode("path", autoscaleSettingName),
92 "resourceGroupName": autorest.Encode("path", resourceGroupName),
93 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
94 }
95
96 const APIVersion = "2021-05-01-preview"
97 queryParameters := map[string]interface{}{
98 "aggregation": autorest.Encode("query", aggregation),
99 "api-version": APIVersion,
100 "interval": autorest.Encode("query", interval),
101 "metricName": autorest.Encode("query", metricName),
102 "metricNamespace": autorest.Encode("query", metricNamespace),
103 "timespan": autorest.Encode("query", timespan),
104 }
105
106 preparer := autorest.CreatePreparer(
107 autorest.AsGet(),
108 autorest.WithBaseURL(client.BaseURI),
109 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Insights/autoscalesettings/{autoscaleSettingName}/predictiveMetrics", pathParameters),
110 autorest.WithQueryParameters(queryParameters))
111 return preparer.Prepare((&http.Request{}).WithContext(ctx))
112 }
113
114
115
116 func (client PredictiveMetricClient) GetSender(req *http.Request) (*http.Response, error) {
117 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
118 }
119
120
121
122 func (client PredictiveMetricClient) GetResponder(resp *http.Response) (result PredictiveResponse, err error) {
123 err = autorest.Respond(
124 resp,
125 azure.WithErrorUnlessStatusCode(http.StatusOK),
126 autorest.ByUnmarshallingJSON(&result),
127 autorest.ByClosing())
128 result.Response = autorest.Response{Response: resp}
129 return
130 }
131
View as plain text