From 6d8e60cebb41d37ca830aed05fb47705848a49e4 Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Wed, 12 Jun 2024 17:35:09 -0700 Subject: [PATCH 1/3] remove batch metrics --- sdk/monitor/azquery/CHANGELOG.md | 1 + sdk/monitor/azquery/README.md | 10 -- sdk/monitor/azquery/autorest.md | 62 +--------- sdk/monitor/azquery/custom_client.go | 24 ---- sdk/monitor/azquery/example_test.go | 57 --------- sdk/monitor/azquery/metricsbatch_client.go | 110 ------------------ .../azquery/metricsbatch_client_test.go | 70 ----------- sdk/monitor/azquery/models.go | 38 ------ sdk/monitor/azquery/models_serde.go | 105 ----------------- sdk/monitor/azquery/options.go | 39 ------- sdk/monitor/azquery/response_types.go | 6 - sdk/monitor/azquery/utils_test.go | 13 --- 12 files changed, 2 insertions(+), 533 deletions(-) delete mode 100644 sdk/monitor/azquery/metricsbatch_client.go delete mode 100644 sdk/monitor/azquery/metricsbatch_client_test.go diff --git a/sdk/monitor/azquery/CHANGELOG.md b/sdk/monitor/azquery/CHANGELOG.md index 1a6c1a475928..623e276a9e2f 100644 --- a/sdk/monitor/azquery/CHANGELOG.md +++ b/sdk/monitor/azquery/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bugs Fixed ### Other Changes +* Removed `MetricsBatchClient`. Support for metrics batch in now GA in [azmetrics](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics) ## 1.2.0-beta.1 (2023-11-16) diff --git a/sdk/monitor/azquery/README.md b/sdk/monitor/azquery/README.md index b5b7d575af78..4b25d634b54d 100644 --- a/sdk/monitor/azquery/README.md +++ b/sdk/monitor/azquery/README.md @@ -43,10 +43,6 @@ Example [logs client][example_logs_client] Example [metrics client][example_metrics_client] -#### Create a metrics batch client - -Example metrics batch client - ## Key concepts ### Timespan @@ -66,12 +62,6 @@ Each set of metric values is a time series with the following characteristics: - The value itself - Some metrics may have multiple dimensions as described in [multi-dimensional metrics][multi-metrics]. Custom metrics can have up to 10 dimensions. -### Metrics batch query - -A user can also query metrics from multiple resources at once using the query_batch method of MetricsBatchClient. This uses a different API than the MetricsClient and requires that a user pass in a regional endpoint when instantiating the client (for example, "https://westus3.metrics.monitor.azure.com"). - -Note, each resource must be in the same region as the endpoint passed in when instantiating the client, and each resource must be in the same Azure subscription. Furthermore, the metric namespace that contains the metrics to be queried must also be passed. A list of metric namespaces can be found [here][metric_namespaces]. - ### Logs query rate limits and throttling The Log Analytics service applies throttling when the request rate is too high. Limits, such as the maximum number of rows returned, are also applied on the Kusto queries. For more information, see [Query API][service_limits]. diff --git a/sdk/monitor/azquery/autorest.md b/sdk/monitor/azquery/autorest.md index 7a73d8899fd9..5ba05ee43097 100644 --- a/sdk/monitor/azquery/autorest.md +++ b/sdk/monitor/azquery/autorest.md @@ -200,71 +200,11 @@ directive: - from: options.go where: $ transform: return $.replace(/Aggregation \*string/g, "Aggregation []*AggregationType"); - - from: - - metrics_client.go - - metricsbatch_client.go + - 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" ``` - -``` yaml -title: Metrics Batch Query Client -input-file: https://github.com/Azure/azure-rest-api-specs/blob/21f5332f2dc7437d1446edf240e9a3d4c90c6431/specification/monitor/data-plane/Microsoft.Insights/preview/2023-05-01-preview/metricBatch.json - -directive: - # rename Batch to QueryBatch - - rename-operation: - from: MetricsBatch_Batch - to: MetricsBatch_QueryBatch - - # Rename MetricResultsResponse - - rename-model: - from: MetricResultsResponse - to: MetricResults - - from: - - models.go - - models_serde.go - where: $ - transform: return $.replace(/MetricResultsValuesItem/g, "MetricValues"); - - from: swagger-document - where: $.definitions.MetricResults.properties.values.items - transform: $["description"] = "Metric data values." - - # fix casing, rename batch metric fields - - from: swagger-document - where: $.parameters.StartTimeParameter - transform: $["x-ms-client-name"] = "StartTime" - - from: swagger-document - where: $.parameters.EndTimeParameter - transform: $["x-ms-client-name"] = "EndTime" - - from: swagger-document - where: $.definitions.ResourceIdList.properties.resourceids - transform: $["x-ms-client-name"] = "ResourceIDs" - - from: swagger-document - where: $.definitions.MetricResults.properties.values.items.properties.starttime - transform: $["x-ms-client-name"] = "StartTime" - - from: swagger-document - where: $.definitions.MetricResults.properties.values.items.properties.endtime - transform: $["x-ms-client-name"] = "EndTime" - - from: swagger-document - where: $.definitions.MetricResults.properties.values.items.properties.resourceid - transform: $["x-ms-client-name"] = "ResourceID" - - from: swagger-document - where: $.definitions.MetricResults.properties.values.items.properties.resourceregion - transform: $["x-ms-client-name"] = "ResourceRegion" - - from: swagger-document - where: $.definitions.MetricResults.properties.values.items.properties.value - transform: $["x-ms-client-name"] = "Values" - - # delete unused error models - - from: models.go - where: $ - transform: return $.replace(/((?:\/\/.*\s)+|)type AdditionalInfoErrorResponse.+\{(?:\s.+\s)+\}\s/g, ""); - - from: models_serde.go - where: $ - transform: return $.replace(/(?:\/\/.*\s)+func \(\w \*?AdditionalInfoErrorResponse.*\{\s(?:.+\s)+\}\s/g, ""); - ``` \ No newline at end of file diff --git a/sdk/monitor/azquery/custom_client.go b/sdk/monitor/azquery/custom_client.go index 0b30171f6c1d..2a6b30b078a4 100644 --- a/sdk/monitor/azquery/custom_client.go +++ b/sdk/monitor/azquery/custom_client.go @@ -32,11 +32,6 @@ type LogsClientOptions struct { azcore.ClientOptions } -// MetricsBatchClientOptions contains optional settings for MetricsBatchClient. -type MetricsBatchClientOptions struct { - azcore.ClientOptions -} - // NewLogsClient creates a client that accesses Azure Monitor logs data. func NewLogsClient(credential azcore.TokenCredential, options *LogsClientOptions) (*LogsClient, error) { if options == nil { @@ -79,25 +74,6 @@ func NewMetricsClient(credential azcore.TokenCredential, options *MetricsClientO return &MetricsClient{host: c.Endpoint, internal: azcoreClient}, nil } -// NewMetricsBatchClient creates a client that accesses Azure Monitor metrics data. -// MetricsBatchClient should be used for performing metrics queries on multiple monitored resources in the same region. -// A credential with authorization at the subscription level is required when using this client. -// -// endpoint - The regional endpoint to use, for example https://eastus.metrics.monitor.azure.com. -// The region should match the region of the requested resources. For global resources, the region should be 'global'. -func NewMetricsBatchClient(endpoint string, credential azcore.TokenCredential, options *MetricsBatchClientOptions) (*MetricsBatchClient, error) { - if options == nil { - options = &MetricsBatchClientOptions{} - } - - authPolicy := runtime.NewBearerTokenPolicy(credential, []string{"https://metrics.monitor.azure.com" + "/.default"}, nil) - azcoreClient, err := azcore.NewClient(moduleName, version, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions) - if err != nil { - return nil, err - } - return &MetricsBatchClient{endpoint: endpoint, internal: azcoreClient}, nil -} - // ErrorInfo - The code and message for an error. type ErrorInfo struct { // REQUIRED; A machine readable error code. diff --git a/sdk/monitor/azquery/example_test.go b/sdk/monitor/azquery/example_test.go index 50eef2dc57f5..fa9cf0703159 100644 --- a/sdk/monitor/azquery/example_test.go +++ b/sdk/monitor/azquery/example_test.go @@ -18,7 +18,6 @@ import ( var logsClient azquery.LogsClient var metricsClient azquery.MetricsClient -var metricsBatchClient azquery.MetricsBatchClient var kustoQuery1 string var kustoQuery2 string var kustoQuery3 string @@ -56,23 +55,6 @@ func ExampleNewMetricsClient() { _ = client } -func ExampleNewMetricsBatchClient() { - // The regional endpoint to use. The region should match the region of the requested resources. - // For global resources, the region should be 'global' - endpoint := "https://eastus.metrics.monitor.azure.com" - - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - //TODO: handle error - } - - client, err := azquery.NewMetricsBatchClient(endpoint, cred, nil) - if err != nil { - //TODO: handle error - } - _ = client -} - func ExampleLogsClient_QueryWorkspace() { // QueryWorkspace allows users to query log data. @@ -296,42 +278,3 @@ func ExampleMetricsClient_NewListNamespacesPager() { } } } - -func ExampleMetricsBatchClient_QueryBatch() { - // This sample uses the MetricsBatchClient to retrieve the "Ingress" - // metric along with the "Average" aggregation type for multiple resources. - // The query will execute over a timespan of 2 hours with a interval (granularity) of 5 minutes. - - // In this example, storage account resource URIs are queried for metrics. - resourceURI1 := "/subscriptions//resourceGroups//providers/Microsoft.Storage/storageAccounts/" - resourceURI2 := "/subscriptions//resourceGroups//providers/Microsoft.Storage/storageAccounts/" - - res, err := metricsBatchClient.QueryBatch( - context.Background(), - subscriptionID, - "Microsoft.Storage/storageAccounts", - []string{"Ingress"}, - azquery.ResourceIDList{ResourceIDs: to.SliceOfPtrs(resourceURI1, resourceURI2)}, - &azquery.MetricsBatchClientQueryBatchOptions{ - Aggregation: to.SliceOfPtrs(azquery.AggregationTypeAverage), - StartTime: to.Ptr("2023-11-15"), - EndTime: to.Ptr("2023-11-16"), - Interval: to.Ptr("PT5M"), - }, - ) - if err != nil { - //TODO: handle error - } - - // Print out results - for _, result := range res.Values { - for _, metric := range result.Values { - fmt.Println(*metric.Name.Value + ": " + *metric.DisplayDescription) - for _, timeSeriesElement := range metric.TimeSeries { - for _, metricValue := range timeSeriesElement.Data { - fmt.Printf("The ingress at %v is %v.\n", metricValue.TimeStamp.String(), *metricValue.Average) - } - } - } - } -} diff --git a/sdk/monitor/azquery/metricsbatch_client.go b/sdk/monitor/azquery/metricsbatch_client.go deleted file mode 100644 index c07b83f80d3e..000000000000 --- a/sdk/monitor/azquery/metricsbatch_client.go +++ /dev/null @@ -1,110 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -package azquery - -import ( - "context" - "errors" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" - "net/http" - "net/url" - "strconv" - "strings" -) - -// MetricsBatchClient contains the methods for the MetricsBatch group. -// Don't use this type directly, use a constructor function instead. -type MetricsBatchClient struct { - internal *azcore.Client - endpoint string -} - -// QueryBatch - Lists the metric values for multiple resources. -// If the operation fails it returns an *azcore.ResponseError type. -// -// Generated from API version 2023-05-01-preview -// - subscriptionID - The subscription identifier for the resources in this batch. -// - metricNamespace - Metric namespace that contains the requested metric names. -// - metricNames - The names of the metrics (comma separated) to retrieve. -// - resourceIDs - The comma separated list of resource IDs to query metrics for. -// - options - MetricsBatchClientQueryBatchOptions contains the optional parameters for the MetricsBatchClient.QueryBatch method. -func (client *MetricsBatchClient) QueryBatch(ctx context.Context, subscriptionID string, metricNamespace string, metricNames []string, resourceIDs ResourceIDList, options *MetricsBatchClientQueryBatchOptions) (MetricsBatchClientQueryBatchResponse, error) { - var err error - ctx, endSpan := runtime.StartSpan(ctx, "MetricsBatchClient.QueryBatch", client.internal.Tracer(), nil) - defer func() { endSpan(err) }() - req, err := client.queryBatchCreateRequest(ctx, subscriptionID, metricNamespace, metricNames, resourceIDs, options) - if err != nil { - return MetricsBatchClientQueryBatchResponse{}, err - } - httpResp, err := client.internal.Pipeline().Do(req) - if err != nil { - return MetricsBatchClientQueryBatchResponse{}, err - } - if !runtime.HasStatusCode(httpResp, http.StatusOK) { - err = runtime.NewResponseError(httpResp) - return MetricsBatchClientQueryBatchResponse{}, err - } - resp, err := client.queryBatchHandleResponse(httpResp) - return resp, err -} - -// queryBatchCreateRequest creates the QueryBatch request. -func (client *MetricsBatchClient) queryBatchCreateRequest(ctx context.Context, subscriptionID string, metricNamespace string, metricNames []string, resourceIDs ResourceIDList, options *MetricsBatchClientQueryBatchOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/metrics:getBatch" - if subscriptionID == "" { - return nil, errors.New("parameter subscriptionID cannot be empty") - } - urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(subscriptionID)) - req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.endpoint, urlPath)) - if err != nil { - return nil, err - } - reqQP := req.Raw().URL.Query() - if options != nil && options.StartTime != nil { - reqQP.Set("starttime", *options.StartTime) - } - if options != nil && options.EndTime != nil { - reqQP.Set("endtime", *options.EndTime) - } - if options != nil && options.Interval != nil { - reqQP.Set("interval", *options.Interval) - } - reqQP.Set("metricnamespace", metricNamespace) - reqQP.Set("metricnames", strings.Join(metricNames, ",")) - if options != nil && options.Aggregation != nil { - reqQP.Set("aggregation", aggregationTypeToString(options.Aggregation)) - } - if options != nil && options.Top != nil { - reqQP.Set("top", strconv.FormatInt(int64(*options.Top), 10)) - } - if options != nil && options.OrderBy != nil { - reqQP.Set("orderby", *options.OrderBy) - } - if options != nil && options.Filter != nil { - reqQP.Set("filter", *options.Filter) - } - reqQP.Set("api-version", "2023-05-01-preview") - req.Raw().URL.RawQuery = reqQP.Encode() - req.Raw().Header["Accept"] = []string{"application/json"} - if err := runtime.MarshalAsJSON(req, resourceIDs); err != nil { - return nil, err - } - return req, nil -} - -// queryBatchHandleResponse handles the QueryBatch response. -func (client *MetricsBatchClient) queryBatchHandleResponse(resp *http.Response) (MetricsBatchClientQueryBatchResponse, error) { - result := MetricsBatchClientQueryBatchResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.MetricResults); err != nil { - return MetricsBatchClientQueryBatchResponse{}, err - } - return result, nil -} diff --git a/sdk/monitor/azquery/metricsbatch_client_test.go b/sdk/monitor/azquery/metricsbatch_client_test.go deleted file mode 100644 index 85d9bd627f58..000000000000 --- a/sdk/monitor/azquery/metricsbatch_client_test.go +++ /dev/null @@ -1,70 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -package azquery_test - -import ( - "context" - "testing" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery" - "github.com/stretchr/testify/require" -) - -func TestQueryBatch_Metrics(t *testing.T) { - client := startMetricsBatchTest(t) - metricName := "HttpIncomingRequestCount" - resourceIDList := azquery.ResourceIDList{ResourceIDs: to.SliceOfPtrs(resourceURI)} - - res, err := client.QueryBatch( - context.Background(), - subscriptionID, - "Microsoft.AppConfiguration/configurationStores", - []string{"HttpIncomingRequestCount"}, - resourceIDList, - &azquery.MetricsBatchClientQueryBatchOptions{ - Aggregation: to.SliceOfPtrs(azquery.AggregationTypeAverage), - StartTime: to.Ptr("P1D"), - Interval: to.Ptr("PT1H"), - }, - ) - require.NoError(t, err) - require.NotNil(t, res) - - for _, resource := range res.Values { - for _, metric := range resource.Values { - require.Equal(t, metricName, *metric.Name.Value) - for _, timeSeriesElement := range metric.TimeSeries { - require.NotNil(t, timeSeriesElement) - } - } - } - - testSerde(t, &res) - testSerde(t, &resourceIDList) -} - -func TestQueryBatch_MetricsFailure(t *testing.T) { - client := startMetricsBatchTest(t) - - res, err := client.QueryBatch( - context.Background(), - "fakesubscriptionID", - "Microsoft.AppConfiguration/configurationStores", - []string{"HttpIncomingRequestCount"}, - azquery.ResourceIDList{ResourceIDs: to.SliceOfPtrs(resourceURI)}, - nil, - ) - require.Error(t, err) - var httpErr *azcore.ResponseError - require.ErrorAs(t, err, &httpErr) - require.NotEqual(t, 200, httpErr.StatusCode) - require.Nil(t, res.Values) - - testSerde(t, &res) -} diff --git a/sdk/monitor/azquery/models.go b/sdk/monitor/azquery/models.go index 475b64d26f52..c032f330106c 100644 --- a/sdk/monitor/azquery/models.go +++ b/sdk/monitor/azquery/models.go @@ -224,38 +224,6 @@ type MetricNamespaceName struct { MetricNamespaceName *string } -// MetricResults - The metrics result for a resource. -type MetricResults struct { - // The collection of metric data responses per resource, per metric. - Values []*MetricValues -} - -// MetricValues - Metric data values. -type MetricValues struct { - // REQUIRED; The end time, in datetime format, for which the data was retrieved. - EndTime *string - - // REQUIRED; The start time, in datetime format, for which the data was retrieved. - StartTime *string - - // REQUIRED; The value of the collection. - Values []*Metric - - // The interval (window size) for which the metric data was returned in. Follows the IS8601/RFC3339 duration format (e.g. - // 'P1D' for 1 day). This may be adjusted in the future and returned back from what - // was originally requested. This is not present if a metadata request was made. - Interval *string - - // The namespace of the metrics been queried - Namespace *string - - // The resource that has been queried for metrics. - ResourceID *string - - // The region of the resource been queried for metrics. - ResourceRegion *string -} - // MetricValue - Represents a metric value. type MetricValue struct { // REQUIRED; The timestamp for the metric value in ISO 8601 format. @@ -278,12 +246,6 @@ type MetricValue struct { Total *float64 } -// ResourceIDList - The comma separated list of resource IDs to query metrics for. -type ResourceIDList struct { - // The list of resource IDs to query metrics for. - ResourceIDs []*string -} - // Response - The response to a metrics query. type Response struct { // REQUIRED; The timespan for which the data was retrieved. Its value consists of two datetimes concatenated, separated by diff --git a/sdk/monitor/azquery/models_serde.go b/sdk/monitor/azquery/models_serde.go index 894aec66d473..3b00b8c76f4f 100644 --- a/sdk/monitor/azquery/models_serde.go +++ b/sdk/monitor/azquery/models_serde.go @@ -614,84 +614,6 @@ func (m *MetricNamespaceName) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type MetricResults. -func (m MetricResults) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "values", m.Values) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type MetricResults. -func (m *MetricResults) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", m, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "values": - err = unpopulate(val, "Values", &m.Values) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", m, err) - } - } - return nil -} - -// MarshalJSON implements the json.Marshaller interface for type MetricValues. -func (m MetricValues) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "endtime", m.EndTime) - populate(objectMap, "interval", m.Interval) - populate(objectMap, "namespace", m.Namespace) - populate(objectMap, "resourceid", m.ResourceID) - populate(objectMap, "resourceregion", m.ResourceRegion) - populate(objectMap, "starttime", m.StartTime) - populate(objectMap, "value", m.Values) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type MetricValues. -func (m *MetricValues) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", m, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "endtime": - err = unpopulate(val, "EndTime", &m.EndTime) - delete(rawMsg, key) - case "interval": - err = unpopulate(val, "Interval", &m.Interval) - delete(rawMsg, key) - case "namespace": - err = unpopulate(val, "Namespace", &m.Namespace) - delete(rawMsg, key) - case "resourceid": - err = unpopulate(val, "ResourceID", &m.ResourceID) - delete(rawMsg, key) - case "resourceregion": - err = unpopulate(val, "ResourceRegion", &m.ResourceRegion) - delete(rawMsg, key) - case "starttime": - err = unpopulate(val, "StartTime", &m.StartTime) - delete(rawMsg, key) - case "value": - err = unpopulate(val, "Values", &m.Values) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", m, err) - } - } - return nil -} - // MarshalJSON implements the json.Marshaller interface for type MetricValue. func (m MetricValue) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) @@ -739,33 +661,6 @@ func (m *MetricValue) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type ResourceIDList. -func (r ResourceIDList) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "resourceids", r.ResourceIDs) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type ResourceIDList. -func (r *ResourceIDList) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", r, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "resourceids": - err = unpopulate(val, "ResourceIDs", &r.ResourceIDs) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", r, err) - } - } - return nil -} - // MarshalJSON implements the json.Marshaller interface for type Response. func (r Response) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) diff --git a/sdk/monitor/azquery/options.go b/sdk/monitor/azquery/options.go index d8638ca5bc61..c1369ee93331 100644 --- a/sdk/monitor/azquery/options.go +++ b/sdk/monitor/azquery/options.go @@ -25,45 +25,6 @@ type LogsClientQueryWorkspaceOptions struct { Options *LogsQueryOptions } -// MetricsBatchClientQueryBatchOptions contains the optional parameters for the MetricsBatchClient.QueryBatch method. -type MetricsBatchClientQueryBatchOptions struct { - // The list of aggregation types to retrieve - Aggregation []*AggregationType - - // The end time of the query. It is a string in the format 'yyyy-MM-ddTHH:mm:ss.fffZ'. - EndTime *string - - // 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 the logical or operator cannot separate two different metadata names. - // - Return all time series where A = a1, B = b1 and C = c1: - // filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘c1’ - // - Return all time series where A = a1 - // filter=A eq ‘a1’ and B eq ‘’ and C eq ‘’. - Filter *string - - // The interval (i.e. timegrain) of the query.Examples: PT15M, PT1H, P1D - Interval *string - - // The aggregation to use for sorting results and the direction of the sort. Only one order can be specified.Examples: sum - // asc - OrderBy *string - - // The start time of the query. It is a string in the format 'yyyy-MM-ddTHH:mm:ss.fffZ'. If you have specified the endtime - // parameter, then this parameter is required. If only starttime is specified, then - // endtime defaults to the current time. If no time interval is specified, the default is 1 hour. - StartTime *string - - // The maximum number of records to retrieve per resource ID in the request. Valid only if filter is specified. Defaults to - // 10. - Top *int32 -} - // MetricsClientListDefinitionsOptions contains the optional parameters for the MetricsClient.NewListDefinitionsPager method. type MetricsClientListDefinitionsOptions struct { // Metric namespace to query metric definitions for. diff --git a/sdk/monitor/azquery/response_types.go b/sdk/monitor/azquery/response_types.go index caae94df0d74..847c272868e7 100644 --- a/sdk/monitor/azquery/response_types.go +++ b/sdk/monitor/azquery/response_types.go @@ -26,12 +26,6 @@ type LogsClientQueryWorkspaceResponse struct { Results } -// MetricsBatchClientQueryBatchResponse contains the response from method MetricsBatchClient.QueryBatch. -type MetricsBatchClientQueryBatchResponse struct { - // The metrics result for a resource. - MetricResults -} - // MetricsClientListDefinitionsResponse contains the response from method MetricsClient.NewListDefinitionsPager. type MetricsClientListDefinitionsResponse struct { // Represents collection of metric definitions. diff --git a/sdk/monitor/azquery/utils_test.go b/sdk/monitor/azquery/utils_test.go index 5792c3f79cf0..090c4f86d8e1 100644 --- a/sdk/monitor/azquery/utils_test.go +++ b/sdk/monitor/azquery/utils_test.go @@ -139,19 +139,6 @@ func startMetricsTest(t *testing.T) *azquery.MetricsClient { return client } -func startMetricsBatchTest(t *testing.T) *azquery.MetricsBatchClient { - startRecording(t) - transport, err := recording.NewRecordingHTTPClient(t, nil) - require.NoError(t, err) - opts := &azquery.MetricsBatchClientOptions{ClientOptions: azcore.ClientOptions{Transport: transport}} - endpoint := "https://" + region + ".metrics.monitor.azure.com" - client, err := azquery.NewMetricsBatchClient(endpoint, credential, opts) - if err != nil { - panic(err) - } - return client -} - func getEnvVar(envVar string, fakeValue string) string { // get value value := fakeValue From 4e2045a931bc2e56cc172bd457f653255c94c6fb Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Thu, 13 Jun 2024 14:10:19 -0700 Subject: [PATCH 2/3] add frozen message --- sdk/monitor/azquery/CHANGELOG.md | 3 ++- sdk/monitor/azquery/README.md | 2 ++ sdk/monitor/azquery/version.go | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sdk/monitor/azquery/CHANGELOG.md b/sdk/monitor/azquery/CHANGELOG.md index 623e276a9e2f..c10980f414cb 100644 --- a/sdk/monitor/azquery/CHANGELOG.md +++ b/sdk/monitor/azquery/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.2.0-beta.2 (Unreleased) +## 1.2.1 (Unreleased) ### Features Added @@ -9,6 +9,7 @@ ### Bugs Fixed ### Other Changes +* This package is frozen. New features will be added in the following packages: [azlogs](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azlogs), [azmetrics](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics) (data plane metrics), and [armmonitor](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor) (control plane metrics) * Removed `MetricsBatchClient`. Support for metrics batch in now GA in [azmetrics](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics) ## 1.2.0-beta.1 (2023-11-16) diff --git a/sdk/monitor/azquery/README.md b/sdk/monitor/azquery/README.md index 4b25d634b54d..890564c3b307 100644 --- a/sdk/monitor/azquery/README.md +++ b/sdk/monitor/azquery/README.md @@ -1,5 +1,7 @@ # Azure Monitor Query client module for Go +> This package is frozen. New feature work will be added in the following packages: [azlogs](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azlogs), [azmetrics](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics) (data plane metrics), and [armmonitor](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor) (control plane metrics). + The Azure Monitor Query client module is used to execute read-only queries against [Azure Monitor][azure_monitor_overview]'s two data platforms: - [Logs][logs_overview] - Collects and organizes log and performance data from monitored resources. Data from different sources such as platform logs from Azure services, log and performance data from virtual machines agents, and usage and performance data from apps can be consolidated into a single [Azure Log Analytics workspace][log_analytics_workspace]. The various data types can be analyzed together using the [Kusto Query Language][kusto_query_language]. See the [Kusto to SQL cheat sheet][kusto_to_sql] for more information. diff --git a/sdk/monitor/azquery/version.go b/sdk/monitor/azquery/version.go index c2b2cf0e12d3..3419ea109b9a 100644 --- a/sdk/monitor/azquery/version.go +++ b/sdk/monitor/azquery/version.go @@ -8,5 +8,5 @@ package azquery const ( moduleName = "github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery" - version = "v1.2.0-beta.2" + version = "v1.2.1" ) From 9c763dbb39afc614153eaf74e50983126aaf7b5c Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Thu, 13 Jun 2024 14:15:13 -0700 Subject: [PATCH 3/3] cleanup utils --- sdk/monitor/azquery/go.mod | 15 +++++++-------- sdk/monitor/azquery/go.sum | 30 ++++++++++++++---------------- sdk/monitor/azquery/utils_test.go | 28 +++++++--------------------- 3 files changed, 28 insertions(+), 45 deletions(-) diff --git a/sdk/monitor/azquery/go.mod b/sdk/monitor/azquery/go.mod index 22b1e8b954c7..bc07091675d4 100644 --- a/sdk/monitor/azquery/go.mod +++ b/sdk/monitor/azquery/go.mod @@ -3,9 +3,9 @@ module github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.2 - github.com/Azure/azure-sdk-for-go/sdk/internal v1.7.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.12.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.9.0 github.com/stretchr/testify v1.9.0 ) @@ -14,13 +14,12 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang-jwt/jwt/v5 v5.2.1 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/kr/text v0.2.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.22.0 // indirect - golang.org/x/net v0.24.0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/crypto v0.24.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/monitor/azquery/go.sum b/sdk/monitor/azquery/go.sum index 418325421c01..60510edb7a54 100644 --- a/sdk/monitor/azquery/go.sum +++ b/sdk/monitor/azquery/go.sum @@ -1,12 +1,11 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 h1:E+OJmp2tPvt1W+amx48v1eqbjDYsgN+RzP4q16yV5eM= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1/go.mod h1:a6xsAQUZg+VsS3TJ05SRp524Hs4pZ/AeFSr5ENf0Yjo= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.2 h1:FDif4R1+UUR+00q6wquyX90K7A8dN+R5E8GEadoP7sU= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.2/go.mod h1:aiYBYui4BJ/BJCAIKs92XiPyQfTaBWqvHujDwKb6CBU= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.7.0 h1:rTfKOCZGy5ViVrlA74ZPE99a+SgoEE2K/yg3RyW9dFA= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.7.0/go.mod h1:4OG6tQ9EOP/MT0NMjDlRzWoVFxfu9rN9B2X+tlSVktg= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.12.0 h1:1nGuui+4POelzDwI7RG56yfQJHCnKvwfMoU7VsEp+Zg= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.12.0/go.mod h1:99EvauvlcJ1U06amZiksfYz/3aFGyIhWGHVyiZXtBAI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0 h1:U2rTu3Ef+7w9FHKIAXM6ZyqF3UOWJZ12zIm8zECAFfg= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.9.0 h1:H+U3Gk9zY56G3u872L82bk4thcsy2Gghb9ExT4Zvm1o= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.9.0/go.mod h1:mgrmMSgaLp9hmax62XQTd0N4aAqSE5E0DulSpVYK7vc= github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU= github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= @@ -15,7 +14,6 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= @@ -25,15 +23,15 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/sdk/monitor/azquery/utils_test.go b/sdk/monitor/azquery/utils_test.go index 090c4f86d8e1..b8c743e91784 100644 --- a/sdk/monitor/azquery/utils_test.go +++ b/sdk/monitor/azquery/utils_test.go @@ -7,7 +7,6 @@ package azquery_test import ( - "context" "crypto/tls" "encoding/json" "net/http" @@ -15,13 +14,11 @@ import ( "regexp" "strings" "testing" - "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" + azcred "github.com/Azure/azure-sdk-for-go/sdk/internal/test/credential" "github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery" "github.com/stretchr/testify/require" ) @@ -62,18 +59,13 @@ func run(m *testing.M) int { }() } - if recording.GetRecordMode() == recording.PlaybackMode { - credential = &FakeCredential{} - } else { - tenantID := getEnvVar("AZQUERY_TENANT_ID", "") - clientID := getEnvVar("AZQUERY_CLIENT_ID", "") - secret := getEnvVar("AZQUERY_CLIENT_SECRET", "") - var err error - credential, err = azidentity.NewClientSecretCredential(tenantID, clientID, secret, nil) - if err != nil { - panic(err) - } + var err error + credential, err = azcred.New(nil) + if err != nil { + panic(err) + } + if recording.GetRecordMode() != recording.PlaybackMode { if cloudEnv, ok := os.LookupEnv("AZQUERY_ENVIRONMENT"); ok { if strings.EqualFold(cloudEnv, "AzureUSGovernment") { clientCloud = cloud.AzureGovernment @@ -160,12 +152,6 @@ func getEnvVar(envVar string, fakeValue string) string { return value } -type FakeCredential struct{} - -func (f *FakeCredential) GetToken(ctx context.Context, options policy.TokenRequestOptions) (azcore.AccessToken, error) { - return azcore.AccessToken{Token: "faketoken", ExpiresOn: time.Now().Add(time.Hour).UTC()}, nil -} - type serdeModel interface { json.Marshaler json.Unmarshaler