Skip to content

Commit c1701d1

Browse files
authored
[MetricsAdvisor] Added GetIncidentRootCauses overloads (Azure#16574)
* Made DataFeed.MetricIds a Dictionary * Added two more GetIncidentRootCauses tests
1 parent f2a4df7 commit c1701d1

18 files changed

+2064
-354
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.0.0-beta.2 (Unreleased)
44

55
### New Features
6+
- Added new sync and async `GetIncidentRootCauses` overloads to `MetricsAdvisorClient` to list root causes for a given `AnomalyIncident` instance.
67
- Added a public constructor to `DataFeed`.
78
- Added the `DataSource` property to `DataFeed`.
89
- All `DataSource`s now have public properties exposing the associated parameters used to get the data, such as endpoints, connection strings, and query strings.
@@ -15,16 +16,18 @@
1516
- In `MetricsAdvisorClient`, renamed sync and async `GetMetricDimensionValues` methods to `GetDimensionValues`.
1617
- In `MetricsAdvisorClient`, changed return types of sync and async `CreateMetricFeedback` methods to a `Response<string>` containing the ID of the created feedback.
1718
- In `MetricsAdvisorClient`, changed return types of sync and async methods `GetIncidentRootCauses`, `GetMetricEnrichedSeriesData`, and `GetMetricSeriesData` to pageables.
19+
- In `MetricsAdvisorClient`, updated sync and async `GetIncidentsForDetectionConfiguration` methods to always populate the `DetectionConfigurationId` of returned incidents.
1820
- In `MetricsAdvisorAdministrationClient`, renamed the sync and async `AnomalyAlertConfiguration` CRUD methods, removing the `Anomaly` word from their names (e.g., `GetAnomalyAlertConfiguration` became `GetAlertConfiguration`).
1921
- In `MetricsAdvisorAdministrationClient`, renamed the sync and async `MetricAnomalyDetectionConfiguration` CRUD methods, removing the `MetricAnomaly` term from their names (e.g., `GetMetricAnomalyDetectionConfiguration` became `GetDetectionConfiguration`).
2022
- In `MetricsAdvisorAdministrationClient`, updated `CreateDataFeed` and `CreateDataFeedAsync` to take a whole `DataFeed` object as a parameter.
2123
- In `MetricsAdvisorAdministrationClient`, changed return types of sync and async `Create` methods (e.g., `CreateDataFeed`) to a `Response<string>` containing the ID of the created resource.
2224
- In `MetricsAdvisorAdministrationClient`, changed return types of sync and async methods `GetAnomalyAlertConfigurations` and `GetMetricAnomalyDetectionConfigurations` to pageables.
2325
- In `MetricsAdvisorAdministrationClient`, renamed parameter `alertConfigurationId` to `detectionConfigurationId` in sync and async `GetAnomalyAlertConfigurations` methods.
26+
- Updated `DataFeed.MetricIds` to a `Dictionary<string, string>` that maps a metric name to its ID.
2427
- In `DataFeedIngestionStatus`, made `Timestamp` and `Status` non-nullables.
25-
- In `AnomalyIncident`, made `Status` non-nullable.
26-
- In `EnrichmentStatus`, made `Timestamp` non-nullable.
2728
- In `MetricEnrichedSeriesData`, made elements of `ExpectedValues`, `Periods`, `IsAnomaly`, `LowerBoundaries` and `UpperBoundaries` nullables.
29+
- Made `AnomalyIncident.Status` non-nullable.
30+
- Made `EnrichmentStatus.Timestamp` non-nullable.
2831
- Removed `MetricsAdvisorClientOptions` and `MetricsAdvisorAdministrationOptions` and replaced both with `MetricsAdvisorClientsOptions`.
2932
- Removed `DataFeedOptions`. All of its properties were moved directly into `DataFeed`.
3033
- Renamed `GetMetricFeedbacksOptions` to `GetAllMetricFeedbackOptions`.

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/api/Azure.AI.MetricsAdvisor.netstandard2.0.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public MetricsAdvisorClient(System.Uri endpoint, Azure.AI.MetricsAdvisor.Metrics
1717
public virtual Azure.AsyncPageable<Azure.AI.MetricsAdvisor.Models.DataPointAnomaly> GetAnomaliesAsync(string alertConfigurationId, string alertId, Azure.AI.MetricsAdvisor.Models.GetAnomaliesForAlertOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1818
public virtual Azure.Pageable<string> GetDimensionValues(string metricId, string dimensionName, Azure.AI.MetricsAdvisor.Models.GetDimensionValuesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1919
public virtual Azure.AsyncPageable<string> GetDimensionValuesAsync(string metricId, string dimensionName, Azure.AI.MetricsAdvisor.Models.GetDimensionValuesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
20+
public virtual Azure.Pageable<Azure.AI.MetricsAdvisor.Models.IncidentRootCause> GetIncidentRootCauses(Azure.AI.MetricsAdvisor.Models.AnomalyIncident incident, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2021
public virtual Azure.Pageable<Azure.AI.MetricsAdvisor.Models.IncidentRootCause> GetIncidentRootCauses(string detectionConfigurationId, string incidentId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
22+
public virtual Azure.AsyncPageable<Azure.AI.MetricsAdvisor.Models.IncidentRootCause> GetIncidentRootCausesAsync(Azure.AI.MetricsAdvisor.Models.AnomalyIncident incident, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2123
public virtual Azure.AsyncPageable<Azure.AI.MetricsAdvisor.Models.IncidentRootCause> GetIncidentRootCausesAsync(string detectionConfigurationId, string incidentId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2224
public virtual Azure.Pageable<Azure.AI.MetricsAdvisor.Models.AnomalyIncident> GetIncidents(string detectionConfigurationId, Azure.AI.MetricsAdvisor.Models.GetIncidentsForDetectionConfigurationOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2325
public virtual Azure.Pageable<Azure.AI.MetricsAdvisor.Models.AnomalyIncident> GetIncidents(string alertConfigurationId, string alertId, Azure.AI.MetricsAdvisor.Models.GetIncidentsForAlertOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -368,7 +370,7 @@ public DataFeed(string dataFeedName, Azure.AI.MetricsAdvisor.Models.DataFeedSour
368370
public string Id { get { throw null; } }
369371
public Azure.AI.MetricsAdvisor.Models.DataFeedIngestionSettings IngestionSettings { get { throw null; } }
370372
public bool? IsAdministrator { get { throw null; } }
371-
public System.Collections.Generic.IReadOnlyList<string> MetricIds { get { throw null; } }
373+
public System.Collections.Generic.IReadOnlyDictionary<string, string> MetricIds { get { throw null; } }
372374
public Azure.AI.MetricsAdvisor.Models.DataFeedMissingDataPointFillSettings MissingDataPointFillSettings { get { throw null; } set { } }
373375
public string Name { get { throw null; } }
374376
public Azure.AI.MetricsAdvisor.Models.DataFeedRollupSettings RollupSettings { get { throw null; } set { } }

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/src/MetricsAdvisorClient.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ async Task<Page<AnomalyIncident>> FirstPageFunc(int? pageSizeHint)
903903
try
904904
{
905905
Response<IncidentResultList> response = await _serviceRestClient.GetIncidentsByAnomalyDetectionConfigurationAsync(detectionConfigurationGuid, queryOptions, top, cancellationToken).ConfigureAwait(false);
906+
PopulateDetectionConfigurationIds(response.Value.Value, detectionConfigurationId);
906907
return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse());
907908
}
908909
catch (Exception e)
@@ -920,6 +921,7 @@ async Task<Page<AnomalyIncident>> NextPageFunc(string nextLink, int? pageSizeHin
920921
try
921922
{
922923
Response<IncidentResultList> response = await _serviceRestClient.GetIncidentsByAnomalyDetectionConfigurationNextPageAsync(nextLink, detectionConfigurationGuid, queryOptions, top, cancellationToken).ConfigureAwait(false);
924+
PopulateDetectionConfigurationIds(response.Value.Value, detectionConfigurationId);
923925
return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse());
924926
}
925927
catch (Exception e)
@@ -962,6 +964,7 @@ Page<AnomalyIncident> FirstPageFunc(int? pageSizeHint)
962964
try
963965
{
964966
Response<IncidentResultList> response = _serviceRestClient.GetIncidentsByAnomalyDetectionConfiguration(detectionConfigurationGuid, queryOptions, top, cancellationToken);
967+
PopulateDetectionConfigurationIds(response.Value.Value, detectionConfigurationId);
965968
return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse());
966969
}
967970
catch (Exception e)
@@ -979,6 +982,7 @@ Page<AnomalyIncident> NextPageFunc(string nextLink, int? pageSizeHint)
979982
try
980983
{
981984
Response<IncidentResultList> response = _serviceRestClient.GetIncidentsByAnomalyDetectionConfigurationNextPage(nextLink, detectionConfigurationGuid, queryOptions, top, cancellationToken);
985+
PopulateDetectionConfigurationIds(response.Value.Value, detectionConfigurationId);
982986
return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse());
983987
}
984988
catch (Exception e)
@@ -1063,6 +1067,74 @@ Page<IncidentRootCause> FirstPageFunc(int? pageSizeHint)
10631067
return PageableHelpers.CreateEnumerable(FirstPageFunc, null);
10641068
}
10651069

1070+
/// <summary>
1071+
/// Gets the automatic suggestions for likely root causes of an incident.
1072+
/// </summary>
1073+
/// <param name="incident">The <see cref="AnomalyIncident"/> from which root causes will be returned.</param>
1074+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
1075+
/// <returns>An <see cref="AsyncPageable{T}"/> containing the collection of <see cref="IncidentRootCause"/>s.</returns>
1076+
/// <exception cref="ArgumentNullException"><paramref name="incident"/> is null.</exception>
1077+
public virtual AsyncPageable<IncidentRootCause> GetIncidentRootCausesAsync(AnomalyIncident incident, CancellationToken cancellationToken = default)
1078+
{
1079+
Argument.AssertNotNull(incident, nameof(incident));
1080+
1081+
Guid detectionConfigurationGuid = new Guid(incident.DetectionConfigurationId);
1082+
string incidentId = incident.Id;
1083+
1084+
async Task<Page<IncidentRootCause>> FirstPageFunc(int? pageSizeHint)
1085+
{
1086+
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsAdvisorClient)}.{nameof(GetIncidentRootCauses)}");
1087+
scope.Start();
1088+
1089+
try
1090+
{
1091+
Response<RootCauseList> response = await _serviceRestClient.GetRootCauseOfIncidentByAnomalyDetectionConfigurationAsync(detectionConfigurationGuid, incidentId, cancellationToken).ConfigureAwait(false);
1092+
return Page.FromValues(response.Value.Value, null, response.GetRawResponse());
1093+
}
1094+
catch (Exception e)
1095+
{
1096+
scope.Failed(e);
1097+
throw;
1098+
}
1099+
}
1100+
1101+
return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, null);
1102+
}
1103+
1104+
/// <summary>
1105+
/// Gets the automatic suggestions for likely root causes of an incident.
1106+
/// </summary>
1107+
/// <param name="incident">The <see cref="AnomalyIncident"/> from which root causes will be returned.</param>
1108+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
1109+
/// <returns>A <see cref="Pageable{T}"/> containing the collection of <see cref="IncidentRootCause"/>s.</returns>
1110+
/// <exception cref="ArgumentNullException"><paramref name="incident"/> is null.</exception>
1111+
public virtual Pageable<IncidentRootCause> GetIncidentRootCauses(AnomalyIncident incident, CancellationToken cancellationToken = default)
1112+
{
1113+
Argument.AssertNotNull(incident, nameof(incident));
1114+
1115+
Guid detectionConfigurationGuid = new Guid(incident.DetectionConfigurationId);
1116+
string incidentId = incident.Id;
1117+
1118+
Page<IncidentRootCause> FirstPageFunc(int? pageSizeHint)
1119+
{
1120+
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsAdvisorClient)}.{nameof(GetIncidentRootCauses)}");
1121+
scope.Start();
1122+
1123+
try
1124+
{
1125+
Response<RootCauseList> response = _serviceRestClient.GetRootCauseOfIncidentByAnomalyDetectionConfiguration(detectionConfigurationGuid, incidentId, cancellationToken);
1126+
return Page.FromValues(response.Value.Value, null, response.GetRawResponse());
1127+
}
1128+
catch (Exception e)
1129+
{
1130+
scope.Failed(e);
1131+
throw;
1132+
}
1133+
}
1134+
1135+
return PageableHelpers.CreateEnumerable(FirstPageFunc, null);
1136+
}
1137+
10661138
/// <summary>
10671139
/// Gets all the values a specified dimension has assumed for anomalous data points detected by a
10681140
/// <see cref="MetricAnomalyAlertConfiguration"/>.
@@ -1267,6 +1339,14 @@ Page<MetricEnrichedSeriesData> FirstPageFunc(int? pageSizeHint)
12671339
return PageableHelpers.CreateEnumerable(FirstPageFunc, null);
12681340
}
12691341

1342+
private static void PopulateDetectionConfigurationIds(IEnumerable<AnomalyIncident> incidents, string detectionConfigurationId)
1343+
{
1344+
foreach (AnomalyIncident incident in incidents)
1345+
{
1346+
incident.DetectionConfigurationId = detectionConfigurationId;
1347+
}
1348+
}
1349+
12701350
#endregion AnomalyDetection
12711351

12721352
#region AlertDetection

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/src/Models/AnomalyIncident.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ internal AnomalyIncident(string metricId, string detectionConfigurationId, strin
3737

3838
/// <summary>
3939
/// The unique identifier of the <see cref="AnomalyDetectionConfiguration"/> that detected
40-
/// this <see cref="AnomalyIncident"/>. This property is only populated when calling
41-
/// <see cref="MetricsAdvisorClient.GetIncidents(string, string, GetIncidentsForAlertOptions, CancellationToken)"/> or
42-
/// <see cref="MetricsAdvisorClient.GetIncidentsAsync(string, string, GetIncidentsForAlertOptions, CancellationToken)"/>.
40+
/// this <see cref="AnomalyIncident"/>.
4341
/// </summary>
4442
[CodeGenMember("AnomalyDetectionConfigurationId")]
45-
public string DetectionConfigurationId { get; }
43+
public string DetectionConfigurationId { get; internal set; }
4644

4745
/// <summary>
4846
/// The unique identifier of the <see cref="DataFeedMetric"/> of the time series in which this

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/src/Models/DataFeed/DataFeed.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal DataFeed(DataFeedDetail dataFeedDetail)
5353
CreatedTime = dataFeedDetail.CreatedTime;
5454
Creator = dataFeedDetail.Creator;
5555
IsAdministrator = dataFeedDetail.IsAdmin;
56-
MetricIds = dataFeedDetail.Metrics.Select(metric => metric.MetricId).ToList();
56+
MetricIds = dataFeedDetail.Metrics.ToDictionary(metric => metric.MetricName, metric => metric.MetricId);
5757
Name = dataFeedDetail.DataFeedName;
5858
DataSource = DataFeedSource.GetDataFeedSource(dataFeedDetail);
5959
SourceType = dataFeedDetail.DataSourceType;
@@ -99,7 +99,7 @@ internal DataFeed(DataFeedDetail dataFeedDetail)
9999
/// The unique identifiers of the metrics defined in this feed's <see cref="DataFeedSchema"/>.
100100
/// Set by the service.
101101
/// </summary>
102-
public IReadOnlyList<string> MetricIds { get; }
102+
public IReadOnlyDictionary<string, string> MetricIds { get; }
103103

104104
/// <summary>
105105
/// A custom name for this <see cref="DataFeed"/> to be displayed on the web portal.

0 commit comments

Comments
 (0)