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 DefinitionsClient struct {
20 BaseClient
21 }
22
23
24 func NewDefinitionsClient(subscriptionID string) DefinitionsClient {
25 return NewDefinitionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewDefinitionsClientWithBaseURI(baseURI string, subscriptionID string) DefinitionsClient {
31 return DefinitionsClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38 func (client DefinitionsClient) List(ctx context.Context, resourceURI string, metricnamespace string) (result DefinitionCollection, err error) {
39 if tracing.IsEnabled() {
40 ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionsClient.List")
41 defer func() {
42 sc := -1
43 if result.Response.Response != nil {
44 sc = result.Response.Response.StatusCode
45 }
46 tracing.EndSpan(ctx, sc, err)
47 }()
48 }
49 req, err := client.ListPreparer(ctx, resourceURI, metricnamespace)
50 if err != nil {
51 err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "List", nil, "Failure preparing request")
52 return
53 }
54
55 resp, err := client.ListSender(req)
56 if err != nil {
57 result.Response = autorest.Response{Response: resp}
58 err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "List", resp, "Failure sending request")
59 return
60 }
61
62 result, err = client.ListResponder(resp)
63 if err != nil {
64 err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "List", resp, "Failure responding to request")
65 return
66 }
67
68 return
69 }
70
71
72 func (client DefinitionsClient) ListPreparer(ctx context.Context, resourceURI string, metricnamespace string) (*http.Request, error) {
73 pathParameters := map[string]interface{}{
74 "resourceUri": resourceURI,
75 }
76
77 const APIVersion = "2021-05-01"
78 queryParameters := map[string]interface{}{
79 "api-version": APIVersion,
80 }
81 if len(metricnamespace) > 0 {
82 queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
83 }
84
85 preparer := autorest.CreatePreparer(
86 autorest.AsGet(),
87 autorest.WithBaseURL(client.BaseURI),
88 autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/metricDefinitions", pathParameters),
89 autorest.WithQueryParameters(queryParameters))
90 return preparer.Prepare((&http.Request{}).WithContext(ctx))
91 }
92
93
94
95 func (client DefinitionsClient) ListSender(req *http.Request) (*http.Response, error) {
96 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
97 }
98
99
100
101 func (client DefinitionsClient) ListResponder(resp *http.Response) (result DefinitionCollection, err error) {
102 err = autorest.Respond(
103 resp,
104 azure.WithErrorUnlessStatusCode(http.StatusOK),
105 autorest.ByUnmarshallingJSON(&result),
106 autorest.ByClosing())
107 result.Response = autorest.Response{Response: resp}
108 return
109 }
110
111
112
113
114
115 func (client DefinitionsClient) ListAtSubscriptionScope(ctx context.Context, region string, metricnamespace string) (result SubscriptionScopeMetricDefinitionCollection, err error) {
116 if tracing.IsEnabled() {
117 ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionsClient.ListAtSubscriptionScope")
118 defer func() {
119 sc := -1
120 if result.Response.Response != nil {
121 sc = result.Response.Response.StatusCode
122 }
123 tracing.EndSpan(ctx, sc, err)
124 }()
125 }
126 if err := validation.Validate([]validation.Validation{
127 {TargetValue: client.SubscriptionID,
128 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
129 return result, validation.NewError("metrics.DefinitionsClient", "ListAtSubscriptionScope", err.Error())
130 }
131
132 req, err := client.ListAtSubscriptionScopePreparer(ctx, region, metricnamespace)
133 if err != nil {
134 err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "ListAtSubscriptionScope", nil, "Failure preparing request")
135 return
136 }
137
138 resp, err := client.ListAtSubscriptionScopeSender(req)
139 if err != nil {
140 result.Response = autorest.Response{Response: resp}
141 err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "ListAtSubscriptionScope", resp, "Failure sending request")
142 return
143 }
144
145 result, err = client.ListAtSubscriptionScopeResponder(resp)
146 if err != nil {
147 err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "ListAtSubscriptionScope", resp, "Failure responding to request")
148 return
149 }
150
151 return
152 }
153
154
155 func (client DefinitionsClient) ListAtSubscriptionScopePreparer(ctx context.Context, region string, metricnamespace string) (*http.Request, error) {
156 pathParameters := map[string]interface{}{
157 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
158 }
159
160 const APIVersion = "2021-05-01"
161 queryParameters := map[string]interface{}{
162 "api-version": APIVersion,
163 "region": autorest.Encode("query", region),
164 }
165 if len(metricnamespace) > 0 {
166 queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
167 }
168
169 preparer := autorest.CreatePreparer(
170 autorest.AsGet(),
171 autorest.WithBaseURL(client.BaseURI),
172 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Insights/metricDefinitions", pathParameters),
173 autorest.WithQueryParameters(queryParameters))
174 return preparer.Prepare((&http.Request{}).WithContext(ctx))
175 }
176
177
178
179 func (client DefinitionsClient) ListAtSubscriptionScopeSender(req *http.Request) (*http.Response, error) {
180 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
181 }
182
183
184
185 func (client DefinitionsClient) ListAtSubscriptionScopeResponder(resp *http.Response) (result SubscriptionScopeMetricDefinitionCollection, err error) {
186 err = autorest.Respond(
187 resp,
188 azure.WithErrorUnlessStatusCode(http.StatusOK),
189 autorest.ByUnmarshallingJSON(&result),
190 autorest.ByClosing())
191 result.Response = autorest.Response{Response: resp}
192 return
193 }
194
View as plain text