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] Fixed UpdateHook methods #21559

Merged
merged 11 commits into from
Jun 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ public MetricsAdvisorAdministrationClient(System.Uri endpoint, Azure.Core.TokenC
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.MetricsAdvisor.Models.DatasourceCredential>> UpdateDatasourceCredentialAsync(Azure.AI.MetricsAdvisor.Models.DatasourceCredential datasourceCredential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.MetricsAdvisor.Models.AnomalyDetectionConfiguration> UpdateDetectionConfiguration(Azure.AI.MetricsAdvisor.Models.AnomalyDetectionConfiguration detectionConfiguration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.MetricsAdvisor.Models.AnomalyDetectionConfiguration>> UpdateDetectionConfigurationAsync(Azure.AI.MetricsAdvisor.Models.AnomalyDetectionConfiguration detectionConfiguration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response UpdateHook(string hookId, Azure.AI.MetricsAdvisor.Models.NotificationHook hook, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> UpdateHookAsync(string hookId, Azure.AI.MetricsAdvisor.Models.NotificationHook hook, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.MetricsAdvisor.Models.NotificationHook> UpdateHook(Azure.AI.MetricsAdvisor.Models.NotificationHook hook, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.MetricsAdvisor.Models.NotificationHook>> UpdateHookAsync(Azure.AI.MetricsAdvisor.Models.NotificationHook hook, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
}
namespace Azure.AI.MetricsAdvisor.Models
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1582,22 +1582,27 @@ public virtual Response<NotificationHook> CreateHook(NotificationHook hook, Canc
}

/// <summary>
/// Updates an existing <see cref="NotificationHook"/>.
/// Updates an existing <see cref="NotificationHook"/>. In order to update your hook, you cannot create a <see cref="NotificationHook"/>
/// directly from its constructor. You need to obtain an instance via <see cref="GetHookAsync"/> or another CRUD operation and update it
/// before calling this method.
/// </summary>
/// <param name="hookId">The ID of the existing <see cref="NotificationHook"/> to update.</param>
/// <param name="hook">The <see cref="NotificationHook"/> model containing the updates to be applied.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>
/// A <see cref="Response"/> containing the result of the operation.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="hookId"/> or <paramref name="hook"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="hookId"/> is empty or not a valid GUID.</exception>
public virtual async Task<Response> UpdateHookAsync(string hookId, NotificationHook hook, CancellationToken cancellationToken = default)
/// <exception cref="ArgumentNullException"><paramref name="hook"/> or <paramref name="hook"/>.Id is null.</exception>
public virtual async Task<Response<NotificationHook>> UpdateHookAsync(NotificationHook hook, CancellationToken cancellationToken = default)
{
/*
Guid hookGuid = ClientCommon.ValidateGuid(hookId, nameof(hookId));
Argument.AssertNotNull(hook, nameof(hook));

if (hook.Id == null)
{
throw new ArgumentNullException(nameof(hook), $"{nameof(hook)}.Id not available. Call {nameof(GetHookAsync)} and update the returned model before calling this method.");
}

Guid hookGuid = new Guid(hook.Id);

using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsAdvisorAdministrationClient)}.{nameof(UpdateHook)}");
scope.Start();

Expand All @@ -1612,29 +1617,30 @@ public virtual async Task<Response> UpdateHookAsync(string hookId, NotificationH
scope.Failed(e);
throw;
}
*/

await Task.CompletedTask.ConfigureAwait(false);
return default;
}

/// <summary>
/// Updates an existing <see cref="NotificationHook"/>.
/// Updates an existing <see cref="NotificationHook"/>. In order to update your hook, you cannot create a <see cref="NotificationHook"/>
/// directly from its constructor. You need to obtain an instance via <see cref="GetHook"/> or another CRUD operation and update it
/// before calling this method.
/// </summary>
/// <param name="hookId">The ID of the existing <see cref="NotificationHook"/> to update.</param>
/// <param name="hook">The <see cref="NotificationHook"/> model containing the updates to be applied.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>
/// A <see cref="Response"/> containing the result of the operation.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="hookId"/> or <paramref name="hook"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="hookId"/> is empty or not a valid GUID.</exception>
public virtual Response UpdateHook(string hookId, NotificationHook hook, CancellationToken cancellationToken = default)
/// <exception cref="ArgumentNullException"><paramref name="hook"/> or <paramref name="hook"/>.Id is null.</exception>
public virtual Response<NotificationHook> UpdateHook(NotificationHook hook, CancellationToken cancellationToken = default)
{
/*
Guid hookGuid = ClientCommon.ValidateGuid(hookId, nameof(hookId));
Argument.AssertNotNull(hook, nameof(hook));

if (hook.Id == null)
{
throw new ArgumentNullException(nameof(hook), $"{nameof(hook)}.Id not available. Call {nameof(GetHook)} and update the returned model before calling this method.");
}

Guid hookGuid = new Guid(hook.Id);

using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsAdvisorAdministrationClient)}.{nameof(UpdateHook)}");
scope.Start();

Expand All @@ -1649,9 +1655,6 @@ public virtual Response UpdateHook(string hookId, NotificationHook hook, Cancell
scope.Failed(e);
throw;
}
*/

return default;
}

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

using System.Collections.Generic;

namespace Azure.AI.MetricsAdvisor.Models
{
internal partial class EmailHookParameterPatch
{
public IList<string> ToList { get; internal set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace Azure.AI.MetricsAdvisor.Models
{
internal partial class WebhookHookParameterPatch
{
public IDictionary<string, string> Headers { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,33 @@ internal NotificationHook(HookType hookType, string id, string name, string desc

internal static HookInfoPatch GetPatchModel(NotificationHook hook)
{
return hook switch
HookInfoPatch patch = hook switch
{
EmailNotificationHook h => new EmailHookInfoPatch() { HookName = h.Name, Description = h.Description, ExternalLink = h.ExternalLink?.AbsoluteUri, /*HookParameter = h.HookParameter,*/ Admins = h.AdministratorsEmails },
WebNotificationHook h => new WebhookHookInfoPatch() { HookName = h.Name, Description = h.Description, ExternalLink = h.ExternalLink?.AbsoluteUri, /*HookParameter = h.HookParameter,*/ Admins = h.AdministratorsEmails },
_ => throw new InvalidOperationException("Unknown AlertingHook type.")
EmailNotificationHook h => new EmailHookInfoPatch()
{
HookParameter = new() { ToList = h.EmailsToAlert }
},
WebNotificationHook h => new WebhookHookInfoPatch()
{
HookParameter = new()
{
Endpoint = h.Endpoint?.AbsoluteUri,
Username = h.Username,
Password = h.Password,
CertificateKey = h.CertificateKey,
CertificatePassword = h.CertificatePassword,
Headers = h.Headers
}
},
_ => throw new InvalidOperationException("Unknown hook type.")
};

patch.HookName = hook.Name;
patch.Description = hook.Description;
patch.ExternalLink = hook.ExternalLink?.AbsoluteUri;
patch.Admins = hook.AdministratorsEmails;

return patch;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,9 @@ public async Task UpdateAlertConfigurationWithMinimumSetupAndGetInstance(bool us

configToUpdate.CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.Or;

await adminClient.UpdateAlertConfigurationAsync(configToUpdate);
AnomalyAlertConfiguration updatedConfig = await adminClient.UpdateAlertConfigurationAsync(configToUpdate);

// Get the updated configuration and validate top-level members.

AnomalyAlertConfiguration updatedConfig = await adminClient.GetAlertConfigurationAsync(disposableConfig.Id);
// Validate top-level members.

Assert.That(updatedConfig.Id, Is.EqualTo(disposableConfig.Id));
Assert.That(updatedConfig.Name, Is.EqualTo(configName));
Expand Down Expand Up @@ -519,11 +517,9 @@ public async Task UpdateAlertConfigurationWithMinimumSetupAndNewInstance()
CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.Or
};

await adminClient.UpdateAlertConfigurationAsync(configToUpdate);

// Get the updated configuration and validate top-level members.
AnomalyAlertConfiguration updatedConfig = await adminClient.UpdateAlertConfigurationAsync(configToUpdate);

AnomalyAlertConfiguration updatedConfig = await adminClient.GetAlertConfigurationAsync(disposableConfig.Id);
// Validate top-level members.

Assert.That(updatedConfig.Id, Is.EqualTo(disposableConfig.Id));
Assert.That(updatedConfig.Name, Is.EqualTo(configName));
Expand Down Expand Up @@ -658,11 +654,9 @@ public async Task UpdateAlertConfigurationWithEveryMemberAndGetInstance()

metricAlertConfigToUpdate.AlertSnoozeCondition = null;

await adminClient.UpdateAlertConfigurationAsync(configToUpdate);
AnomalyAlertConfiguration updatedConfig = await adminClient.UpdateAlertConfigurationAsync(configToUpdate);

// Get the updated configuration and validate top-level members.

AnomalyAlertConfiguration updatedConfig = await adminClient.GetAlertConfigurationAsync(disposableConfig.Id);
// Validate top-level members.

Assert.That(updatedConfig.Id, Is.EqualTo(disposableConfig.Id));
Assert.That(updatedConfig.Name, Is.EqualTo(configName));
Expand Down Expand Up @@ -800,11 +794,9 @@ public async Task UpdateAlertConfigurationWithEveryMemberAndNewInstance()

metricAlertConfigToUpdate.AlertSnoozeCondition = null;

await adminClient.UpdateAlertConfigurationAsync(configToUpdate);

// Get the updated configuration and validate top-level members.
AnomalyAlertConfiguration updatedConfig = await adminClient.UpdateAlertConfigurationAsync(configToUpdate);

AnomalyAlertConfiguration updatedConfig = await adminClient.GetAlertConfigurationAsync(disposableConfig.Id);
// Validate top-level members.

Assert.That(updatedConfig.Id, Is.EqualTo(disposableConfig.Id));
Assert.That(updatedConfig.Name, Is.EqualTo(configName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,9 @@ public async Task UpdateDetectionConfigurationWithMinimumSetupAndGetInstance(boo

configToUpdate.WholeSeriesDetectionConditions.HardThresholdCondition.LowerBound = 12.0;

await adminClient.UpdateDetectionConfigurationAsync(configToUpdate);
AnomalyDetectionConfiguration updatedConfig = await adminClient.UpdateDetectionConfigurationAsync(configToUpdate);

// Get the updated configuration and validate top-level members.

AnomalyDetectionConfiguration updatedConfig = await adminClient.GetDetectionConfigurationAsync(disposableConfig.Id);
// Validate top-level members.

Assert.That(updatedConfig.Id, Is.EqualTo(disposableConfig.Id));
Assert.That(updatedConfig.MetricId, Is.EqualTo(MetricId));
Expand Down Expand Up @@ -512,11 +510,9 @@ public async Task UpdateDetectionConfigurationWithMinimumSetupAndNewInstance()

configToUpdate.WholeSeriesDetectionConditions.HardThresholdCondition.LowerBound = 12.0;

await adminClient.UpdateDetectionConfigurationAsync(configToUpdate);

// Get the updated configuration and validate top-level members.
AnomalyDetectionConfiguration updatedConfig = await adminClient.UpdateDetectionConfigurationAsync(configToUpdate);

AnomalyDetectionConfiguration updatedConfig = await adminClient.GetDetectionConfigurationAsync(disposableConfig.Id);
// Validate top-level members.

Assert.That(updatedConfig.Id, Is.EqualTo(disposableConfig.Id));
Assert.That(updatedConfig.MetricId, Is.EqualTo(MetricId));
Expand Down Expand Up @@ -652,11 +648,9 @@ public async Task UpdateDetectionConfigurationWithEveryMemberAndGetInstance()

configToUpdate.SeriesDetectionConditions.Clear();

await adminClient.UpdateDetectionConfigurationAsync(configToUpdate);
AnomalyDetectionConfiguration updatedConfig = await adminClient.UpdateDetectionConfigurationAsync(configToUpdate);

// Get the updated configuration and validate top-level members.

AnomalyDetectionConfiguration updatedConfig = await adminClient.GetDetectionConfigurationAsync(disposableConfig.Id);
// Validate top-level members.

Assert.That(updatedConfig.Id, Is.EqualTo(disposableConfig.Id));
Assert.That(updatedConfig.MetricId, Is.EqualTo(MetricId));
Expand Down Expand Up @@ -798,11 +792,9 @@ public async Task UpdateDetectionConfigurationWithEveryMemberAndNewInstance()

configToUpdate.SeriesDetectionConditions.Clear();

await adminClient.UpdateDetectionConfigurationAsync(configToUpdate);

// Get the updated configuration and validate top-level members.
AnomalyDetectionConfiguration updatedConfig = await adminClient.UpdateDetectionConfigurationAsync(configToUpdate);

AnomalyDetectionConfiguration updatedConfig = await adminClient.GetDetectionConfigurationAsync(disposableConfig.Id);
// Validate top-level members.

Assert.That(updatedConfig.Id, Is.EqualTo(disposableConfig.Id));
Assert.That(updatedConfig.MetricId, Is.EqualTo(MetricId));
Expand Down
Loading