Skip to content

Commit

Permalink
[Azure.Monitor.Query] Add Extensions (#34968)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip
  • Loading branch information
nisha-bhatia authored Mar 21, 2023
1 parent 296af20 commit a9a133a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 9 deletions.
10 changes: 2 additions & 8 deletions sdk/monitor/Azure.Monitor.Query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# Release History

## 1.2.0-beta.1 (Unreleased)

## 1.2.0-beta.1 (2023-04-11)
### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
Added Client Builder Extension methods for `LogsQueryClient` and `MetricsQueryClient`

## 1.1.0 (2022-01-25)

Expand Down
5 changes: 5 additions & 0 deletions sdk/monitor/Azure.Monitor.Query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ All client instance methods are thread-safe and independent of each other ([guid
- [Metrics query](#metrics-query)
- [Handle metrics query response](#handle-metrics-query-response)
- [Query metrics with options](#query-metrics-with-options)
- [Register the client with dependency injection](#register-the-client-with-dependency-injection)

### Logs query

Expand Down Expand Up @@ -504,6 +505,10 @@ foreach (MetricTimeSeriesElement element in metric.TimeSeries)
}
```

#### Register the client with dependency injection

To register `LogsQueryClient` with the dependency injection (DI) container, invoke the `AddLogsQueryClient` method. To register `MetricsQueryClient` with the dependency injection (DI) container, invoke the `AddMetricsQueryClient` method. For more information, see [Register client](https://learn.microsoft.com/dotnet/azure/sdk/dependency-injection#register-client).

## Troubleshooting

To diagnose various failure scenarios, see the [troubleshooting guide](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/monitor/Azure.Monitor.Query/TROUBLESHOOTING.md).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,16 @@ public static partial class MonitorQueryModelFactory
public static Azure.Monitor.Query.Models.MetricValue MetricValue(System.DateTimeOffset timeStamp = default(System.DateTimeOffset), double? average = default(double?), double? minimum = default(double?), double? maximum = default(double?), double? total = default(double?), double? count = default(double?)) { throw null; }
}
}
namespace Microsoft.Extensions.Azure
{
public static partial class LogsQueryClientBuilderExtensions
{
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Monitor.Query.LogsQueryClient, Azure.Monitor.Query.LogsQueryClientOptions> AddLogsQueryClient<TBuilder>(this TBuilder builder, System.Uri endpoint) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithCredential { throw null; }
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Monitor.Query.LogsQueryClient, Azure.Monitor.Query.LogsQueryClientOptions> AddLogsQueryClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithConfiguration<TConfiguration> { throw null; }
}
public static partial class MetricsQueryClientBuilderExtensions
{
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Monitor.Query.MetricsQueryClient, Azure.Monitor.Query.MetricsQueryClientOptions> AddMetricsQueryClient<TBuilder>(this TBuilder builder, System.Uri endpoint) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithCredential { throw null; }
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Monitor.Query.MetricsQueryClient, Azure.Monitor.Query.MetricsQueryClientOptions> AddMetricsQueryClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithConfiguration<TConfiguration> { throw null; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core.Extensions;
using Azure.Monitor.Query;

namespace Microsoft.Extensions.Azure
{
/// <summary> Extension methods to add <see cref="LogsQueryClient"/> to client builder. </summary>
public static class LogsQueryClientBuilderExtensions
{
/// <summary> Registers a <see cref="LogsQueryClient"/> instance. </summary>
/// <param name="builder"> The builder to register with. </param>
/// <param name="endpoint"> The resource manager service endpoint to use. For example <c>https://management.azure.com/</c> for public cloud. </param>
public static IAzureClientBuilder<LogsQueryClient, LogsQueryClientOptions> AddLogsQueryClient<TBuilder>(this TBuilder builder, Uri endpoint)
where TBuilder : IAzureClientFactoryBuilderWithCredential
{
return builder.RegisterClientFactory<LogsQueryClient, LogsQueryClientOptions>((options, cred) => new LogsQueryClient(endpoint, cred, options));
}

/// <summary> Registers a <see cref="LogsQueryClient"/> instance. </summary>
/// <param name="builder"> The builder to register with. </param>
/// <param name="configuration"> The configuration values. </param>
public static IAzureClientBuilder<LogsQueryClient, LogsQueryClientOptions> AddLogsQueryClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration)
where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration>
{
return builder.RegisterClientFactory<LogsQueryClient, LogsQueryClientOptions>(configuration);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core.Extensions;
using Azure.Monitor.Query;

namespace Microsoft.Extensions.Azure
{
/// <summary> Extension methods to add <see cref="MetricsQueryClient"/> to client builder. </summary>
public static class MetricsQueryClientBuilderExtensions
{
/// <summary> Registers a <see cref="MetricsQueryClient"/> instance. </summary>
/// <param name="builder"> The builder to register with. </param>
/// <param name="endpoint"> The resource manager service endpoint to use. For example <c>https://management.azure.com/</c> for public cloud. </param>
public static IAzureClientBuilder<MetricsQueryClient, MetricsQueryClientOptions> AddMetricsQueryClient<TBuilder>(this TBuilder builder, Uri endpoint)
where TBuilder : IAzureClientFactoryBuilderWithCredential
{
return builder.RegisterClientFactory<MetricsQueryClient, MetricsQueryClientOptions>((options, cred) => new MetricsQueryClient(endpoint, cred, options));
}

/// <summary> Registers a <see cref="MetricsQueryClient"/> instance. </summary>
/// <param name="builder"> The builder to register with. </param>
/// <param name="configuration"> The configuration values. </param>
public static IAzureClientBuilder<MetricsQueryClient, MetricsQueryClientOptions> AddMetricsQueryClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration)
where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration>
{
return builder.RegisterClientFactory<MetricsQueryClient, MetricsQueryClientOptions>(configuration);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public async Task CanQueryWithStatistics(bool include)
if (include)
{
using JsonDocument document = JsonDocument.Parse(response.Value.GetStatistics());
Assert.Greater(document.RootElement.GetProperty("query").GetProperty("executionTime").GetDouble(), 0);
Assert.GreaterOrEqual(document.RootElement.GetProperty("query").GetProperty("executionTime").GetDouble(), 0);
}
else
{
Expand Down

0 comments on commit a9a133a

Please sign in to comment.