diff --git a/sdk/monitor/azquery/assets.json b/sdk/monitor/azquery/assets.json index 5a6770d18f1d..fd1c49d37f59 100644 --- a/sdk/monitor/azquery/assets.json +++ b/sdk/monitor/azquery/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/monitor/azquery", - "Tag": "go/monitor/azquery_98fd781041" + "Tag": "go/monitor/azquery_123118d585" } diff --git a/sdk/monitor/azquery/autorest.md b/sdk/monitor/azquery/autorest.md index 95cfa50a0534..1de0bc8285d7 100644 --- a/sdk/monitor/azquery/autorest.md +++ b/sdk/monitor/azquery/autorest.md @@ -250,4 +250,15 @@ directive: transform: return $.replace(/Timespan \*string/g, "Timespan *TimeInterval"); - from: metrics_client.go where: $ - transform: return $.replace(/reqQP\.Set\(\"timespan\", \*options\.Timespan\)/g, "reqQP.Set(\"timespan\", string(*options.Timespan))"); \ No newline at end of file + transform: return $.replace(/reqQP\.Set\(\"timespan\", \*options\.Timespan\)/g, "reqQP.Set(\"timespan\", string(*options.Timespan))"); + + # change type of MetricsClientQueryResourceOptions.Aggregation from *string to []*AggregationType + - from: models.go + where: $ + transform: return $.replace(/Aggregation \*string/g, "Aggregation []*AggregationType"); + - from: metrics_client.go + where: $ + transform: return $.replace(/\*options.Aggregation/g, "aggregationTypeToString(options.Aggregation)"); + - from: swagger-document + where: $.parameters.AggregationsParameter + transform: $["description"] = "The list of aggregation types to retrieve" \ No newline at end of file diff --git a/sdk/monitor/azquery/custom_client.go b/sdk/monitor/azquery/custom_client.go index 0d2af3a01f2d..39f0d062ff7c 100644 --- a/sdk/monitor/azquery/custom_client.go +++ b/sdk/monitor/azquery/custom_client.go @@ -192,3 +192,13 @@ func NewBatchQueryRequest(workspaceID string, query string, timespan TimeInterva Headers: optionsMap, } } + +// aggregationTypeToString converts []*AggregationType to string, so the values can be sent +// in MetricsClient.QueryResource +func aggregationTypeToString(aggregations []*AggregationType) string { + var s []string + for _, aggregation := range aggregations { + s = append(s, string(*aggregation)) + } + return strings.Join(s, ",") +} diff --git a/sdk/monitor/azquery/example_test.go b/sdk/monitor/azquery/example_test.go index 61fda84ef100..30b788945e90 100644 --- a/sdk/monitor/azquery/example_test.go +++ b/sdk/monitor/azquery/example_test.go @@ -194,7 +194,7 @@ func ExampleMetricsClient_QueryResource() { Timespan: to.Ptr(azquery.NewTimeInterval(time.Date(2022, 12, 25, 0, 0, 0, 0, time.UTC), time.Date(2022, 12, 25, 12, 0, 0, 0, time.UTC))), Interval: to.Ptr("PT1M"), MetricNames: nil, - Aggregation: to.Ptr("Average,count"), + Aggregation: to.SliceOfPtrs(azquery.AggregationTypeAverage, azquery.AggregationTypeCount), Top: to.Ptr[int32](3), OrderBy: to.Ptr("Average asc"), Filter: to.Ptr("BlobType eq '*'"), diff --git a/sdk/monitor/azquery/metrics_client.go b/sdk/monitor/azquery/metrics_client.go index 14f72cfc1c9a..a8ef22e4c9fd 100644 --- a/sdk/monitor/azquery/metrics_client.go +++ b/sdk/monitor/azquery/metrics_client.go @@ -163,7 +163,7 @@ func (client *MetricsClient) queryResourceCreateRequest(ctx context.Context, res reqQP.Set("metricnames", *options.MetricNames) } if options != nil && options.Aggregation != nil { - reqQP.Set("aggregation", *options.Aggregation) + reqQP.Set("aggregation", aggregationTypeToString(options.Aggregation)) } if options != nil && options.Top != nil { reqQP.Set("top", strconv.FormatInt(int64(*options.Top), 10)) diff --git a/sdk/monitor/azquery/metrics_client_test.go b/sdk/monitor/azquery/metrics_client_test.go index 02377f5f8f13..3e832206399a 100644 --- a/sdk/monitor/azquery/metrics_client_test.go +++ b/sdk/monitor/azquery/metrics_client_test.go @@ -42,10 +42,11 @@ func TestQueryResource_BasicQuerySuccess(t *testing.T) { client := startMetricsTest(t) timespan := azquery.TimeInterval("PT12H") res, err := client.QueryResource(context.Background(), resourceURI, - &azquery.MetricsClientQueryResourceOptions{Timespan: to.Ptr(timespan), + &azquery.MetricsClientQueryResourceOptions{ + Timespan: to.Ptr(timespan), Interval: to.Ptr("PT1M"), MetricNames: nil, - Aggregation: to.Ptr("Average,count"), + Aggregation: to.SliceOfPtrs(azquery.AggregationTypeAverage, azquery.AggregationTypeCount), Top: nil, OrderBy: to.Ptr("Average asc"), Filter: nil, diff --git a/sdk/monitor/azquery/models.go b/sdk/monitor/azquery/models.go index 251e84a645bf..92d07d130f8f 100644 --- a/sdk/monitor/azquery/models.go +++ b/sdk/monitor/azquery/models.go @@ -274,8 +274,8 @@ type MetricsClientListNamespacesOptions struct { // MetricsClientQueryResourceOptions contains the optional parameters for the MetricsClient.QueryResource method. type MetricsClientQueryResourceOptions struct { - // The list of aggregation types (comma separated) to retrieve. - Aggregation *string + // The list of aggregation types to retrieve + Aggregation []*AggregationType // The $filter is used to reduce the set of metric data returned. Example: Metric contains metadata A, B and C. - Return all // time series of C where A = a1 and B = b1 or b2 $filter=A eq 'a1' and B eq 'b1' // or B eq 'b2' and C eq '' - Invalid variant: $filter=A eq 'a1' and B eq 'b1' and C eq '' or B = 'b2' This is invalid because