Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ protected MetricsQueryClient() { }
public MetricsQueryClient(Azure.Core.TokenCredential credential) { }
public MetricsQueryClient(Azure.Core.TokenCredential credential, Azure.Monitor.Query.MetricsQueryClientOptions options) { }
public MetricsQueryClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.Monitor.Query.MetricsQueryClientOptions options = null) { }
public virtual Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Monitor.Query.Models.MetricNamespace>> GetMetricNamespaces(string resourceId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Monitor.Query.Models.MetricNamespace>>> GetMetricNamespacesAsync(string resourceId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Monitor.Query.Models.MetricDefinition>> GetMetrics(string resourceId, string metricsNamespace, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Monitor.Query.Models.MetricDefinition>>> GetMetricsAsync(string resourceId, string metricsNamespace, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Pageable<Azure.Monitor.Query.Models.MetricDefinition> GetMetricDefinitions(string resourceId, string metricsNamespace, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AsyncPageable<Azure.Monitor.Query.Models.MetricDefinition> GetMetricDefinitionsAsync(string resourceId, string metricsNamespace, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Pageable<Azure.Monitor.Query.Models.MetricNamespace> GetMetricNamespaces(string resourceId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AsyncPageable<Azure.Monitor.Query.Models.MetricNamespace> GetMetricNamespacesAsync(string resourceId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Monitor.Query.Models.MetricsQueryResult> Query(string resourceId, System.Collections.Generic.IEnumerable<string> metrics, Azure.Monitor.Query.MetricsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Monitor.Query.Models.MetricsQueryResult>> QueryAsync(string resourceId, System.Collections.Generic.IEnumerable<string> metrics, Azure.Monitor.Query.MetricsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<Compile Include="$(AzureCoreSharedSources)HashCodeBuilder.cs" LinkBase="Shared" />
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" LinkBase="Shared" />
<Compile Include="$(AzureCoreSharedSources)TypeBinder.cs" LinkBase="Shared" />
<Compile Include="$(AzureCoreSharedSources)PageResponseEnumerator.cs" LinkBase="Shared" />
</ItemGroup>

</Project>
116 changes: 64 additions & 52 deletions sdk/monitor/Azure.Monitor.Query/src/MetricsQueryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,25 @@ public virtual async Task<Response<MetricsQueryResult>> QueryAsync(string resour
/// <param name="metricsNamespace">The metric namespace.
/// For example: <c>Microsoft.OperationalInsights/workspaces</c>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
/// <returns>A list of metric definitions.</returns>
public virtual Response<IReadOnlyList<MetricDefinition>> GetMetrics(string resourceId, string metricsNamespace, CancellationToken cancellationToken = default)
/// <returns>A pageable collection of metric definitions.</returns>
public virtual Pageable<MetricDefinition> GetMetricDefinitions(string resourceId, string metricsNamespace, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsQueryClient)}.{nameof(GetMetrics)}");
scope.Start();
try
return PageResponseEnumerator.CreateEnumerable(_ =>
{
var response = _metricDefinitionsClient.List(resourceId, metricsNamespace, cancellationToken);
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsQueryClient)}.{nameof(GetMetricDefinitions)}");
scope.Start();
try
{
var response = _metricDefinitionsClient.List(resourceId, metricsNamespace, cancellationToken);

return Response.FromValue(response.Value.Value, response.GetRawResponse());
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
return Page<MetricDefinition>.FromValues(response.Value.Value, null, response.GetRawResponse());
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
});
}

/// <summary>
Expand All @@ -237,22 +240,25 @@ public virtual Response<IReadOnlyList<MetricDefinition>> GetMetrics(string resou
/// <param name="metricsNamespace">The metric namespace.
/// For example: <c>Microsoft.OperationalInsights/workspaces</c>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
/// <returns>A list of metric definitions.</returns>
public virtual async Task<Response<IReadOnlyList<MetricDefinition>>> GetMetricsAsync(string resourceId, string metricsNamespace, CancellationToken cancellationToken = default)
/// <returns>A pageable collection of metric definitions.</returns>
public virtual AsyncPageable<MetricDefinition> GetMetricDefinitionsAsync(string resourceId, string metricsNamespace, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsQueryClient)}.{nameof(GetMetrics)}");
scope.Start();
try
return PageResponseEnumerator.CreateAsyncEnumerable(async _ =>
{
var response = await _metricDefinitionsClient.ListAsync(resourceId, metricsNamespace, cancellationToken).ConfigureAwait(false);
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsQueryClient)}.{nameof(GetMetricDefinitions)}");
scope.Start();
try
{
var response = await _metricDefinitionsClient.ListAsync(resourceId, metricsNamespace, cancellationToken).ConfigureAwait(false);

return Response.FromValue(response.Value.Value, response.GetRawResponse());
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
return Page<MetricDefinition>.FromValues(response.Value.Value, null, response.GetRawResponse());
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
});
}

/// <summary>
Expand All @@ -265,45 +271,51 @@ public virtual async Task<Response<IReadOnlyList<MetricDefinition>>> GetMetricsA
/// <c>/subscriptions/faa080af-c1d8-40ad-9cce-e1a450ca5b57/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachines/myvm</c><br/>
/// </param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
/// <returns>A list of metric namespaces.</returns>
public virtual Response<IReadOnlyList<MetricNamespace>> GetMetricNamespaces(string resourceId, CancellationToken cancellationToken = default)
/// <returns>A pageable collection of metric namespaces.</returns>
public virtual Pageable<MetricNamespace> GetMetricNamespaces(string resourceId, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsQueryClient)}.{nameof(GetMetricNamespaces)}");
scope.Start();
try
return PageResponseEnumerator.CreateEnumerable(_ =>
{
var response = _namespacesRestClient.List(resourceId, cancellationToken: cancellationToken);
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsQueryClient)}.{nameof(GetMetricNamespaces)}");
scope.Start();
try
{
var response = _namespacesRestClient.List(resourceId, cancellationToken: cancellationToken);

return Response.FromValue(response.Value.Value, response.GetRawResponse());
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
return Page<MetricNamespace>.FromValues(response.Value.Value, null, response.GetRawResponse());
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
});
}

/// <summary>
/// Gets metric namespaces for a particular resource.
/// </summary>
/// <param name="resourceId">The resource name.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
/// <returns>A list of metric namespaces.</returns>
public virtual async Task<Response<IReadOnlyList<MetricNamespace>>> GetMetricNamespacesAsync(string resourceId, CancellationToken cancellationToken = default)
/// <returns>A pageable collection of metric namespaces.</returns>
public virtual AsyncPageable<MetricNamespace> GetMetricNamespacesAsync(string resourceId, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsQueryClient)}.{nameof(GetMetricNamespaces)}");
scope.Start();
try
return PageResponseEnumerator.CreateAsyncEnumerable(async _ =>
{
var response = await _namespacesRestClient.ListAsync(resourceId, cancellationToken: cancellationToken).ConfigureAwait(false);
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsQueryClient)}.{nameof(GetMetricNamespaces)}");
scope.Start();
try
{
var response = await _namespacesRestClient.ListAsync(resourceId, cancellationToken: cancellationToken).ConfigureAwait(false);

return Response.FromValue(response.Value.Value, response.GetRawResponse());
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
return Page<MetricNamespace>.FromValues(response.Value.Value, null, response.GetRawResponse());
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
});
}

