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

[monitor query] move metrics dataplane to new azmetrics module #22366

Merged
merged 8 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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: 4 additions & 0 deletions eng/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
{
"Name": "security/keyvault/azadmin",
"CoverageGoal": 0.80
},
{
"Name": "monitor/query/azmetrics",
"CoverageGoal": 0.75
}
]
}
5 changes: 5 additions & 0 deletions sdk/monitor/query/azmetrics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release History

## 0.1.0 (2024-02-13)

* This is the initial release of the `azmetrics` module
21 changes: 21 additions & 0 deletions sdk/monitor/query/azmetrics/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
78 changes: 78 additions & 0 deletions sdk/monitor/query/azmetrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Azure Monitor Metrics client module for Go

Source code | Package (pkg.go.dev) | [REST API documentation][monitor_rest_docs] | [Product documentation][monitor_docs] | Samples

## Getting started

### Prerequisites

* Go version 1.18 or higher - [Install Go](https://go.dev/doc/install)
* Azure subscription - [Create a free account][azure_sub]
* The resource URI of an Azure resource (Storage Account, Key Vault, CosmosDB, etc.) that you plan to monitor

### Install the packages

Install the `azmetrics` and `azidentity` modules with `go get`:

```bash
go get github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics
go get github.com/Azure/azure-sdk-for-go/sdk/azidentity
```

The [azidentity][azure_identity] module is used for client authentication.

### Authentication

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.

The clients default to the Azure public cloud. For other cloud configurations, see the [cloud][cloud_documentation] package documentation.

#### Create a client

Example client

## Key concepts

### Metrics data structure

Each set of metric values is a time series with the following characteristics:

- The time the value was collected
- The resource associated with the value
- A namespace that acts like a category for the metric
- A metric name
- 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.

## Examples

Get started with our examples.

## Contributing

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.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate
the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to
do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information, see
the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or
comments.

<!-- LINKS -->
[azure_identity]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity
[azure_sub]: https://azure.microsoft.com/free/
[azure_monitor_overview]: https://learn.microsoft.com/azure/azure-monitor/overview
gracewilcox marked this conversation as resolved.
Show resolved Hide resolved
[cloud_documentation]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud
[default_cred_ref]: https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/azidentity#defaultazurecredential
[go_samples]: (https://github.com/Azure-Samples/azure-sdk-for-go-samples)
[metrics_overview]: https://learn.microsoft.com/azure/azure-monitor/essentials/data-platform-metrics
[metric_namespaces]: https://learn.microsoft.com/azure/azure-monitor/reference/supported-metrics/metrics-index#metrics-by-resource-provider
gracewilcox marked this conversation as resolved.
Show resolved Hide resolved
[monitor_docs]: https://learn.microsoft.com/azure/azure-monitor/
[monitor_rest_docs]: https://learn.microsoft.com/rest/api/monitor/
[multi-metrics]: https://learn.microsoft.com/azure/azure-monitor/essentials/data-platform-metrics#multi-dimensional-metrics
[cla]: https://cla.microsoft.com
[coc]: https://opensource.microsoft.com/codeofconduct/
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[coc_contact]: mailto:opencode@microsoft.com
6 changes: 6 additions & 0 deletions sdk/monitor/query/azmetrics/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/monitor/query/azmetrics",
"Tag": "go/monitor/query/azmetrics_37251fcc33"
}
96 changes: 96 additions & 0 deletions sdk/monitor/query/azmetrics/autorest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
``` yaml
title: Metrics Query Client
clear-output-folder: false
go: true
input-file: https://github.com/Azure/azure-rest-api-specs/blob/0373f0edc4414fd402603fac51d0df93f1f70507/specification/monitor/data-plane/Microsoft.Insights/stable/2023-10-01/metricBatch.json
license-header: MICROSOFT_MIT_NO_VERSION
module: github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics
openapi-type: "data-plane"
output-folder: ../azmetrics
security: "AADToken"
use: "@autorest/go@4.0.0-preview.61"
inject-spans: true
version: "^3.0.0"

directive:
# rename Batch to QueryResources
- rename-operation:
from: MetricsBatch_Batch
to: Metrics_QueryResources

# remove unused error models
- from: swagger-document
where:
- $.definitions..ErrorResponse
- $.definitions..ErrorDetail
- $.definitions..ErrorAdditionalInfo
transform: $["x-ms-external"] = true

# 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."

# renaming or fixing the casing of struct fields and parameters
- from: swagger-document
where: $.definitions.Metric.properties.timeseries
transform: $["x-ms-client-name"] = "TimeSeries"
- from: swagger-document
where: $.parameters.MetricNamespaceParameter
transform: $["x-ms-client-name"] = "metricNamespace"
- from: swagger-document
where: $.parameters.MetricNamesParameter
transform: $["x-ms-client-name"] = "metricNames"
- 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"
- from: swagger-document
where: $.definitions.TimeSeriesElement.properties.metadatavalues
transform: $["x-ms-client-name"] = "MetadataValues"
- from: swagger-document
where: $.parameters.OrderByParameter
transform: $["x-ms-client-name"] = "OrderBy"
- from: swagger-document
where: $.parameters.RollUpByParameter
transform: $["x-ms-client-name"] = "RollUpBy"
- from: client.go
where: $
transform: return $.replace(/batchRequest/g, "resourceIDs");

# delete client name prefix from method options and response types
- from:
- client.go
- options.go
- response_types.go
where: $
transform: return $.replace(/Client(\w+)((?:Options|Response))/g, "$1$2");
```
10 changes: 10 additions & 0 deletions sdk/monitor/query/azmetrics/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build go1.18
// +build go1.18

//go:generate autorest ./autorest.md
//go:generate gofmt -w .

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package azmetrics
31 changes: 31 additions & 0 deletions sdk/monitor/query/azmetrics/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file.
trigger:
branches:
include:
- main
- feature/*
- hotfix/*
- release/*
paths:
include:
- sdk/monitor/query/azmetrics

pr:
branches:
include:
- main
- feature/*
- hotfix/*
- release/*
paths:
include:
- sdk/monitor/query/azmetrics


stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'monitor/query/azmetrics'
RunLiveTests: true
UsePipelineProxy: false
SupportedClouds: 'Public'
113 changes: 113 additions & 0 deletions sdk/monitor/query/azmetrics/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading