Skip to content

Commit 5a3e03a

Browse files
authored
[MetricsAdvisor] Moving to new MA resource (Azure#25406)
1 parent 62ea45e commit 5a3e03a

File tree

128 files changed

+27203
-295363
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+27203
-295363
lines changed

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ dataFeed.Schema = new DataFeedSchema();
228228
dataFeed.Schema.MetricColumns.Add(new DataFeedMetric("cost"));
229229
dataFeed.Schema.MetricColumns.Add(new DataFeedMetric("revenue"));
230230
dataFeed.Schema.DimensionColumns.Add(new DataFeedDimension("category"));
231-
dataFeed.Schema.DimensionColumns.Add(new DataFeedDimension("city"));
231+
dataFeed.Schema.DimensionColumns.Add(new DataFeedDimension("region"));
232232

233233
dataFeed.IngestionSettings = new DataFeedIngestionSettings(DateTimeOffset.Parse("2020-01-01T00:00:00Z"));
234234

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/tests/MetricsAdvisorClient/AnomalyDetectionLiveTests.cs

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public async Task GetAnomaliesForDetectionConfigurationWithOptionalFilter()
6262
Filter = new AnomalyFilter(AnomalySeverity.Medium, AnomalySeverity.Medium)
6363
};
6464

65-
var dimensions = new Dictionary<string, string>() { { "city", "Delhi" }, { "category", "Handmade" } };
65+
var dimensions = new Dictionary<string, string>() { { "region", "Delhi" }, { "category", "Handmade" } };
6666
var groupKey1 = new DimensionKey(dimensions);
6767

68-
dimensions = new Dictionary<string, string>() { { "city", "Kolkata" } };
68+
dimensions = new Dictionary<string, string>() { { "region", "Kolkata" } };
6969
var groupKey2 = new DimensionKey(dimensions);
7070

7171
options.Filter.DimensionKeys.Add(groupKey1);
@@ -88,10 +88,10 @@ public async Task GetAnomaliesForDetectionConfigurationWithOptionalFilter()
8888

8989
ValidateSeriesKey(anomaly.SeriesKey);
9090

91-
anomaly.SeriesKey.TryGetValue("city", out string city);
91+
anomaly.SeriesKey.TryGetValue("region", out string region);
9292
anomaly.SeriesKey.TryGetValue("category", out string category);
9393

94-
Assert.That((city == "Delhi" && category == "Handmade") || city == "Kolkata");
94+
Assert.That((region == "Delhi" && category == "Handmade") || region == "Kolkata");
9595

9696
if (++anomalyCount >= MaximumSamplesCount)
9797
{
@@ -144,10 +144,10 @@ public async Task GetIncidentsForDetectionConfigurationWithOptionalDimensionFilt
144144

145145
var options = new GetIncidentsForDetectionConfigurationOptions(SamplingStartTime, SamplingEndTime);
146146

147-
var dimensions = new Dictionary<string, string>() { { "city", "Delhi" }, { "category", "Handmade" } };
147+
var dimensions = new Dictionary<string, string>() { { "region", "Delhi" }, { "category", "Handmade" } };
148148
var groupKey1 = new DimensionKey(dimensions);
149149

150-
dimensions = new Dictionary<string, string>() { { "city", "Kolkata" } };
150+
dimensions = new Dictionary<string, string>() { { "region", "Kolkata" } };
151151
var groupKey2 = new DimensionKey(dimensions);
152152

153153
options.DimensionKeys.Add(groupKey1);
@@ -170,10 +170,10 @@ public async Task GetIncidentsForDetectionConfigurationWithOptionalDimensionFilt
170170

171171
ValidateSeriesKey(incident.RootSeriesKey);
172172

173-
incident.RootSeriesKey.TryGetValue("city", out string city);
173+
incident.RootSeriesKey.TryGetValue("region", out string region);
174174
incident.RootSeriesKey.TryGetValue("category", out string category);
175175

176-
Assert.That((city == "Delhi" && category == "Handmade") || city == "Kolkata");
176+
Assert.That((region == "Delhi" && category == "Handmade") || region == "Kolkata");
177177

178178
if (++incidentCount >= MaximumSamplesCount)
179179
{
@@ -217,7 +217,7 @@ public async Task GetIncidentRootCausesForIncidentFromDetectionConfiguration()
217217
// We already know the the incident we want to get, so apply filters to make the
218218
// service call cheaper.
219219

220-
var dimensions = new Dictionary<string, string>() { { "city", "__SUM__" }, { "category", "Grocery & Gourmet Food" } };
220+
var dimensions = new Dictionary<string, string>() { { "region", "__SUM__" }, { "category", "Grocery & Gourmet Food" } };
221221
var groupKey = new DimensionKey(dimensions);
222222

223223
options.DimensionKeys.Add(groupKey);
@@ -251,7 +251,7 @@ public async Task GetIncidentRootCausesForIncidentFromDetectionConfiguration()
251251
[RecordedTest]
252252
public async Task GetIncidentRootCausesForIncidentFromAlert()
253253
{
254-
const string incidentId = "5a0692283edccf37ce825b3a8d475f4e-17571a77000";
254+
const string incidentId = "30612c95b4c216ef418956c5c6162691-17bbd8dec00";
255255

256256
MetricsAdvisorClient client = GetMetricsAdvisorClient();
257257

@@ -293,7 +293,7 @@ public async Task GetIncidentRootCausesForIncidentFromAlert()
293293
[TestCase(false)]
294294
public async Task GetAnomalyDimensionValuesWithMinimumSetup(bool useTokenCredential)
295295
{
296-
const string dimensionName = "city";
296+
const string dimensionName = "region";
297297

298298
MetricsAdvisorClient client = GetMetricsAdvisorClient(useTokenCredential);
299299

@@ -317,7 +317,7 @@ public async Task GetAnomalyDimensionValuesWithMinimumSetup(bool useTokenCredent
317317
[RecordedTest]
318318
public async Task GetAnomalyDimensionValuesWithOptionalDimensionFilter()
319319
{
320-
const string dimensionName = "city";
320+
const string dimensionName = "region";
321321

322322
MetricsAdvisorClient client = GetMetricsAdvisorClient();
323323

@@ -349,10 +349,10 @@ public async Task GetMetricEnrichedSeriesData(bool useTokenCredential)
349349
{
350350
MetricsAdvisorClient client = GetMetricsAdvisorClient(useTokenCredential);
351351

352-
var dimensions = new Dictionary<string, string>() { { "city", "Delhi" }, { "category", "Handmade" } };
352+
var dimensions = new Dictionary<string, string>() { { "region", "Delhi" }, { "category", "Handmade" } };
353353
var seriesKey1 = new DimensionKey(dimensions);
354354

355-
dimensions = new Dictionary<string, string>() { { "city", "Kolkata" }, { "category", "__SUM__" } };
355+
dimensions = new Dictionary<string, string>() { { "region", "Kolkata" }, { "category", "__SUM__" } };
356356
var seriesKey2 = new DimensionKey(dimensions);
357357

358358
var seriesKeys = new List<DimensionKey>() { seriesKey1, seriesKey2 };
@@ -387,10 +387,19 @@ public async Task GetMetricEnrichedSeriesData(bool useTokenCredential)
387387
returnedKeys.Add(seriesData.SeriesKey);
388388
}
389389

390-
IEnumerable<List<KeyValuePair<string, string>>> expectedKvps = seriesKeys.Select(key => key.ToList());
391-
IEnumerable<List<KeyValuePair<string, string>>> returnedKvps = returnedKeys.Select(key => key.ToList());
390+
// Making sure count is exactly 2 because the logic below relies on that.
391+
Assert.That(seriesKeys.Count, Is.EqualTo(2));
392+
Assert.That(returnedKeys.Count, Is.EqualTo(2));
392393

393-
Assert.That(returnedKvps, Is.EquivalentTo(expectedKvps));
394+
if (AreSame(seriesKeys[0], returnedKeys[0]))
395+
{
396+
Assert.That(seriesKeys[1], Is.EquivalentTo(returnedKeys[1]));
397+
}
398+
else
399+
{
400+
Assert.That(seriesKeys[0], Is.EquivalentTo(returnedKeys[1]));
401+
Assert.That(seriesKeys[1], Is.EquivalentTo(returnedKeys[0]));
402+
}
394403
}
395404

396405
private void ValidateIncidentRootCause(IncidentRootCause rootCause)
@@ -406,5 +415,23 @@ private void ValidateIncidentRootCause(IncidentRootCause rootCause)
406415

407416
ValidateSeriesKey(rootCause.SeriesKey);
408417
}
418+
419+
private bool AreSame(DimensionKey left, DimensionKey right)
420+
{
421+
if (left.Dimension.Count != right.Dimension.Count)
422+
{
423+
return false;
424+
}
425+
426+
foreach (KeyValuePair<string, string> kvp in left)
427+
{
428+
if (!right.TryGetValue(kvp.Key, out string value) || value != kvp.Value)
429+
{
430+
return false;
431+
}
432+
}
433+
434+
return true;
435+
}
409436
}
410437
}

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/tests/MetricsAdvisorClient/MetricFeedbackLiveTests.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace Azure.AI.MetricsAdvisor.Tests
1212
{
1313
public class MetricFeedbackLiveTests : MetricsAdvisorLiveTestBase
1414
{
15-
private const string ExpectedCity = "Delhi";
15+
private const string ExpectedRegion = "Cairo";
1616

17-
private const string ExpectedCategory = "Handmade";
17+
private const string ExpectedCategory = "Shoes Handbags & Sunglasses";
1818

1919
public MetricFeedbackLiveTests(bool isAsync) : base(isAsync)
2020
{
@@ -31,7 +31,7 @@ public async Task AddAndGetAnomalyFeedbackWithMinimumSetup(bool useTokenCredenti
3131
{
3232
MetricsAdvisorClient client = GetMetricsAdvisorClient(useTokenCredential);
3333

34-
var dimensions = new Dictionary<string, string>() { { "city", ExpectedCity }, { "category", ExpectedCategory } };
34+
var dimensions = new Dictionary<string, string>() { { "region", ExpectedRegion }, { "category", ExpectedCategory } };
3535
var dimensionKey = new DimensionKey(dimensions);
3636

3737
var feedbackToAdd = new MetricAnomalyFeedback(MetricId, dimensionKey, CreatedFeedbackStartTime, CreatedFeedbackEndTime, AnomalyValue.AutoDetect);
@@ -58,7 +58,7 @@ public async Task AddAndGetAnomalyFeedbackWithOptionalDetectionConfigurationFilt
5858
{
5959
MetricsAdvisorClient client = GetMetricsAdvisorClient();
6060

61-
var dimensions = new Dictionary<string, string>() { { "city", ExpectedCity }, { "category", ExpectedCategory } };
61+
var dimensions = new Dictionary<string, string>() { { "region", ExpectedRegion }, { "category", ExpectedCategory } };
6262
var dimensionKey = new DimensionKey(dimensions);
6363

6464
var feedbackToAdd = new MetricAnomalyFeedback(MetricId, dimensionKey, CreatedFeedbackStartTime, CreatedFeedbackEndTime, AnomalyValue.AutoDetect)
@@ -88,7 +88,7 @@ public async Task AddAndGetChangePointFeedback()
8888
{
8989
MetricsAdvisorClient client = GetMetricsAdvisorClient();
9090

91-
var dimensions = new Dictionary<string, string>() { { "city", ExpectedCity }, { "category", ExpectedCategory } };
91+
var dimensions = new Dictionary<string, string>() { { "region", ExpectedRegion }, { "category", ExpectedCategory } };
9292
var dimensionKey = new DimensionKey(dimensions);
9393

9494
var feedbackToAdd = new MetricChangePointFeedback(MetricId, dimensionKey, CreatedFeedbackStartTime, CreatedFeedbackEndTime, ChangePointValue.AutoDetect);
@@ -118,7 +118,7 @@ public async Task AddAndGetCommentFeedbackWithMinimumSetup()
118118
{
119119
MetricsAdvisorClient client = GetMetricsAdvisorClient();
120120

121-
var dimensions = new Dictionary<string, string>() { { "city", ExpectedCity }, { "category", ExpectedCategory } };
121+
var dimensions = new Dictionary<string, string>() { { "region", ExpectedRegion }, { "category", ExpectedCategory } };
122122
var dimensionKey = new DimensionKey(dimensions);
123123

124124
var comment = "Feedback created in a .NET test.";
@@ -145,7 +145,7 @@ public async Task AddAndGetCommentFeedbackWithOptionalTimeFilters()
145145
{
146146
MetricsAdvisorClient client = GetMetricsAdvisorClient();
147147

148-
var dimensions = new Dictionary<string, string>() { { "city", ExpectedCity }, { "category", ExpectedCategory } };
148+
var dimensions = new Dictionary<string, string>() { { "region", ExpectedRegion }, { "category", ExpectedCategory } };
149149
var dimensionKey = new DimensionKey(dimensions);
150150

151151
var comment = "Feedback created in a .NET test.";
@@ -176,7 +176,7 @@ public async Task AddAndGetPeriodFeedback()
176176
{
177177
MetricsAdvisorClient client = GetMetricsAdvisorClient();
178178

179-
var dimensions = new Dictionary<string, string>() { { "city", ExpectedCity }, { "category", ExpectedCategory } };
179+
var dimensions = new Dictionary<string, string>() { { "region", ExpectedRegion }, { "category", ExpectedCategory } };
180180
var dimensionKey = new DimensionKey(dimensions);
181181

182182
var periodValue = 10;
@@ -272,10 +272,10 @@ public async Task GetAllFeedbackWithOptionalFeedbackFilter()
272272
// The sampling time range was chosen in a way to make sure there'll be feedback returned by the
273273
// service call. Changing these values can make this test fail.
274274

275-
DateTimeOffset feedbackSamplingStartTime = DateTimeOffset.Parse("2020-12-01T00:00:00Z");
276-
DateTimeOffset feedbackSamplingEndTime = DateTimeOffset.Parse("2020-12-31T00:00:00Z");
275+
DateTimeOffset feedbackSamplingStartTime = DateTimeOffset.Parse("2021-10-01T00:00:00Z");
276+
DateTimeOffset feedbackSamplingEndTime = DateTimeOffset.Parse("2021-11-20T00:00:00Z");
277277

278-
var dimensions = new Dictionary<string, string>() { { "city", "Delhi" } };
278+
var dimensions = new Dictionary<string, string>() { { "region", "Karachi" } };
279279
var options = new GetAllFeedbackOptions()
280280
{
281281
Filter = new FeedbackFilter()
@@ -284,7 +284,7 @@ public async Task GetAllFeedbackWithOptionalFeedbackFilter()
284284
TimeMode = FeedbackQueryTimeMode.FeedbackCreatedOn,
285285
StartsOn = feedbackSamplingStartTime,
286286
EndsOn = feedbackSamplingEndTime,
287-
FeedbackKind = MetricFeedbackKind.Comment,
287+
FeedbackKind = MetricFeedbackKind.Anomaly
288288
}
289289
};
290290

@@ -308,15 +308,15 @@ public async Task GetAllFeedbackWithOptionalFeedbackFilter()
308308

309309
ValidateGroupKey(dimensionKeyFilter);
310310

311-
Assert.That(dimensionKeyFilter.TryGetValue("city", out string city));
312-
Assert.That(city, Is.EqualTo("Delhi"));
311+
Assert.That(dimensionKeyFilter.TryGetValue("region", out string region));
312+
Assert.That(region, Is.EqualTo("Karachi"));
313313

314-
Assert.That(feedback.FeedbackKind, Is.EqualTo(MetricFeedbackKind.Comment));
314+
Assert.That(feedback.FeedbackKind, Is.EqualTo(MetricFeedbackKind.Anomaly));
315315

316-
var commentFeedback = feedback as MetricCommentFeedback;
316+
var anomalyFeedback = feedback as MetricAnomalyFeedback;
317317

318-
Assert.That(commentFeedback, Is.Not.Null);
319-
Assert.That(commentFeedback.Comment, Is.Not.Null.And.Not.Empty);
318+
Assert.That(anomalyFeedback, Is.Not.Null);
319+
Assert.That(anomalyFeedback.AnomalyValue, Is.Not.EqualTo(default(AnomalyValue)));
320320

321321
if (++feedbackCount >= MaximumSamplesCount)
322322
{
@@ -344,9 +344,9 @@ private void ValidateMetricFeedback(MetricFeedback feedback)
344344
Assert.That(dimensionFilter, Is.Not.Null);
345345

346346
Assert.That(Count(dimensionFilter), Is.EqualTo(2));
347-
Assert.That(dimensionFilter.TryGetValue("city", out string city));
347+
Assert.That(dimensionFilter.TryGetValue("region", out string region));
348348
Assert.That(dimensionFilter.TryGetValue("category", out string category));
349-
Assert.That(city, Is.EqualTo(ExpectedCity));
349+
Assert.That(region, Is.EqualTo(ExpectedRegion));
350350
Assert.That(category, Is.EqualTo(ExpectedCategory));
351351
}
352352
}

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/tests/MetricsAdvisorClient/TimeSeriesLiveTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public TimeSeriesLiveTests(bool isAsync) : base(isAsync)
2121
[TestCase(false)]
2222
public async Task GetMetricDimensionValuesWithMinimumSetup(bool useTokenCredential)
2323
{
24-
const string dimensionName = "city";
24+
const string dimensionName = "region";
2525

2626
MetricsAdvisorClient client = GetMetricsAdvisorClient(useTokenCredential);
2727

@@ -43,7 +43,7 @@ public async Task GetMetricDimensionValuesWithMinimumSetup(bool useTokenCredenti
4343
[RecordedTest]
4444
public async Task GetMetricDimensionValuesWithOptionalDimensionFilter()
4545
{
46-
const string dimensionName = "city";
46+
const string dimensionName = "region";
4747
const string filter = "ba";
4848

4949
MetricsAdvisorClient client = GetMetricsAdvisorClient();
@@ -99,14 +99,14 @@ public async Task GetMetricSeriesDefinitionsWithMinimumSetup(bool useTokenCreden
9999
[RecordedTest]
100100
public async Task GetMetricSeriesDefinitionsWithOptionalDimensionFilter()
101101
{
102-
var cityFilter = new List<string>() { "Belo Horizonte", "Chennai", "Hong Kong" };
103-
var categoryFilter = new List<string>() { "__SUM__", "Outdoors" };
102+
var regionFilter = new List<string>() { "Cairo", "Seoul", "Beijing" };
103+
var categoryFilter = new List<string>() { "__SUM__", "Handmade" };
104104

105105
MetricsAdvisorClient client = GetMetricsAdvisorClient();
106106

107107
var options = new GetMetricSeriesDefinitionsOptions(SamplingStartTime);
108108

109-
options.DimensionCombinationsFilter.Add("city", cityFilter);
109+
options.DimensionCombinationsFilter.Add("region", regionFilter);
110110
options.DimensionCombinationsFilter.Add("category", categoryFilter);
111111

112112
var definitionCount = 0;
@@ -120,10 +120,10 @@ public async Task GetMetricSeriesDefinitionsWithOptionalDimensionFilter()
120120

121121
DimensionKey seriesKey = definition.SeriesKey;
122122

123-
Assert.That(seriesKey.TryGetValue("city", out string city));
123+
Assert.That(seriesKey.TryGetValue("region", out string region));
124124
Assert.That(seriesKey.TryGetValue("category", out string category));
125125

126-
Assert.That(cityFilter.Contains(city));
126+
Assert.That(regionFilter.Contains(region));
127127
Assert.That(categoryFilter.Contains(category));
128128

129129
if (++definitionCount >= MaximumSamplesCount)
@@ -142,10 +142,10 @@ public async Task GetMetricSeriesData(bool useTokenCredential)
142142
{
143143
MetricsAdvisorClient client = GetMetricsAdvisorClient(useTokenCredential);
144144

145-
var dimensions = new Dictionary<string, string>() { { "city", "Delhi" }, { "category", "Handmade" } };
145+
var dimensions = new Dictionary<string, string>() { { "region", "Delhi" }, { "category", "Handmade" } };
146146
var seriesKey1 = new DimensionKey(dimensions);
147147

148-
dimensions = new Dictionary<string, string>() { { "city", "Kolkata" }, { "category", "__SUM__" } };
148+
dimensions = new Dictionary<string, string>() { { "region", "Kolkata" }, { "category", "__SUM__" } };
149149
var seriesKey2 = new DimensionKey(dimensions);
150150

151151
var returnedKey1 = false;
@@ -175,14 +175,14 @@ public async Task GetMetricSeriesData(bool useTokenCredential)
175175

176176
var seriesKey = seriesData.SeriesKey;
177177

178-
Assert.That(seriesKey.TryGetValue("city", out string city));
178+
Assert.That(seriesKey.TryGetValue("region", out string region));
179179
Assert.That(seriesKey.TryGetValue("category", out string category));
180180

181-
if (city == "Delhi" && category == "Handmade")
181+
if (region == "Delhi" && category == "Handmade")
182182
{
183183
returnedKey1 = true;
184184
}
185-
else if (city == "Kolkata" && category == "__SUM__")
185+
else if (region == "Kolkata" && category == "__SUM__")
186186
{
187187
returnedKey2 = true;
188188
}

0 commit comments

Comments
 (0)