1 package insights
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, aggregation string, timespan string, interval *string, metricnamespace string, metricnames 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("insights.PredictiveMetricClient", "Get", err.Error())
64 }
65
66 req, err := client.GetPreparer(ctx, resourceGroupName, autoscaleSettingName, aggregation, timespan, interval, metricnamespace, metricnames)
67 if err != nil {
68 err = autorest.NewErrorWithError(err, "insights.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, "insights.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, "insights.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, aggregation string, timespan string, interval *string, metricnamespace string, metricnames 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 = "2022-10-01"
97 queryParameters := map[string]interface{}{
98 "aggregation": autorest.Encode("query", aggregation),
99 "api-version": APIVersion,
100 }
101 if len(timespan) > 0 {
102 queryParameters["timespan"] = autorest.Encode("query", timespan)
103 }
104 if interval != nil {
105 queryParameters["interval"] = autorest.Encode("query", *interval)
106 }
107 if len(metricnamespace) > 0 {
108 queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
109 }
110 if len(metricnames) > 0 {
111 queryParameters["metricnames"] = autorest.Encode("query", metricnames)
112 }
113
114 preparer := autorest.CreatePreparer(
115 autorest.AsGet(),
116 autorest.WithBaseURL(client.BaseURI),
117 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Insights/autoscalesettings/{autoscaleSettingName}/predictiveMetrics", pathParameters),
118 autorest.WithQueryParameters(queryParameters))
119 return preparer.Prepare((&http.Request{}).WithContext(ctx))
120 }
121
122
123
124 func (client PredictiveMetricClient) GetSender(req *http.Request) (*http.Response, error) {
125 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
126 }
127
128
129
130 func (client PredictiveMetricClient) GetResponder(resp *http.Response) (result PredictiveResponse, err error) {
131 err = autorest.Respond(
132 resp,
133 azure.WithErrorUnlessStatusCode(http.StatusOK),
134 autorest.ByUnmarshallingJSON(&result),
135 autorest.ByClosing())
136 result.Response = autorest.Response{Response: resp}
137 return
138 }
139
View as plain text