Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MetricsAdvisor] Updated DimensionKey implementation #21972

Merged
merged 3 commits into from
Jun 24, 2021
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
11 changes: 11 additions & 0 deletions sdk/metricsadvisor/Azure.AI.MetricsAdvisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

## 1.0.0-beta.5 (Unreleased)

### New Features
- `DimensionKey` now implements the `IEnumerable<KeyValuePair<string, string>>` interface. Dimension columns can now be enumerated.
- Added method `Contains` to `DimensionKey` to check whether or not a dimension column is present.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is worth showing this in any sample? or the use of the TryGetValue? The names and docstrings are clear enough that I don't think it is needed, but asking just in case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To tell you the truth, I don't think these methods will be used that much. In general, customers will need to go through every element anyway, so they'll use the enumerator (kudos to KC who suggested making it an IEnumerable). I added these methods just in case someone wants to check a specific element without going through the whole set.

- Added a property setter to `MetricSeriesGroupDetectionCondition.SeriesGroupKey` and to `MetricSingleSeriesDetectionCondition.SeriesKey`.

### Breaking Changes
- Removed methods `AddDimensionColumn` and `RemoveDimensionColumn` from `DimensionKey`. In order to access elements, the new method `TryGetValue` must be used. Once the instance has been created, the columns can't be modified anymore.
- `DimensionKey` is not an `IEquatable` anymore. Equality will be calculated based on reference only.
- `DimensionKey` constructor now takes the required `dimension` parameter.
- The whole `DatasourceCredential` API has been renamed to `DataSourceCredential`. This includes renames in methods, method parameters, and properties.
- Renamed class `DatasourceCredential` to `DataSourceCredentialEntity`.
- Renamed class `DataLakeGen2SharedKeyDatasourceCredential` to `DataSourceDataLakeGen2SharedKey`.
Expand All @@ -15,6 +23,8 @@
- `DataFeedMissingDataPointFillSettings` constructor now takes the required `fillType` parameter. For this reason, the property `FillType` is not nullable anymore.
- `EmailNotificationHook` constructor now takes the required `name` parameter.
- `WebNotificationHook` constructor now takes the required `name` and `endpoint` parameters.
- `MetricSeriesGroupDetectionCondition` constructor now takes the required `seriesGroupKey` parameter.
- `MetricSingleSeriesDetectionCondition` constructor now takes the required `seriesKey` parameter.
- In `MetricSeriesData`, removed the `Definition` property. Now, properties `MetricId` and `SeriesKey` can be accessed directly from `MetricSeriesData`.
- In `DataPointAnomaly`, renamed property `AnomalyDetectionConfigurationId` to `DetectionConfigurationId`.
- In `DataFeedMetric`, renamed constructor parameter `metricName` to `name` only.
Expand All @@ -23,6 +33,7 @@
- Moved `DatasourceCredential`, `DataFeedSource`, `NotificationHook`, and all of their concrete child types to the `Azure.AI.MetricsAdvisor.Administration` namespace.
- Moved `MetricFeedback` and all of its concrete child types to the `Azure.AI.MetricsAdvisor` namespace.
- Changed order of parameters of `MetricsAdvisorClient.GetMetricEnrichedSeriesData`. Now, `detectionConfigurationId` appears first.
- Optional properties `GetAllFeedbackOptions.Filter`, `GetAnomalyDimensionValuesOptions.DimensionToFilter`, and `FeedbackDimensionFilter.DimensionFilter` must now be manually added with setters to be used.
- Moved property `DataFeed.SourceType` to `DataFeedSource.DataSourceType`.
- In `MetricsAdvisorKeyCredential`, merged `UpdateSubscriptionKey` and `UpdateApiKey` into a single method, `Update`, to make it an atomic operation.

