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 MetricsClient struct {
20 BaseClient
21 }
22
23
24 func NewMetricsClient(subscriptionID string) MetricsClient {
25 return NewMetricsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewMetricsClientWithBaseURI(baseURI string, subscriptionID string) MetricsClient {
31 return MetricsClient{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 func (client MetricsClient) List(ctx context.Context, resourceURI string, timespan string, interval *string, metricnames string, aggregation string, top *int32, orderby string, filter string, resultType ResultType, metricnamespace string) (result Response, err error) {
63 if tracing.IsEnabled() {
64 ctx = tracing.StartSpan(ctx, fqdn+"/MetricsClient.List")
65 defer func() {
66 sc := -1
67 if result.Response.Response != nil {
68 sc = result.Response.Response.StatusCode
69 }
70 tracing.EndSpan(ctx, sc, err)
71 }()
72 }
73 if err := validation.Validate([]validation.Validation{
74 {TargetValue: resourceURI,
75 Constraints: []validation.Constraint{{Target: "resourceURI", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
76 return result, validation.NewError("insights.MetricsClient", "List", err.Error())
77 }
78
79 req, err := client.ListPreparer(ctx, resourceURI, timespan, interval, metricnames, aggregation, top, orderby, filter, resultType, metricnamespace)
80 if err != nil {
81 err = autorest.NewErrorWithError(err, "insights.MetricsClient", "List", nil, "Failure preparing request")
82 return
83 }
84
85 resp, err := client.ListSender(req)
86 if err != nil {
87 result.Response = autorest.Response{Response: resp}
88 err = autorest.NewErrorWithError(err, "insights.MetricsClient", "List", resp, "Failure sending request")
89 return
90 }
91
92 result, err = client.ListResponder(resp)
93 if err != nil {
94 err = autorest.NewErrorWithError(err, "insights.MetricsClient", "List", resp, "Failure responding to request")
95 return
96 }
97
98 return
99 }
100
101
102 func (client MetricsClient) ListPreparer(ctx context.Context, resourceURI string, timespan string, interval *string, metricnames string, aggregation string, top *int32, orderby string, filter string, resultType ResultType, metricnamespace string) (*http.Request, error) {
103 pathParameters := map[string]interface{}{
104 "resourceUri": resourceURI,
105 }
106
107 const APIVersion = "2018-01-01"
108 queryParameters := map[string]interface{}{
109 "api-version": APIVersion,
110 }
111 if len(timespan) > 0 {
112 queryParameters["timespan"] = autorest.Encode("query", timespan)
113 }
114 if interval != nil {
115 queryParameters["interval"] = autorest.Encode("query", *interval)
116 }
117 if len(metricnames) > 0 {
118 queryParameters["metricnames"] = autorest.Encode("query", metricnames)
119 }
120 if len(aggregation) > 0 {
121 queryParameters["aggregation"] = autorest.Encode("query", aggregation)
122 }
123 if top != nil {
124 queryParameters["top"] = autorest.Encode("query", *top)
125 }
126 if len(orderby) > 0 {
127 queryParameters["orderby"] = autorest.Encode("query", orderby)
128 }
129 if len(filter) > 0 {
130 queryParameters["$filter"] = autorest.Encode("query", filter)
131 }
132 if len(string(resultType)) > 0 {
133 queryParameters["resultType"] = autorest.Encode("query", resultType)
134 }
135 if len(metricnamespace) > 0 {
136 queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
137 }
138
139 preparer := autorest.CreatePreparer(
140 autorest.AsGet(),
141 autorest.WithBaseURL(client.BaseURI),
142 autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/metrics", pathParameters),
143 autorest.WithQueryParameters(queryParameters))
144 return preparer.Prepare((&http.Request{}).WithContext(ctx))
145 }
146
147
148
149 func (client MetricsClient) ListSender(req *http.Request) (*http.Response, error) {
150 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
151 }
152
153
154
155 func (client MetricsClient) ListResponder(resp *http.Response) (result Response, err error) {
156 err = autorest.Respond(
157 resp,
158 azure.WithErrorUnlessStatusCode(http.StatusOK),
159 autorest.ByUnmarshallingJSON(&result),
160 autorest.ByClosing())
161 result.Response = autorest.Response{Response: resp}
162 return
163 }
164
View as plain text