Skip to content

Commit 3d66198

Browse files
authored
[monitor query] move metrics dataplane to new azmetrics module (#22366)
* move code * add files * cleanup code * added tests * license * update code coverage * charles feedback * charles feedback
1 parent 7899ebe commit 3d66198

22 files changed

+1391
-0
lines changed

eng/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
{
113113
"Name": "security/keyvault/azadmin",
114114
"CoverageGoal": 0.80
115+
},
116+
{
117+
"Name": "monitor/query/azmetrics",
118+
"CoverageGoal": 0.75
115119
}
116120
]
117121
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release History
2+
3+
## 0.1.0 (2024-02-14)
4+
5+
* This is the initial release of the `azmetrics` module
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation. All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE

sdk/monitor/query/azmetrics/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Azure Monitor Metrics client module for Go
2+
3+
Source code | Package (pkg.go.dev) | [REST API documentation][monitor_rest_docs] | [Product documentation][monitor_docs] | Samples
4+
5+
## Getting started
6+
7+
### Prerequisites
8+
9+
* Go version 1.18 or higher - [Install Go](https://go.dev/doc/install)
10+
* Azure subscription - [Create a free account][azure_sub]
11+
* The resource URI of an Azure resource (Storage Account, Key Vault, CosmosDB, etc.) that you plan to monitor
12+
13+
### Install the packages
14+
15+
Install the `azmetrics` and `azidentity` modules with `go get`:
16+
17+
```bash
18+
go get github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics
19+
go get github.com/Azure/azure-sdk-for-go/sdk/azidentity
20+
```
21+
22+
The [azidentity][azure_identity] module is used for client authentication.
23+
24+
### Authentication
25+
26+
An authenticated client object is required to execute a query. The examples demonstrate using [azidentity.NewDefaultAzureCredential][default_cred_ref] to authenticate; however, the client accepts any [azidentity][azure_identity] credential. See the [azidentity][azure_identity] documentation for more information about other credential types.
27+
28+
The clients default to the Azure public cloud. For other cloud configurations, see the [cloud][cloud_documentation] package documentation.
29+
30+
#### Create a client
31+
32+
Example client
33+
34+
## Key concepts
35+
36+
### Metrics data structure
37+
38+
Each set of metric values is a time series with the following characteristics:
39+
40+
- The time the value was collected
41+
- The resource associated with the value
42+
- A namespace that acts like a category for the metric
43+
- A metric name
44+
- The value itself
45+
- Some metrics may have multiple dimensions as described in [multi-dimensional metrics][multi-metrics]. Custom metrics can have up to 10 dimensions.
46+
47+
## Examples
48+
49+
Get started with our examples.
50+
51+
## Contributing
52+
53+
This project welcomes contributions and suggestions. Most contributions require you to agree to a [Contributor License Agreement (CLA)][cla] declaring that you have the right to, and actually do, grant us the rights to use your contribution.
54+
55+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate
56+
the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to
57+
do this once across all repos using our CLA.
58+
59+
This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information, see
60+
the [Code of Conduct FAQ][coc_faq] or contact [[email protected]][coc_contact] with any additional questions or
61+
comments.
62+
63+
<!-- LINKS -->
64+
[azure_identity]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity
65+
[azure_sub]: https://azure.microsoft.com/free/
66+
[cloud_documentation]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud
67+
[default_cred_ref]: https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/azidentity#defaultazurecredential
68+
[monitor_docs]: https://learn.microsoft.com/azure/azure-monitor/
69+
[monitor_rest_docs]: https://learn.microsoft.com/rest/api/monitor/
70+
[multi-metrics]: https://learn.microsoft.com/azure/azure-monitor/essentials/data-platform-metrics#multi-dimensional-metrics
71+
[cla]: https://cla.microsoft.com
72+
[coc]: https://opensource.microsoft.com/codeofconduct/
73+
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
74+
[coc_contact]: mailto:[email protected]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"AssetsRepo": "Azure/azure-sdk-assets",
3+
"AssetsRepoPrefixPath": "go",
4+
"TagPrefix": "go/monitor/query/azmetrics",
5+
"Tag": "go/monitor/query/azmetrics_37251fcc33"
6+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
``` yaml
2+
title: Metrics Query Client
3+
clear-output-folder: false
4+
go: true
5+
input-file: https://github.com/Azure/azure-rest-api-specs/blob/0373f0edc4414fd402603fac51d0df93f1f70507/specification/monitor/data-plane/Microsoft.Insights/stable/2023-10-01/metricBatch.json
6+
license-header: MICROSOFT_MIT_NO_VERSION
7+
module: github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics
8+
openapi-type: "data-plane"
9+
output-folder: ../azmetrics
10+
security: "AADToken"
11+
use: "@autorest/[email protected]"
12+
inject-spans: true
13+
version: "^3.0.0"
14+
15+
directive:
16+
# rename Batch to QueryResources
17+
- rename-operation:
18+
from: MetricsBatch_Batch
19+
to: Metrics_QueryResources
20+
21+
# remove unused error models
22+
- from: swagger-document
23+
where:
24+
- $.definitions..ErrorResponse
25+
- $.definitions..ErrorDetail
26+
- $.definitions..ErrorAdditionalInfo
27+
transform: $["x-ms-external"] = true
28+
29+
# Rename MetricResultsResponse
30+
- rename-model:
31+
from: MetricResultsResponse
32+
to: MetricResults
33+
- from:
34+
- models.go
35+
- models_serde.go
36+
where: $
37+
transform: return $.replace(/MetricResultsValuesItem/g, "MetricValues");
38+
- from: swagger-document
39+
where: $.definitions.MetricResults.properties.values.items
40+
transform: $["description"] = "Metric data values."
41+
42+
# renaming or fixing the casing of struct fields and parameters
43+
- from: swagger-document
44+
where: $.definitions.Metric.properties.timeseries
45+
transform: $["x-ms-client-name"] = "TimeSeries"
46+
- from: swagger-document
47+
where: $.parameters.MetricNamespaceParameter
48+
transform: $["x-ms-client-name"] = "metricNamespace"
49+
- from: swagger-document
50+
where: $.parameters.MetricNamesParameter
51+
transform: $["x-ms-client-name"] = "metricNames"
52+
- from: swagger-document
53+
where: $.parameters.StartTimeParameter
54+
transform: $["x-ms-client-name"] = "StartTime"
55+
- from: swagger-document
56+
where: $.parameters.EndTimeParameter
57+
transform: $["x-ms-client-name"] = "EndTime"
58+
- from: swagger-document
59+
where: $.definitions.ResourceIdList.properties.resourceids
60+
transform: $["x-ms-client-name"] = "ResourceIDs"
61+
- from: swagger-document
62+
where: $.definitions.MetricResults.properties.values.items.properties.starttime
63+
transform: $["x-ms-client-name"] = "StartTime"
64+
- from: swagger-document
65+
where: $.definitions.MetricResults.properties.values.items.properties.endtime
66+
transform: $["x-ms-client-name"] = "EndTime"
67+
- from: swagger-document
68+
where: $.definitions.MetricResults.properties.values.items.properties.resourceid
69+
transform: $["x-ms-client-name"] = "ResourceID"
70+
- from: swagger-document
71+
where: $.definitions.MetricResults.properties.values.items.properties.resourceregion
72+
transform: $["x-ms-client-name"] = "ResourceRegion"
73+
- from: swagger-document
74+
where: $.definitions.MetricResults.properties.values.items.properties.value
75+
transform: $["x-ms-client-name"] = "Values"
76+
- from: swagger-document
77+
where: $.definitions.TimeSeriesElement.properties.metadatavalues
78+
transform: $["x-ms-client-name"] = "MetadataValues"
79+
- from: swagger-document
80+
where: $.parameters.OrderByParameter
81+
transform: $["x-ms-client-name"] = "OrderBy"
82+
- from: swagger-document
83+
where: $.parameters.RollUpByParameter
84+
transform: $["x-ms-client-name"] = "RollUpBy"
85+
- from: client.go
86+
where: $
87+
transform: return $.replace(/batchRequest/g, "resourceIDs");
88+
89+
# delete client name prefix from method options and response types
90+
- from:
91+
- client.go
92+
- options.go
93+
- response_types.go
94+
where: $
95+
transform: return $.replace(/Client(\w+)((?:Options|Response))/g, "$1$2");
96+
```

sdk/monitor/query/azmetrics/build.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build go1.18
2+
// +build go1.18
3+
4+
//go:generate autorest ./autorest.md
5+
//go:generate gofmt -w .
6+
7+
// Copyright (c) Microsoft Corporation. All rights reserved.
8+
// Licensed under the MIT License. See License.txt in the project root for license information.
9+
10+
package azmetrics

sdk/monitor/query/azmetrics/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file.
2+
trigger:
3+
branches:
4+
include:
5+
- main
6+
- feature/*
7+
- hotfix/*
8+
- release/*
9+
paths:
10+
include:
11+
- sdk/monitor/query/azmetrics
12+
13+
pr:
14+
branches:
15+
include:
16+
- main
17+
- feature/*
18+
- hotfix/*
19+
- release/*
20+
paths:
21+
include:
22+
- sdk/monitor/query/azmetrics
23+
24+
25+
stages:
26+
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
27+
parameters:
28+
ServiceDirectory: 'monitor/query/azmetrics'
29+
RunLiveTests: true
30+
UsePipelineProxy: false
31+
SupportedClouds: 'Public'

sdk/monitor/query/azmetrics/client.go

Lines changed: 113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)