Expand Down
4 changes: 2 additions & 2 deletions sdk/metricsadvisor/Azure.AI.MetricsAdvisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ await foreach (DataPointAnomaly anomaly in client.GetAnomaliesForAlertAsync(aler
Console.WriteLine($"Severity: {anomaly.Severity}");
Console.WriteLine("Series key:");

foreach (KeyValuePair<string, string> keyValuePair in anomaly.SeriesKey.AsDictionary())
foreach (KeyValuePair<string, string> dimensionColumn in anomaly.SeriesKey)
{
Console.WriteLine($" Dimension '{keyValuePair.Key}': {keyValuePair.Value}");
Console.WriteLine($" Dimension '{dimensionColumn.Key}': {dimensionColumn.Value}");
}

Console.WriteLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public partial class GetAllFeedbackOptions
public GetAllFeedbackOptions() { }
public System.DateTimeOffset? EndTime { get { throw null; } set { } }
public Azure.AI.MetricsAdvisor.Models.FeedbackType? FeedbackType { get { throw null; } set { } }
public Azure.AI.MetricsAdvisor.Models.DimensionKey Filter { get { throw null; } }
public Azure.AI.MetricsAdvisor.Models.DimensionKey Filter { get { throw null; } set { } }
kinelski marked this conversation as resolved.
Show resolved Hide resolved
public int? MaxPageSize { get { throw null; } set { } }
public int? Skip { get { throw null; } set { } }
public System.DateTimeOffset? StartTime { get { throw null; } set { } }
Expand Down Expand Up @@ -83,7 +83,7 @@ public GetAnomaliesForDetectionConfigurationOptions(System.DateTimeOffset startT
public partial class GetAnomalyDimensionValuesOptions
{
public GetAnomalyDimensionValuesOptions(System.DateTimeOffset startTime, System.DateTimeOffset endTime) { }
public Azure.AI.MetricsAdvisor.Models.DimensionKey DimensionToFilter { get { throw null; } }
public Azure.AI.MetricsAdvisor.Models.DimensionKey DimensionToFilter { get { throw null; } set { } }
public System.DateTimeOffset EndTime { get { throw null; } }
public int? MaxPageSize { get { throw null; } set { } }
public int? Skip { get { throw null; } set { } }
Expand Down Expand Up @@ -988,19 +988,13 @@ internal DataPointAnomaly() { }
public static bool operator !=(Azure.AI.MetricsAdvisor.Models.DetectionConditionsOperator left, Azure.AI.MetricsAdvisor.Models.DetectionConditionsOperator right) { throw null; }
public override string ToString() { throw null; }
}
public partial class DimensionKey : System.IEquatable<Azure.AI.MetricsAdvisor.Models.DimensionKey>
public partial class DimensionKey : System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>>, System.Collections.IEnumerable
kinelski marked this conversation as resolved.
Show resolved Hide resolved
{
public DimensionKey() { }
public void AddDimensionColumn(string dimensionColumnName, string dimensionColumnValue) { }
public System.Collections.Generic.Dictionary<string, string> AsDictionary() { throw null; }
public bool Equals(Azure.AI.MetricsAdvisor.Models.DimensionKey other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
public static bool operator ==(Azure.AI.MetricsAdvisor.Models.DimensionKey left, Azure.AI.MetricsAdvisor.Models.DimensionKey right) { throw null; }
public static bool operator !=(Azure.AI.MetricsAdvisor.Models.DimensionKey left, Azure.AI.MetricsAdvisor.Models.DimensionKey right) { throw null; }
public void RemoveDimensionColumn(string dimensionColumnName) { }
public DimensionKey(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> dimension) { }
public bool Contains(string columnName) { throw null; }
public System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, string>> GetEnumerator() { throw null; }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
public bool TryGetValue(string columnName, out string value) { throw null; }
}
public partial class EnrichmentStatus
{
Expand All @@ -1012,7 +1006,7 @@ internal EnrichmentStatus() { }
public partial class FeedbackDimensionFilter
{
public FeedbackDimensionFilter() { }
public Azure.AI.MetricsAdvisor.Models.DimensionKey DimensionFilter { get { throw null; } }
public Azure.AI.MetricsAdvisor.Models.DimensionKey DimensionFilter { get { throw null; } set { } }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct FeedbackType : System.IEquatable<Azure.AI.MetricsAdvisor.Models.FeedbackType>
Expand Down Expand Up @@ -1181,13 +1175,13 @@ internal MetricSeriesDefinition() { }
}
public partial class MetricSeriesGroupDetectionCondition : Azure.AI.MetricsAdvisor.Models.MetricWholeSeriesDetectionCondition
{
public MetricSeriesGroupDetectionCondition() { }
public Azure.AI.MetricsAdvisor.Models.DimensionKey SeriesGroupKey { get { throw null; } }
public MetricSeriesGroupDetectionCondition(Azure.AI.MetricsAdvisor.Models.DimensionKey seriesGroupKey) { }
public Azure.AI.MetricsAdvisor.Models.DimensionKey SeriesGroupKey { get { throw null; } set { } }
kinelski marked this conversation as resolved.
Show resolved Hide resolved
}
public partial class MetricSingleSeriesDetectionCondition : Azure.AI.MetricsAdvisor.Models.MetricWholeSeriesDetectionCondition
{
public MetricSingleSeriesDetectionCondition() { }
public Azure.AI.MetricsAdvisor.Models.DimensionKey SeriesKey { get { throw null; } }
public MetricSingleSeriesDetectionCondition(Azure.AI.MetricsAdvisor.Models.DimensionKey seriesKey) { }
public Azure.AI.MetricsAdvisor.Models.DimensionKey SeriesKey { get { throw null; } set { } }
}
public partial class MetricWholeSeriesDetectionCondition
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ public class GetAllFeedbackOptions
/// </summary>
public GetAllFeedbackOptions()
{
Filter = new DimensionKey();
}

/// <summary> The dimension filter. </summary>
internal FeedbackDimensionFilter DimensionFilter => Filter.Dimension.Count == 0 ? null : new FeedbackDimensionFilter(Filter.Dimension);
internal FeedbackDimensionFilter DimensionFilter => Filter.Dimension == null ? null : new FeedbackDimensionFilter(Filter.Dimension);

/// <summary>
/// Filters the result by series. Only feedbacks for the series in the time series group specified will
/// be returned.
/// </summary>
public DimensionKey Filter { get; }
public DimensionKey Filter { get; set; }

/// <summary>
/// Filters the result by <see cref="MetricFeedback.Type"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public GetAnomalyDimensionValuesOptions(DateTimeOffset startTime, DateTimeOffset
{
StartTime = startTime;
EndTime = endTime;
DimensionToFilter = new DimensionKey();
}

/// <summary>
Expand All @@ -38,7 +37,7 @@ public GetAnomalyDimensionValuesOptions(DateTimeOffset startTime, DateTimeOffset
/// Filters the result by series. Only anomalies detected in the time series group specified will
/// be returned.
/// </summary>
public DimensionKey DimensionToFilter { get; }
public DimensionKey DimensionToFilter { get; set; }

/// <summary>
/// If set, skips the first set of items returned. This property specifies the amount of items to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core;

namespace Azure.AI.MetricsAdvisor.Models
Expand All @@ -16,16 +17,20 @@ public partial class MetricSeriesGroupDetectionCondition : MetricWholeSeriesDete
/// <summary>
/// Initializes a new instance of the <see cref="MetricSeriesGroupDetectionCondition"/> class.
/// </summary>
public MetricSeriesGroupDetectionCondition()
/// <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 <c>null</c>.</exception>
public MetricSeriesGroupDetectionCondition(DimensionKey seriesGroupKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do you have tests to check that we correctly assert when null?
Same for MetricSingleSeriesDetectionCondition

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't, but I think it's common to not add constructor assertion tests to every single model, right? We don't do it in FR either. Let me know if you think otherwise.

{
SeriesGroupKey = new DimensionKey();
Argument.AssertNotNull(seriesGroupKey, nameof(seriesGroupKey));

SeriesGroupKey = seriesGroupKey;
}

/// <summary>
/// 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.
/// </summary>
[CodeGenMember("Group")]
public DimensionKey SeriesGroupKey { get; }
public DimensionKey SeriesGroupKey { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core;

namespace Azure.AI.MetricsAdvisor.Models
Expand All @@ -16,9 +17,13 @@ public partial class MetricSingleSeriesDetectionCondition : MetricWholeSeriesDet
/// <summary>
/// Initializes a new instance of the <see cref="MetricSingleSeriesDetectionCondition"/> class.
/// </summary>
public MetricSingleSeriesDetectionCondition()
/// <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 <c>null</c>.</exception>
public MetricSingleSeriesDetectionCondition(DimensionKey seriesKey)
{
SeriesKey = new DimensionKey();
Argument.AssertNotNull(seriesKey, nameof(seriesKey));

SeriesKey = seriesKey;
}

internal MetricSingleSeriesDetectionCondition(DetectionConditionsOperator? crossConditionsOperator, SmartDetectionCondition smartDetectionCondition, HardThresholdCondition hardThresholdCondition, ChangeThresholdCondition changeThresholdCondition, SeriesIdentity series)
Expand All @@ -31,7 +36,7 @@ internal MetricSingleSeriesDetectionCondition(DetectionConditionsOperator? cross
/// 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.
/// </summary>
public DimensionKey SeriesKey { get; }
public DimensionKey SeriesKey { get; set; }

/// <summary>
/// Used by CodeGen during serialization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public partial class FeedbackDimensionFilter
/// </summary>
public FeedbackDimensionFilter()
{
DimensionFilter = new DimensionKey();
}

/// <summary> Initializes a new instance of FeedbackDimensionFilter. </summary>
Expand All @@ -36,14 +35,14 @@ internal FeedbackDimensionFilter(IDictionary<string, string> dimension)
/// Filters the result by series. Only feedbacks for the series in the time series group specified will
/// be returned.
/// </summary>
public DimensionKey DimensionFilter { get; private set; }
public DimensionKey DimensionFilter { get; set; }

/// <summary>
/// Used by CodeGen during serialization.
/// </summary>
internal IDictionary<string, string> Dimension
{
get => DimensionFilter.Dimension;
get => DimensionFilter?.Dimension ?? new Dictionary<string, string>();
set => DimensionFilter = new DimensionKey(value);
}
}
Expand Down
Loading