1 package metrics
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 Client struct {
20 BaseClient
21 }
22
23
24 func NewClient(subscriptionID string) Client {
25 return NewClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewClientWithBaseURI(baseURI string, subscriptionID string) Client {
31 return Client{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 func (client Client) List(ctx context.Context, resourceURI string, timespan string, interval *string, metricnames string, aggregation string, top *int32, orderby string, filter string, resultType ResultType, metricnamespace string, autoAdjustTimegrain *bool, validateDimensions *bool) (result Response, err error) {
64 if tracing.IsEnabled() {
65 ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
66 defer func() {
67 sc := -1
68 if result.Response.Response != nil {
69 sc = result.Response.Response.StatusCode
70 }
71 tracing.EndSpan(ctx, sc, err)
72 }()
73 }
74 req, err := client.ListPreparer(ctx, resourceURI, timespan, interval, metricnames, aggregation, top, orderby, filter, resultType, metricnamespace, autoAdjustTimegrain, validateDimensions)
75 if err != nil {
76 err = autorest.NewErrorWithError(err, "metrics.Client", "List", nil, "Failure preparing request")
77 return
78 }
79
80 resp, err := client.ListSender(req)
81 if err != nil {
82 result.Response = autorest.Response{Response: resp}
83 err = autorest.NewErrorWithError(err, "metrics.Client", "List", resp, "Failure sending request")
84 return
85 }
86
87 result, err = client.ListResponder(resp)
88 if err != nil {
89 err = autorest.NewErrorWithError(err, "metrics.Client", "List", resp, "Failure responding to request")
90 return
91 }
92
93 return
94 }
95
96
97 func (client Client) ListPreparer(ctx context.Context, resourceURI string, timespan string, interval *string, metricnames string, aggregation string, top *int32, orderby string, filter string, resultType ResultType, metricnamespace string, autoAdjustTimegrain *bool, validateDimensions *bool) (*http.Request, error) {
98 pathParameters := map[string]interface{}{
99 "resourceUri": resourceURI,
100 }
101
102 const APIVersion = "2021-05-01"
103 queryParameters := map[string]interface{}{
104 "api-version": APIVersion,
105 }
106 if len(timespan) > 0 {
107 queryParameters["timespan"] = autorest.Encode("query", timespan)
108 }
109 if interval != nil {
110 queryParameters["interval"] = autorest.Encode("query", *interval)
111 }
112 if len(metricnames) > 0 {
113 queryParameters["metricnames"] = autorest.Encode("query", metricnames)
114 }
115 if len(aggregation) > 0 {
116 queryParameters["aggregation"] = autorest.Encode("query", aggregation)
117 }
118 if top != nil {
119 queryParameters["top"] = autorest.Encode("query", *top)
120 }
121 if len(orderby) > 0 {
122 queryParameters["orderby"] = autorest.Encode("query", orderby)
123 }
124 if len(filter) > 0 {
125 queryParameters["$filter"] = autorest.Encode("query", filter)
126 }
127 if len(string(resultType)) > 0 {
128 queryParameters["resultType"] = autorest.Encode("query", resultType)
129 }
130 if len(metricnamespace) > 0 {
131 queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
132 }
133 if autoAdjustTimegrain != nil {
134 queryParameters["AutoAdjustTimegrain"] = autorest.Encode("query", *autoAdjustTimegrain)
135 }
136 if validateDimensions != nil {
137 queryParameters["ValidateDimensions"] = autorest.Encode("query", *validateDimensions)
138 }
139
140 preparer := autorest.CreatePreparer(
141 autorest.AsGet(),
142 autorest.WithBaseURL(client.BaseURI),
143 autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/metrics", pathParameters),
144 autorest.WithQueryParameters(queryParameters))
145 return preparer.Prepare((&http.Request{}).WithContext(ctx))
146 }
147
148
149
150 func (client Client) ListSender(req *http.Request) (*http.Response, error) {
151 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
152 }
153
154
155
156 func (client Client) ListResponder(resp *http.Response) (result Response, err error) {
157 err = autorest.Respond(
158 resp,
159 azure.WithErrorUnlessStatusCode(http.StatusOK),
160 autorest.ByUnmarshallingJSON(&result),
161 autorest.ByClosing())
162 result.Response = autorest.Response{Response: resp}
163 return
164 }
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195 func (client Client) ListAtSubscriptionScope(ctx context.Context, region string, timespan string, interval *string, metricnames string, aggregation string, top *int32, orderby string, filter string, resultType MetricResultType, metricnamespace string, autoAdjustTimegrain *bool, validateDimensions *bool) (result SubscriptionScopeMetricResponse, err error) {
196 if tracing.IsEnabled() {
197 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListAtSubscriptionScope")
198 defer func() {
199 sc := -1
200 if result.Response.Response != nil {
201 sc = result.Response.Response.StatusCode
202 }
203 tracing.EndSpan(ctx, sc, err)
204 }()
205 }
206 if err := validation.Validate([]validation.Validation{
207 {TargetValue: client.SubscriptionID,
208 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
209 return result, validation.NewError("metrics.Client", "ListAtSubscriptionScope", err.Error())
210 }
211
212 req, err := client.ListAtSubscriptionScopePreparer(ctx, region, timespan, interval, metricnames, aggregation, top, orderby, filter, resultType, metricnamespace, autoAdjustTimegrain, validateDimensions)
213 if err != nil {
214 err = autorest.NewErrorWithError(err, "metrics.Client", "ListAtSubscriptionScope", nil, "Failure preparing request")
215 return
216 }
217
218 resp, err := client.ListAtSubscriptionScopeSender(req)
219 if err != nil {
220 result.Response = autorest.Response{Response: resp}
221 err = autorest.NewErrorWithError(err, "metrics.Client", "ListAtSubscriptionScope", resp, "Failure sending request")
222 return
223 }
224
225 result, err = client.ListAtSubscriptionScopeResponder(resp)
226 if err != nil {
227 err = autorest.NewErrorWithError(err, "metrics.Client", "ListAtSubscriptionScope", resp, "Failure responding to request")
228 return
229 }
230
231 return
232 }
233
234
235 func (client Client) ListAtSubscriptionScopePreparer(ctx context.Context, region string, timespan string, interval *string, metricnames string, aggregation string, top *int32, orderby string, filter string, resultType MetricResultType, metricnamespace string, autoAdjustTimegrain *bool, validateDimensions *bool) (*http.Request, error) {
236 pathParameters := map[string]interface{}{
237 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
238 }
239
240 const APIVersion = "2021-05-01"
241 queryParameters := map[string]interface{}{
242 "api-version": APIVersion,
243 "region": autorest.Encode("query", region),
244 }
245 if len(timespan) > 0 {
246 queryParameters["timespan"] = autorest.Encode("query", timespan)
247 }
248 if interval != nil {
249 queryParameters["interval"] = autorest.Encode("query", *interval)
250 }
251 if len(metricnames) > 0 {
252 queryParameters["metricnames"] = autorest.Encode("query", metricnames)
253 }
254 if len(aggregation) > 0 {
255 queryParameters["aggregation"] = autorest.Encode("query", aggregation)
256 }
257 if top != nil {
258 queryParameters["top"] = autorest.Encode("query", *top)
259 }
260 if len(orderby) > 0 {
261 queryParameters["orderby"] = autorest.Encode("query", orderby)
262 }
263 if len(filter) > 0 {
264 queryParameters["$filter"] = autorest.Encode("query", filter)
265 }
266 if len(string(resultType)) > 0 {
267 queryParameters["resultType"] = autorest.Encode("query", resultType)
268 }
269 if len(metricnamespace) > 0 {
270 queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
271 }
272 if autoAdjustTimegrain != nil {
273 queryParameters["AutoAdjustTimegrain"] = autorest.Encode("query", *autoAdjustTimegrain)
274 }
275 if validateDimensions != nil {
276 queryParameters["ValidateDimensions"] = autorest.Encode("query", *validateDimensions)
277 }
278
279 preparer := autorest.CreatePreparer(
280 autorest.AsGet(),
281 autorest.WithBaseURL(client.BaseURI),
282 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Insights/metrics", pathParameters),
283 autorest.WithQueryParameters(queryParameters))
284 return preparer.Prepare((&http.Request{}).WithContext(ctx))
285 }
286
287
288
289 func (client Client) ListAtSubscriptionScopeSender(req *http.Request) (*http.Response, error) {
290 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
291 }
292
293
294
295 func (client Client) ListAtSubscriptionScopeResponder(resp *http.Response) (result SubscriptionScopeMetricResponse, err error) {
296 err = autorest.Respond(
297 resp,
298 azure.WithErrorUnlessStatusCode(http.StatusOK),
299 autorest.ByUnmarshallingJSON(&result),
300 autorest.ByClosing())
301 result.Response = autorest.Response{Response: resp}
302 return
303 }
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336 func (client Client) ListAtSubscriptionScopePost(ctx context.Context, region string, timespan string, interval *string, metricnames string, aggregation string, top *int32, orderby string, filter string, resultType MetricResultType, metricnamespace string, autoAdjustTimegrain *bool, validateDimensions *bool, body *SubscriptionScopeMetricsRequestBodyParameters) (result SubscriptionScopeMetricResponse, err error) {
337 if tracing.IsEnabled() {
338 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListAtSubscriptionScopePost")
339 defer func() {
340 sc := -1
341 if result.Response.Response != nil {
342 sc = result.Response.Response.StatusCode
343 }
344 tracing.EndSpan(ctx, sc, err)
345 }()
346 }
347 if err := validation.Validate([]validation.Validation{
348 {TargetValue: client.SubscriptionID,
349 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
350 return result, validation.NewError("metrics.Client", "ListAtSubscriptionScopePost", err.Error())
351 }
352
353 req, err := client.ListAtSubscriptionScopePostPreparer(ctx, region, timespan, interval, metricnames, aggregation, top, orderby, filter, resultType, metricnamespace, autoAdjustTimegrain, validateDimensions, body)
354 if err != nil {
355 err = autorest.NewErrorWithError(err, "metrics.Client", "ListAtSubscriptionScopePost", nil, "Failure preparing request")
356 return
357 }
358
359 resp, err := client.ListAtSubscriptionScopePostSender(req)
360 if err != nil {
361 result.Response = autorest.Response{Response: resp}
362 err = autorest.NewErrorWithError(err, "metrics.Client", "ListAtSubscriptionScopePost", resp, "Failure sending request")
363 return
364 }
365
366 result, err = client.ListAtSubscriptionScopePostResponder(resp)
367 if err != nil {
368 err = autorest.NewErrorWithError(err, "metrics.Client", "ListAtSubscriptionScopePost", resp, "Failure responding to request")
369 return
370 }
371
372 return
373 }
374
375
376 func (client Client) ListAtSubscriptionScopePostPreparer(ctx context.Context, region string, timespan string, interval *string, metricnames string, aggregation string, top *int32, orderby string, filter string, resultType MetricResultType, metricnamespace string, autoAdjustTimegrain *bool, validateDimensions *bool, body *SubscriptionScopeMetricsRequestBodyParameters) (*http.Request, error) {
377 pathParameters := map[string]interface{}{
378 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
379 }
380
381 const APIVersion = "2021-05-01"
382 queryParameters := map[string]interface{}{
383 "api-version": APIVersion,
384 "region": autorest.Encode("query", region),
385 }
386 if len(timespan) > 0 {
387 queryParameters["timespan"] = autorest.Encode("query", timespan)
388 }
389 if interval != nil {
390 queryParameters["interval"] = autorest.Encode("query", *interval)
391 }
392 if len(metricnames) > 0 {
393 queryParameters["metricnames"] = autorest.Encode("query", metricnames)
394 }
395 if len(aggregation) > 0 {
396 queryParameters["aggregation"] = autorest.Encode("query", aggregation)
397 }
398 if top != nil {
399 queryParameters["top"] = autorest.Encode("query", *top)
400 }
401 if len(orderby) > 0 {
402 queryParameters["orderby"] = autorest.Encode("query", orderby)
403 }
404 if len(filter) > 0 {
405 queryParameters["$filter"] = autorest.Encode("query", filter)
406 }
407 if len(string(resultType)) > 0 {
408 queryParameters["resultType"] = autorest.Encode("query", resultType)
409 }
410 if len(metricnamespace) > 0 {
411 queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
412 }
413 if autoAdjustTimegrain != nil {
414 queryParameters["AutoAdjustTimegrain"] = autorest.Encode("query", *autoAdjustTimegrain)
415 }
416 if validateDimensions != nil {
417 queryParameters["ValidateDimensions"] = autorest.Encode("query", *validateDimensions)
418 }
419
420 preparer := autorest.CreatePreparer(
421 autorest.AsContentType("application/json; charset=utf-8"),
422 autorest.AsPost(),
423 autorest.WithBaseURL(client.BaseURI),
424 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Insights/metrics", pathParameters),
425 autorest.WithQueryParameters(queryParameters))
426 if body != nil {
427 preparer = autorest.DecoratePreparer(preparer,
428 autorest.WithJSON(body))
429 }
430 return preparer.Prepare((&http.Request{}).WithContext(ctx))
431 }
432
433
434
435 func (client Client) ListAtSubscriptionScopePostSender(req *http.Request) (*http.Response, error) {
436 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
437 }
438
439
440
441 func (client Client) ListAtSubscriptionScopePostResponder(resp *http.Response) (result SubscriptionScopeMetricResponse, err error) {
442 err = autorest.Respond(
443 resp,
444 azure.WithErrorUnlessStatusCode(http.StatusOK),
445 autorest.ByUnmarshallingJSON(&result),
446 autorest.ByClosing())
447 result.Response = autorest.Response{Response: resp}
448 return
449 }
450
View as plain text