Skip to content

Commit

Permalink
[MetricsAdvisor] Made constructor of AnomalyDetectionConfiguration pa…
Browse files Browse the repository at this point in the history
…rameterless (Azure#18393)
  • Loading branch information
kinelski authored and jongio committed Feb 9, 2021
1 parent c310bf2 commit 0eb2ebd
Show file tree
Hide file tree
Showing 15 changed files with 367 additions and 345 deletions.
7 changes: 7 additions & 0 deletions sdk/metricsadvisor/Azure.AI.MetricsAdvisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
- The constructor of the `DataFeed` class is now parameterless. Required properties should be set via setters.
- The constructor of the `DataFeedSchema` class is now parameterless. Metrics can be added directly to `MetricColumns`.
- The constructor of the `DataFeedIngestionSettings` class is now parameterless. Required properties should be set via setters.
- The constructor of the `AnomalyDetectionConfiguration` class is now parameterless. Required properties should be set via setters.
- The constructor of the `MetricSingleSeriesDetectionCondition` class is now parameterless. Dimension columns can be added directly to `SeriesKey`.
- The constructor of the `MetricSeriesGroupDetectionCondition` class is now parameterless. Dimension columns can be added directly to `SeriesGroupKey`.
- In `DataFeed`, added property setters to `Name`, `DataSource`, `Granularity`, `IngestionSettings`, and `Schema`.
- In `DataFeedIngestionSettings`, added a property setter to `IngestionStartTime`.
- In `AnomalyDetectionConfiguration`, added property setters to `MetricId`, `Name`, and `WholeSeriesDetectionConditions`.
- In `DataFeed`, removed the setters of the properties `Administrators` and `Viewers`.
- In `DataFeedSchema`, removed the setter of the property `DimensionColumns`.
- In `DataFeedRollupSettings`, removed the setter of the property `AutoRollupGroupByColumnNames`.
- In `AnomalyDetectionConfiguration`, removed the setters of the properties `SeriesDetectionConditions` and `SeriesGroupDetectionConditions`.
- `DataFeed.SourceType` is now nullable. It will be null whenever `DataFeed.DataSource` is null.
- `DataFeed.IngestionStartTime` is now nullable.
- `MetricsAdvisorAdministrationClient.CreateDataFeed` sync and async methods now throw an `ArgumentException` if required properties are not set properly.
- `MetricsAdvisorAdministrationClient.CreateDetectionConfiguration` sync and async methods now throw an `ArgumentException` if required properties are not set properly.
- In `MetricsAdvisorKeyCredential`, renamed the parameter `key` to `subscriptionKey` in the method `UpdateSubscriptionKey`.
- In `MetricsAdvisorKeyCredential`, renamed the parameter `key` to `apiKey` in the method `UpdateApiKey`.

Expand Down
22 changes: 12 additions & 10 deletions sdk/metricsadvisor/Azure.AI.MetricsAdvisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,23 +277,25 @@ Create an [`AnomalyDetectionConfiguration`](#data-point-anomaly) to tell the ser
string metricId = "<metricId>";
string configurationName = "Sample anomaly detection configuration";

var hardThresholdSuppressCondition = new SuppressCondition(1, 100);
var hardThresholdCondition = new HardThresholdCondition(AnomalyDetectorDirection.Down, hardThresholdSuppressCondition)
var detectionConfiguration = new AnomalyDetectionConfiguration()
{
LowerBound = 5.0
MetricId = metricId,
Name = configurationName,
WholeSeriesDetectionConditions = new MetricWholeSeriesDetectionCondition()
};

var smartDetectionSuppressCondition = new SuppressCondition(4, 50);
var smartDetectionCondition = new SmartDetectionCondition(10.0, AnomalyDetectorDirection.Up, smartDetectionSuppressCondition);
var detectCondition = detectionConfiguration.WholeSeriesDetectionConditions;

var detectionCondition = new MetricWholeSeriesDetectionCondition()
var hardSuppress = new SuppressCondition(1, 100);
detectCondition.HardThresholdCondition = new HardThresholdCondition(AnomalyDetectorDirection.Down, hardSuppress)
{
HardThresholdCondition = hardThresholdCondition,
SmartDetectionCondition = smartDetectionCondition,
CrossConditionsOperator = DetectionConditionsOperator.Or
LowerBound = 5.0
};

var detectionConfiguration = new AnomalyDetectionConfiguration(metricId, configurationName, detectionCondition);
var smartSuppress = new SuppressCondition(4, 50);
detectCondition.SmartDetectionCondition = new SmartDetectionCondition(10.0, AnomalyDetectorDirection.Up, smartSuppress);

detectCondition.CrossConditionsOperator = DetectionConditionsOperator.Or;

Response<string> response = await adminClient.CreateDetectionConfigurationAsync(detectionConfiguration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,14 @@ public AnomalyAlertConfiguration(string name, System.Collections.Generic.IList<s
}
public partial class AnomalyDetectionConfiguration
{
public AnomalyDetectionConfiguration(string metricId, string name, Azure.AI.MetricsAdvisor.Models.MetricWholeSeriesDetectionCondition wholeSeriesDetectionConditions) { }
public AnomalyDetectionConfiguration() { }
public string Description { get { throw null; } set { } }
public string Id { get { throw null; } }
public string MetricId { get { throw null; } }
public string Name { get { throw null; } }
public System.Collections.Generic.IList<Azure.AI.MetricsAdvisor.Models.MetricSingleSeriesDetectionCondition> SeriesDetectionConditions { get { throw null; } set { } }
public System.Collections.Generic.IList<Azure.AI.MetricsAdvisor.Models.MetricSeriesGroupDetectionCondition> SeriesGroupDetectionConditions { get { throw null; } set { } }
public Azure.AI.MetricsAdvisor.Models.MetricWholeSeriesDetectionCondition WholeSeriesDetectionConditions { get { throw null; } }
public string MetricId { get { throw null; } set { } }
public string Name { get { throw null; } set { } }
public System.Collections.Generic.IList<Azure.AI.MetricsAdvisor.Models.MetricSingleSeriesDetectionCondition> SeriesDetectionConditions { get { throw null; } }
public System.Collections.Generic.IList<Azure.AI.MetricsAdvisor.Models.MetricSeriesGroupDetectionCondition> SeriesGroupDetectionConditions { get { throw null; } }
public Azure.AI.MetricsAdvisor.Models.MetricWholeSeriesDetectionCondition WholeSeriesDetectionConditions { get { throw null; } set { } }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct AnomalyDetectorDirection : System.IEquatable<Azure.AI.MetricsAdvisor.Models.AnomalyDetectorDirection>
Expand Down Expand Up @@ -1036,12 +1036,12 @@ internal MetricSeriesDefinition() { }
}
public partial class MetricSeriesGroupDetectionCondition : Azure.AI.MetricsAdvisor.Models.MetricWholeSeriesDetectionCondition
{
public MetricSeriesGroupDetectionCondition(Azure.AI.MetricsAdvisor.Models.DimensionKey seriesGroupKey) { }
public MetricSeriesGroupDetectionCondition() { }
public Azure.AI.MetricsAdvisor.Models.DimensionKey SeriesGroupKey { get { throw null; } }
}
public partial class MetricSingleSeriesDetectionCondition : Azure.AI.MetricsAdvisor.Models.MetricWholeSeriesDetectionCondition
{
public MetricSingleSeriesDetectionCondition(Azure.AI.MetricsAdvisor.Models.DimensionKey seriesKey) { }
public MetricSingleSeriesDetectionCondition() { }
public Azure.AI.MetricsAdvisor.Models.DimensionKey SeriesKey { get { throw null; } }
}
public partial class MetricWholeSeriesDetectionCondition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,11 @@ private static void ValidateDataFeedToCreate(DataFeed dataFeed)
/// A <see cref="Response{T}"/> containing the result of the operation. The result is a <c>string</c>
/// containing the ID of the newly created configuration.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="detectionConfiguration"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="detectionConfiguration"/>, <paramref name="detectionConfiguration"/>.MetricId, <paramref name="detectionConfiguration"/>.Name, or <paramref name="detectionConfiguration"/>.WholeSeriesDetectionConditions is null.</exception>
/// <exception cref="ArgumentException"><paramref name="detectionConfiguration"/>.MetricId or <paramref name="detectionConfiguration"/>.Name is empty.</exception>
public virtual async Task<Response<string>> CreateDetectionConfigurationAsync(AnomalyDetectionConfiguration detectionConfiguration, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(detectionConfiguration, nameof(detectionConfiguration));
ValidateDetectionConfigurationToCreate(detectionConfiguration);

using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsAdvisorAdministrationClient)}.{nameof(CreateDetectionConfiguration)}");
scope.Start();
Expand Down Expand Up @@ -735,10 +736,11 @@ public virtual async Task<Response<string>> CreateDetectionConfigurationAsync(An
/// A <see cref="Response{T}"/> containing the result of the operation. The result is a <c>string</c>
/// containing the ID of the newly created configuration.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="detectionConfiguration"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="detectionConfiguration"/>, <paramref name="detectionConfiguration"/>.MetricId, <paramref name="detectionConfiguration"/>.Name, or <paramref name="detectionConfiguration"/>.WholeSeriesDetectionConditions is null.</exception>
/// <exception cref="ArgumentException"><paramref name="detectionConfiguration"/>.MetricId or <paramref name="detectionConfiguration"/>.Name is empty.</exception>
public virtual Response<string> CreateDetectionConfiguration(AnomalyDetectionConfiguration detectionConfiguration, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(detectionConfiguration, nameof(detectionConfiguration));
ValidateDetectionConfigurationToCreate(detectionConfiguration);

using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsAdvisorAdministrationClient)}.{nameof(CreateDetectionConfiguration)}");
scope.Start();
Expand Down Expand Up @@ -1007,6 +1009,14 @@ public virtual Response DeleteDetectionConfiguration(string detectionConfigurati
}
}

private static void ValidateDetectionConfigurationToCreate(AnomalyDetectionConfiguration configuration)
{
Argument.AssertNotNull(configuration, nameof(configuration));
Argument.AssertNotNullOrEmpty(configuration.MetricId, $"{nameof(configuration)}.{nameof(AnomalyDetectionConfiguration.MetricId)}");
Argument.AssertNotNullOrEmpty(configuration.Name, $"{nameof(configuration)}.{nameof(AnomalyDetectionConfiguration.Name)}");
Argument.AssertNotNull(configuration.WholeSeriesDetectionConditions, $"{nameof(configuration)}.{nameof(AnomalyDetectionConfiguration.WholeSeriesDetectionConditions)}");
}

#endregion AnomalyDetectionConfiguration

#region AnomalyAlertConfiguration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using Azure.Core;

Expand All @@ -13,33 +12,14 @@ namespace Azure.AI.MetricsAdvisor.Models
/// series within the same metric.
/// </summary>
[CodeGenModel("AnomalyDetectionConfiguration")]
[CodeGenSuppress(nameof(AnomalyDetectionConfiguration), typeof(string), typeof(string), typeof(MetricWholeSeriesDetectionCondition))]
public partial class AnomalyDetectionConfiguration
{
private string _name;

private MetricWholeSeriesDetectionCondition _wholeSeriesDetectionConditions;

private IList<MetricSingleSeriesDetectionCondition> _seriesDetectionConditions;

private IList<MetricSeriesGroupDetectionCondition> _seriesGroupDetectionConditions;

/// <summary>
/// Creates a new instance of the <see cref="AnomalyDetectionConfiguration"/> class.
/// </summary>
/// <param name="metricId">The identifier of the metric to which this configuration applies.</param>
/// <param name="name">A custom name for this <see cref="AnomalyDetectionConfiguration"/> to be displayed on the web portal.</param>
/// <param name="wholeSeriesDetectionConditions">The default anomaly detection conditions to be applied to all series associated with this configuration's <paramref name="metricId"/>.</param>
/// <exception cref="ArgumentNullException"><paramref name="metricId"/>, <paramref name="name"/>, or <paramref name="wholeSeriesDetectionConditions"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="metricId"/> or <paramref name="name"/> is empty.</exception>
public AnomalyDetectionConfiguration(string metricId, string name, MetricWholeSeriesDetectionCondition wholeSeriesDetectionConditions)
public AnomalyDetectionConfiguration()
{
Argument.AssertNotNullOrEmpty(metricId, nameof(metricId));
Argument.AssertNotNullOrEmpty(name, nameof(name));
Argument.AssertNotNull(wholeSeriesDetectionConditions, nameof(wholeSeriesDetectionConditions));

MetricId = metricId;
Name = name;
WholeSeriesDetectionConditions = wholeSeriesDetectionConditions;
SeriesDetectionConditions = new ChangeTrackingList<MetricSingleSeriesDetectionCondition>();
SeriesGroupDetectionConditions = new ChangeTrackingList<MetricSeriesGroupDetectionCondition>();
}
Expand All @@ -53,72 +33,34 @@ public AnomalyDetectionConfiguration(string metricId, string name, MetricWholeSe
/// <summary>
/// The identifier of the metric to which this configuration applies.
/// </summary>
public string MetricId { get; }
public string MetricId { get; set; }

/// <summary>
/// A custom name for this <see cref="AnomalyDetectionConfiguration"/> to be displayed on the web portal.
/// </summary>
public string Name
{
get => _name;
private set
{
Argument.AssertNotNullOrEmpty(value, nameof(Name));
_name = value;
}
}
public string Name { get; set; }

/// <summary>
/// The default anomaly detection conditions to be applied to all series associated with this configuration's
/// <see cref="MetricId"/>.
/// </summary>
[CodeGenMember("WholeMetricConfiguration")]
public MetricWholeSeriesDetectionCondition WholeSeriesDetectionConditions
{
get => _wholeSeriesDetectionConditions;
private set
{
Argument.AssertNotNull(value, nameof(WholeSeriesDetectionConditions));
_wholeSeriesDetectionConditions = value;
}
}
public MetricWholeSeriesDetectionCondition WholeSeriesDetectionConditions { get; set; }

/// <summary>
/// The anomaly detection conditions to be applied to the time series associated with this configuration's
/// <see cref="MetricId"/>. These conditions overwrite the ones specified by <see cref="WholeSeriesDetectionConditions"/>.
/// </summary>
/// <exception cref="ArgumentNullException"><see cref="SeriesGroupDetectionConditions"/> is null.</exception>
[CodeGenMember("DimensionGroupOverrideConfigurations")]
#pragma warning disable CA2227 // Collection properties should be readonly
public IList<MetricSeriesGroupDetectionCondition> SeriesGroupDetectionConditions
{
get => _seriesGroupDetectionConditions;
set
{
Argument.AssertNotNull(value, nameof(SeriesGroupDetectionConditions));
_seriesGroupDetectionConditions = value;
}
}
#pragma warning restore CA2227 // Collection properties should be readonly
public IList<MetricSeriesGroupDetectionCondition> SeriesGroupDetectionConditions { get; }

/// <summary>
/// The anomaly detection conditions to be applied to the time series associated with this configuration's
/// <see cref="MetricId"/>. These conditions overwrite the ones specified by <see cref="WholeSeriesDetectionConditions"/>
/// and <see cref="SeriesGroupDetectionConditions"/>.
/// </summary>
/// <exception cref="ArgumentNullException"><see cref="SeriesDetectionConditions"/> is null.</exception>
[CodeGenMember("SeriesOverrideConfigurations")]
#pragma warning disable CA2227 // Collection properties should be readonly
public IList<MetricSingleSeriesDetectionCondition> SeriesDetectionConditions
{
get => _seriesDetectionConditions;
set
{
Argument.AssertNotNull(value, nameof(SeriesDetectionConditions));
_seriesDetectionConditions = value;
}
}
#pragma warning restore CA2227 // Collection properties should be readonly
public IList<MetricSingleSeriesDetectionCondition> SeriesDetectionConditions { get; }

/// <summary>
/// A description about the <see cref="AnomalyDetectionConfiguration"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core;

namespace Azure.AI.MetricsAdvisor.Models
Expand All @@ -11,18 +10,15 @@ namespace Azure.AI.MetricsAdvisor.Models
/// of time series.
/// </summary>
[CodeGenModel("DimensionGroupConfiguration")]
[CodeGenSuppress(nameof(MetricSeriesGroupDetectionCondition), typeof(DimensionKey))]
public partial class MetricSeriesGroupDetectionCondition : MetricWholeSeriesDetectionCondition
{
/// <summary>
/// Initializes a new instance of the <see cref="MetricSeriesGroupDetectionCondition"/> class.
/// </summary>
/// <param name="seriesGroupKey">The key that identifies the group of time series to which these conditions apply within a metric. A subset of the possible dimensions of the associated data feed must be set.</param>
/// <exception cref="ArgumentNullException"><paramref name="seriesGroupKey"/> is null.</exception>
public MetricSeriesGroupDetectionCondition(DimensionKey seriesGroupKey)
public MetricSeriesGroupDetectionCondition()
{
Argument.AssertNotNull(seriesGroupKey, nameof(seriesGroupKey));

SeriesGroupKey = seriesGroupKey;
SeriesGroupKey = new DimensionKey();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core;

namespace Azure.AI.MetricsAdvisor.Models
Expand All @@ -17,13 +16,9 @@ public partial class MetricSingleSeriesDetectionCondition : MetricWholeSeriesDet
/// <summary>
/// Initializes a new instance of the <see cref="MetricSingleSeriesDetectionCondition"/> class.
/// </summary>
/// <param name="seriesKey">The key that uniquely identifies the time series to which these conditions apply within a metric. Every dimension contained in the associated <see cref="DataFeed"/> must be assigned a value.</param>
/// <exception cref="ArgumentNullException"><paramref name="seriesKey"/> is null.</exception>
public MetricSingleSeriesDetectionCondition(DimensionKey seriesKey)
public MetricSingleSeriesDetectionCondition()
{
Argument.AssertNotNull(seriesKey, nameof(seriesKey));

SeriesKey = seriesKey;
SeriesKey = new DimensionKey();
}

internal MetricSingleSeriesDetectionCondition(DetectionConditionsOperator? crossConditionsOperator, SmartDetectionCondition smartDetectionCondition, HardThresholdCondition hardThresholdCondition, ChangeThresholdCondition changeThresholdCondition, SeriesIdentity series)
Expand Down
Loading

0 comments on commit 0eb2ebd

Please sign in to comment.