Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azquery] cleanup #23065

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sdk/monitor/azquery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release History

## 1.2.0-beta.2 (Unreleased)
## 1.2.1 (Unreleased)

### Features Added

Expand All @@ -9,6 +9,8 @@
### 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)

Expand Down
12 changes: 2 additions & 10 deletions sdk/monitor/azquery/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -43,10 +45,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
Expand All @@ -66,12 +64,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].
Expand Down
62 changes: 1 addition & 61 deletions sdk/monitor/azquery/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");

```
24 changes: 0 additions & 24 deletions sdk/monitor/azquery/custom_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
57 changes: 0 additions & 57 deletions sdk/monitor/azquery/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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/<id>/resourceGroups/<rg>/providers/Microsoft.Storage/storageAccounts/<account-1>"
resourceURI2 := "/subscriptions/<id>/resourceGroups/<rg>/providers/Microsoft.Storage/storageAccounts/<account-2>"

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)
}
}
}
}
}
15 changes: 7 additions & 8 deletions sdk/monitor/azquery/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
)
30 changes: 14 additions & 16 deletions sdk/monitor/azquery/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down
Loading