-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Azure.Monitor.Query: invalid date string format in MetricsClient (#45998
- Loading branch information
Showing
10 changed files
with
227 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
sdk/monitor/Azure.Monitor.Query/tests/MetricsClientLiveTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Azure.Monitor.Query.Models; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Monitor.Query.Tests | ||
{ | ||
public class MetricsClientLiveTests : RecordedTestBase<MonitorQueryTestEnvironment> | ||
{ | ||
private MetricsTestData _testData; | ||
|
||
public MetricsClientLiveTests(bool isAsync) : base(isAsync) | ||
{ | ||
} | ||
|
||
private MetricsClient CreateMetricsClient() | ||
{ | ||
return InstrumentClient(new MetricsClient( | ||
new Uri(TestEnvironment.ConstructMetricsClientUri()), | ||
TestEnvironment.Credential, | ||
InstrumentClientOptions(new MetricsClientOptions() | ||
{ | ||
Audience = TestEnvironment.GetMetricsClientAudience() | ||
}) | ||
)); | ||
} | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_testData = new MetricsTestData(TestEnvironment, Recording.UtcNow); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task MetricsQueryResourcesAsync() | ||
{ | ||
MetricsClient client = CreateMetricsClient(); | ||
|
||
var resourceId = TestEnvironment.StorageAccountId; | ||
|
||
Response<MetricsQueryResourcesResult> metricsResultsResponse = await client.QueryResourcesAsync( | ||
resourceIds: new List<ResourceIdentifier> { new ResourceIdentifier(resourceId) }, | ||
metricNames: new List<string> { "Ingress" }, | ||
metricNamespace: "Microsoft.Storage/storageAccounts").ConfigureAwait(false); | ||
|
||
Assert.AreEqual(200, metricsResultsResponse.GetRawResponse().Status); | ||
MetricsQueryResourcesResult metricsQueryResults = metricsResultsResponse.Value; | ||
Assert.AreEqual(1, metricsQueryResults.Values.Count); | ||
Assert.AreEqual(TestEnvironment.StorageAccountId + "/providers/Microsoft.Insights/metrics/Ingress", metricsQueryResults.Values[0].Metrics[0].Id); | ||
Assert.AreEqual("Microsoft.Storage/storageAccounts", metricsQueryResults.Values[0].Namespace); | ||
for (int i = 0; i < metricsQueryResults.Values.Count; i++) | ||
{ | ||
foreach (MetricResult value in metricsQueryResults.Values[i].Metrics) | ||
{ | ||
for (int j = 0; j < value.TimeSeries.Count; j++) | ||
{ | ||
Assert.GreaterOrEqual(value.TimeSeries[j].Values[i].Total, 0); | ||
} | ||
} | ||
} | ||
} | ||
|
||
[RecordedTest] | ||
public async Task MetricsQueryResourcesWithStartEndTimeRangeAsync() | ||
{ | ||
MetricsClient client = CreateMetricsClient(); | ||
|
||
var resourceId = TestEnvironment.StorageAccountId; | ||
|
||
var timeRange = new QueryTimeRange( | ||
start: Recording.UtcNow.Subtract(TimeSpan.FromHours(4)), | ||
end: Recording.UtcNow | ||
); | ||
|
||
Response<MetricsQueryResourcesResult> metricsResultsResponse = await client.QueryResourcesAsync( | ||
resourceIds: new List<ResourceIdentifier> { new ResourceIdentifier(resourceId) }, | ||
metricNames: new List<string> { "Ingress" }, | ||
metricNamespace: "Microsoft.Storage/storageAccounts", | ||
options: new MetricsQueryResourcesOptions { TimeRange = timeRange} ).ConfigureAwait(false); | ||
|
||
Assert.AreEqual(200, metricsResultsResponse.GetRawResponse().Status); | ||
MetricsQueryResourcesResult metricsQueryResults = metricsResultsResponse.Value; | ||
Assert.AreEqual(1, metricsQueryResults.Values.Count); | ||
Assert.AreEqual(TestEnvironment.StorageAccountId + "/providers/Microsoft.Insights/metrics/Ingress", metricsQueryResults.Values[0].Metrics[0].Id); | ||
Assert.AreEqual("Microsoft.Storage/storageAccounts", metricsQueryResults.Values[0].Namespace); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task MetricsQueryResourcesWithStartDurationTimeRangeAsync() | ||
{ | ||
MetricsClient client = CreateMetricsClient(); | ||
|
||
var resourceId = TestEnvironment.StorageAccountId; | ||
|
||
var timeRange = new QueryTimeRange( | ||
start: Recording.UtcNow.Subtract(TimeSpan.FromHours(4)), | ||
duration: TimeSpan.FromHours(4) | ||
); | ||
|
||
Response<MetricsQueryResourcesResult> metricsResultsResponse = await client.QueryResourcesAsync( | ||
resourceIds: new List<ResourceIdentifier> { new ResourceIdentifier(resourceId) }, | ||
metricNames: new List<string> { "Ingress" }, | ||
metricNamespace: "Microsoft.Storage/storageAccounts", | ||
options: new MetricsQueryResourcesOptions { TimeRange = timeRange }).ConfigureAwait(false); | ||
|
||
Assert.AreEqual(200, metricsResultsResponse.GetRawResponse().Status); | ||
MetricsQueryResourcesResult metricsQueryResults = metricsResultsResponse.Value; | ||
Assert.AreEqual(1, metricsQueryResults.Values.Count); | ||
Assert.AreEqual(TestEnvironment.StorageAccountId + "/providers/Microsoft.Insights/metrics/Ingress", metricsQueryResults.Values[0].Metrics[0].Id); | ||
Assert.AreEqual("Microsoft.Storage/storageAccounts", metricsQueryResults.Values[0].Namespace); | ||
} | ||
|
||
[RecordedTest] | ||
[SyncOnly] | ||
public void MetricsQueryResourcesWithEndDurationTimeRange() | ||
{ | ||
MetricsClient client = CreateMetricsClient(); | ||
|
||
var resourceId = TestEnvironment.StorageAccountId; | ||
|
||
var timeRange = new QueryTimeRange( | ||
end: Recording.UtcNow, | ||
duration: TimeSpan.FromHours(4) | ||
); | ||
|
||
Assert.Throws<AggregateException>(() => | ||
client.QueryResources( | ||
resourceIds: new List<ResourceIdentifier> { new ResourceIdentifier(resourceId) }, | ||
metricNames: new List<string> { "Ingress" }, | ||
metricNamespace: "Microsoft.Storage/storageAccounts", | ||
options: new MetricsQueryResourcesOptions { TimeRange = timeRange })); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task MetricsQueryResourcesWithDurationTimeRangeAsync() | ||
{ | ||
MetricsClient client = CreateMetricsClient(); | ||
|
||
var resourceId = TestEnvironment.StorageAccountId; | ||
|
||
var timeRange = new QueryTimeRange( | ||
duration: TimeSpan.FromHours(4) | ||
); | ||
|
||
Response<MetricsQueryResourcesResult> metricsResultsResponse = await client.QueryResourcesAsync( | ||
resourceIds: new List<ResourceIdentifier> { new ResourceIdentifier(resourceId) }, | ||
metricNames: new List<string> { "Ingress" }, | ||
metricNamespace: "Microsoft.Storage/storageAccounts", | ||
options: new MetricsQueryResourcesOptions { TimeRange = timeRange }).ConfigureAwait(false); | ||
|
||
Assert.AreEqual(200, metricsResultsResponse.GetRawResponse().Status); | ||
MetricsQueryResourcesResult metricsQueryResults = metricsResultsResponse.Value; | ||
Assert.AreEqual(1, metricsQueryResults.Values.Count); | ||
Assert.AreEqual(TestEnvironment.StorageAccountId + "/providers/Microsoft.Insights/metrics/Ingress", metricsQueryResults.Values[0].Metrics[0].Id); | ||
Assert.AreEqual("Microsoft.Storage/storageAccounts", metricsQueryResults.Values[0].Namespace); | ||
} | ||
|
||
[Test] | ||
[SyncOnly] | ||
public void MetricsQueryResourcesInvalid() | ||
{ | ||
MetricsClient client = CreateMetricsClient(); | ||
|
||
Assert.Throws<ArgumentException>(() => | ||
client.QueryResources( | ||
resourceIds: new List<ResourceIdentifier>(), | ||
metricNames: new List<string> { "Ingress" }, | ||
metricNamespace: "Microsoft.Storage/storageAccounts")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.