private static string GetAggregation(MetricsQueryOptions options)
Expand Down
8 changes: 4 additions & 4 deletions sdk/monitor/Azure.Monitor.Query/src/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Run `dotnet build /t:GenerateCode` to generate code.
``` yaml
title: Query
input-file:
- https://github.com/Azure/azure-rest-api-specs/blob/8dff86df71bee429af84ea4713288ef3cdd1db2f/specification/operationalinsights/data-plane/Microsoft.OperationalInsights/preview/2021-05-19_Preview/OperationalInsights.json
- https://github.com/Azure/azure-rest-api-specs/blob/8dff86df71bee429af84ea4713288ef3cdd1db2f/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-01-01/metricDefinitions_API.json
- https://github.com/Azure/azure-rest-api-specs/blob/8dff86df71bee429af84ea4713288ef3cdd1db2f/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-01-01/metrics_API.json
- https://github.com/Azure/azure-rest-api-specs/blob/8dff86df71bee429af84ea4713288ef3cdd1db2f/specification/monitor/resource-manager/Microsoft.Insights/preview/2017-12-01-preview/metricNamespaces_API.json
- https://github.com/Azure/azure-rest-api-specs/blob/dba6ed1f03bda88ac6884c0a883246446cc72495/specification/operationalinsights/data-plane/Microsoft.OperationalInsights/preview/2021-05-19_Preview/OperationalInsights.json
- https://github.com/Azure/azure-rest-api-specs/blob/dba6ed1f03bda88ac6884c0a883246446cc72495/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-01-01/metricDefinitions_API.json
- https://github.com/Azure/azure-rest-api-specs/blob/dba6ed1f03bda88ac6884c0a883246446cc72495/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-01-01/metrics_API.json
- https://github.com/Azure/azure-rest-api-specs/blob/dba6ed1f03bda88ac6884c0a883246446cc72495/specification/monitor/resource-manager/Microsoft.Insights/preview/2017-12-01-preview/metricNamespaces_API.json
modelerfour:
lenient-model-deduplication: true
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public async Task CanListMetrics()
{
var client = CreateClient();

var results = await client.GetMetricsAsync(TestEnvironment.MetricsResource, TestEnvironment.MetricsNamespace);
var results = await client.GetMetricDefinitionsAsync(TestEnvironment.MetricsResource, TestEnvironment.MetricsNamespace).ToEnumerableAsync();

CollectionAssert.IsNotEmpty(results.Value);
CollectionAssert.IsNotEmpty(results);
}

[RecordedTest]
Expand Down Expand Up @@ -252,14 +252,14 @@ public async Task CanListNamespacesMetrics()
var client = CreateClient();

var results = await client.GetMetricNamespacesAsync(
TestEnvironment.MetricsResource);
TestEnvironment.MetricsResource).ToEnumerableAsync();

Assert.True(results.Value.Any(ns =>
Assert.True(results.Any(ns =>
ns.Name == "Microsoft.OperationalInsights-workspaces" &&
ns.Type == "Microsoft.Insights/metricNamespaces" &&
ns.FullyQualifiedName == "Microsoft.OperationalInsights/workspaces"));

Assert.True(results.Value.Any(ns =>
Assert.True(results.Any(ns =>
ns.Name == "Cows" &&
ns.Type == "Microsoft.Insights/metricNamespaces" &&
ns.FullyQualifiedName == "Cows"));
Expand Down
2 changes: 1 addition & 1 deletion sdk/monitor/Azure.Monitor.Query/tests/MetricsTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private async Task SendData(MetricsSenderClient senderClient)

private async Task<bool> MetricsPropagated(MetricsQueryClient metricQueryClient)
{
var nsExists = (await metricQueryClient.GetMetricNamespacesAsync(_testEnvironment.MetricsResource)).Value.Any(ns => ns.Name == MetricNamespace);
var nsExists = (await metricQueryClient.GetMetricNamespacesAsync(_testEnvironment.MetricsResource).ToEnumerableAsync()).Any(ns => ns.Name == MetricNamespace);

if (!nsExists)
{
Expand Down