Skip to content

Commit

Permalink
[MetricsAdvisor] Added Authentication and CredentiaId properties to D…
Browse files Browse the repository at this point in the history
…ata Feed Sources (#21626)
  • Loading branch information
kinelski authored Jun 7, 2021
1 parent dc35567 commit 755b7e2
Show file tree
Hide file tree
Showing 89 changed files with 20,419 additions and 2,067 deletions.
2 changes: 2 additions & 0 deletions sdk/metricsadvisor/Azure.AI.MetricsAdvisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### New Features
- Added `DatasourceCredential` CRUD operations to the `MetricsAdvisorAdministrationClient`. This API provides new ways of authenticating to a `DataFeedSource`.
- Added property `Authentication` to data sources `AzureBlobDataFeedSource`, `AzureDataExplorerDataFeedSource`, `AzureDataLakeStorageGen2DataFeedSource`, and `SqlServerDataFeedSource` to specify the authentication type to use.
- Added property `DatasourceCredentialId` to data sources `AzureDataExplorerDataFeedSource`, `AzureDataLakeStorageGen2DataFeedSource`, and `SqlServerDataFeedSource` to specify the datasource credential to use for authentication.
- Added properties `Value` and `ExpectedValue` to `DataPointAnomaly` to provide more information about the anomalous data point.
- Added properties `ValueOfRootNode` and `ExpectedValueOfRootNode` to `AnomalyIncident` to provide more information about the anomalous data point at the root node of the indicent.
- Response headers that were marked as `REDACTED` in error messages and logs are now exposed by default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,15 @@ public void UpdateApiKey(string apiKey) { }
public partial class AzureBlobDataFeedSource : Azure.AI.MetricsAdvisor.Models.DataFeedSource
{
public AzureBlobDataFeedSource(string connectionString, string container, string blobTemplate) { }
public Azure.AI.MetricsAdvisor.Models.AzureBlobDataFeedSource.AuthenticationType? Authentication { get { throw null; } set { } }
public string BlobTemplate { get { throw null; } set { } }
public string Container { get { throw null; } set { } }
public void UpdateConnectionString(string connectionString) { }
public enum AuthenticationType
{
Basic = 0,
ManagedIdentity = 1,
}
}
public partial class AzureCosmosDbDataFeedSource : Azure.AI.MetricsAdvisor.Models.DataFeedSource
{
Expand All @@ -470,17 +476,35 @@ public void UpdateConnectionString(string connectionString) { }
public partial class AzureDataExplorerDataFeedSource : Azure.AI.MetricsAdvisor.Models.DataFeedSource
{
public AzureDataExplorerDataFeedSource(string connectionString, string query) { }
public Azure.AI.MetricsAdvisor.Models.AzureDataExplorerDataFeedSource.AuthenticationType? Authentication { get { throw null; } set { } }
public string DatasourceCredentialId { get { throw null; } set { } }
public string Query { get { throw null; } set { } }
public void UpdateConnectionString(string connectionString) { }
public enum AuthenticationType
{
Basic = 0,
ManagedIdentity = 1,
ServicePrincipal = 2,
ServicePrincipalInKeyVault = 3,
}
}
public partial class AzureDataLakeStorageGen2DataFeedSource : Azure.AI.MetricsAdvisor.Models.DataFeedSource
{
public AzureDataLakeStorageGen2DataFeedSource(string accountName, string accountKey, string fileSystemName, string directoryTemplate, string fileTemplate) { }
public string AccountName { get { throw null; } set { } }
public Azure.AI.MetricsAdvisor.Models.AzureDataLakeStorageGen2DataFeedSource.AuthenticationType? Authentication { get { throw null; } set { } }
public string DatasourceCredentialId { get { throw null; } set { } }
public string DirectoryTemplate { get { throw null; } set { } }
public string FileSystemName { get { throw null; } set { } }
public string FileTemplate { get { throw null; } set { } }
public void UpdateAccountKey(string accountKey) { }
public enum AuthenticationType
{
Basic = 0,
SharedKey = 1,
ServicePrincipal = 2,
ServicePrincipalInKeyVault = 3,
}
}
public partial class AzureEventHubsDataFeedSource : Azure.AI.MetricsAdvisor.Models.DataFeedSource
{
Expand Down Expand Up @@ -1199,8 +1223,18 @@ public void UpdateConnectionString(string connectionString) { }
public partial class SqlServerDataFeedSource : Azure.AI.MetricsAdvisor.Models.DataFeedSource
{
public SqlServerDataFeedSource(string connectionString, string query) { }
public Azure.AI.MetricsAdvisor.Models.SqlServerDataFeedSource.AuthenticationType? Authentication { get { throw null; } set { } }
public string DatasourceCredentialId { get { throw null; } set { } }
public string Query { get { throw null; } set { } }
public void UpdateConnectionString(string connectionString) { }
public enum AuthenticationType
{
Basic = 0,
ManagedIdentity = 1,
SqlConnectionString = 2,
ServicePrincipal = 3,
ServicePrincipalInKeyVault = 4,
}
}
public partial class SuppressCondition
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Azure.AI.MetricsAdvisor.Models
{
// TODO: expose it as part of 1.0.0-beta.4
internal readonly partial struct AuthenticationTypeEnum
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ internal DataFeedDetail GetDataFeedDetail()
detail.Viewers.Add(viewer);
}

SetAuthenticationProperties(detail, DataSource);

return detail;
}

Expand Down Expand Up @@ -247,7 +249,53 @@ internal DataFeedDetailPatch GetPatchModel()
patch.Admins = AdministratorsEmails;
patch.Viewers = ViewersEmails;

SetAuthenticationProperties(patch, DataSource);

return patch;
}

private static void SetAuthenticationProperties(DataFeedDetail detail, DataFeedSource dataSource)
{
switch (dataSource)
{
case AzureBlobDataFeedSource s:
detail.AuthenticationType = s.GetAuthenticationTypeEnum();
break;
case AzureDataExplorerDataFeedSource s:
detail.AuthenticationType = s.GetAuthenticationTypeEnum();
detail.CredentialId = s.DatasourceCredentialId;
break;
case AzureDataLakeStorageGen2DataFeedSource s:
detail.AuthenticationType = s.GetAuthenticationTypeEnum();
detail.CredentialId = s.DatasourceCredentialId;
break;
case SqlServerDataFeedSource s:
detail.AuthenticationType = s.GetAuthenticationTypeEnum();
detail.CredentialId = s.DatasourceCredentialId;
break;
}
}

private static void SetAuthenticationProperties(DataFeedDetailPatch patch, DataFeedSource dataSource)
{
switch (dataSource)
{
case AzureBlobDataFeedSource s:
patch.AuthenticationType = s.GetAuthenticationTypeEnum();
break;
case AzureDataExplorerDataFeedSource s:
patch.AuthenticationType = s.GetAuthenticationTypeEnum();
patch.CredentialId = s.DatasourceCredentialId;
break;
case AzureDataLakeStorageGen2DataFeedSource s:
patch.AuthenticationType = s.GetAuthenticationTypeEnum();
patch.CredentialId = s.DatasourceCredentialId;
break;
case SqlServerDataFeedSource s:
patch.AuthenticationType = s.GetAuthenticationTypeEnum();
patch.CredentialId = s.DatasourceCredentialId;
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ internal static DataFeedSource GetDataFeedSource(DataFeedDetail dataFeedDetail)
dataFeedDetail switch
{
AzureApplicationInsightsDataFeed d => new AzureApplicationInsightsDataFeedSource(d.DataSourceParameter),
AzureBlobDataFeed d => new AzureBlobDataFeedSource(d.DataSourceParameter),
AzureBlobDataFeed d => new AzureBlobDataFeedSource(d.DataSourceParameter, d.AuthenticationType),
AzureCosmosDBDataFeed d => new AzureCosmosDbDataFeedSource(d.DataSourceParameter),
AzureDataExplorerDataFeed d => new AzureDataExplorerDataFeedSource(d.DataSourceParameter),
AzureDataLakeStorageGen2DataFeed d => new AzureDataLakeStorageGen2DataFeedSource(d.DataSourceParameter),
AzureDataExplorerDataFeed d => new AzureDataExplorerDataFeedSource(d.DataSourceParameter, d.AuthenticationType, d.CredentialId),
AzureDataLakeStorageGen2DataFeed d => new AzureDataLakeStorageGen2DataFeedSource(d.DataSourceParameter, d.AuthenticationType, d.CredentialId),
AzureEventHubsDataFeed d => new AzureEventHubsDataFeedSource(d.DataSourceParameter),
AzureLogAnalyticsDataFeed d => new LogAnalyticsDataFeedSource(d.DataSourceParameter),
AzureTableDataFeed d => new AzureTableDataFeedSource(d.DataSourceParameter),
InfluxDBDataFeed d => new InfluxDbDataFeedSource(d.DataSourceParameter),
MongoDBDataFeed d => new MongoDbDataFeedSource(d.DataSourceParameter),
MySqlDataFeed d => new MySqlDataFeedSource(d.DataSourceParameter),
PostgreSqlDataFeed d => new PostgreSqlDataFeedSource(d.DataSourceParameter),
SQLServerDataFeed d => new SqlServerDataFeedSource(d.DataSourceParameter),
SQLServerDataFeed d => new SqlServerDataFeedSource(d.DataSourceParameter, d.AuthenticationType, d.CredentialId),
_ => throw new InvalidOperationException("Invalid DataFeedDetail type")
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,42 @@ public AzureBlobDataFeedSource(string connectionString, string container, string
BlobTemplate = blobTemplate;
}

internal AzureBlobDataFeedSource(AzureBlobParameter parameter)
internal AzureBlobDataFeedSource(AzureBlobParameter parameter, AuthenticationTypeEnum? authentication)
: base(DataFeedSourceType.AzureBlob)
{
Argument.AssertNotNull(parameter, nameof(parameter));

ConnectionString = parameter.ConnectionString;
Container = parameter.Container;
BlobTemplate = parameter.BlobTemplate;

SetAuthentication(authentication);
}

/// <summary>
/// The different ways of authenticating to an <see cref="AzureBlobDataFeedSource"/>.
/// Defaults to <see cref="Basic"/>.
/// </summary>
public enum AuthenticationType
{
/// <summary>
/// Only uses the <see cref="ConnectionString"/> present in this <see cref="AzureBlobDataFeedSource"/>
/// instance for authentication.
/// </summary>
Basic,

/// <summary>
/// Uses Managed Identity authentication.
/// </summary>
ManagedIdentity
};

/// <summary>
/// The method used to authenticate to this <see cref="AzureDataExplorerDataFeedSource"/>. Defaults to
/// <see cref="AuthenticationType.Basic"/>.
/// </summary>
public AuthenticationType? Authentication { get; set; }

/// <summary>
/// The name of the blob container.
/// </summary>
Expand Down Expand Up @@ -120,5 +146,25 @@ public void UpdateConnectionString(string connectionString)
Argument.AssertNotNullOrEmpty(connectionString, nameof(connectionString));
ConnectionString = connectionString;
}

internal AuthenticationTypeEnum? GetAuthenticationTypeEnum() => Authentication switch
{
null => default(AuthenticationTypeEnum?),
AuthenticationType.Basic => AuthenticationTypeEnum.Basic,
AuthenticationType.ManagedIdentity => AuthenticationTypeEnum.ManagedIdentity,
_ => throw new InvalidOperationException($"Unknown authentication type: {Authentication}")
};

internal void SetAuthentication(AuthenticationTypeEnum? authentication)
{
if (authentication == AuthenticationTypeEnum.Basic)
{
Authentication = AuthenticationType.Basic;
}
else if (authentication == AuthenticationTypeEnum.ManagedIdentity)
{
Authentication = AuthenticationType.ManagedIdentity;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,65 @@ public AzureDataExplorerDataFeedSource(string connectionString, string query)
Query = query;
}

internal AzureDataExplorerDataFeedSource(SqlSourceParameter parameter)
internal AzureDataExplorerDataFeedSource(SqlSourceParameter parameter, AuthenticationTypeEnum? authentication, string credentialId)
: base(DataFeedSourceType.AzureDataExplorer)
{
Argument.AssertNotNull(parameter, nameof(parameter));

ConnectionString = parameter.ConnectionString;
Query = parameter.Query;

SetAuthentication(authentication);
DatasourceCredentialId = credentialId;
}

/// <summary>
/// The different ways of authenticating to an <see cref="AzureDataExplorerDataFeedSource"/>. Be aware that
/// some authentication types require you to have a <see cref="DatasourceCredential"/> in the service. In this
/// case, you also need to set the property <see cref="DatasourceCredentialId"/> to specify which credential
/// to use. Defaults to <see cref="Basic"/>.
/// </summary>
public enum AuthenticationType
{
/// <summary>
/// Only uses the <see cref="ConnectionString"/> present in this <see cref="AzureDataExplorerDataFeedSource"/>
/// instance for authentication.
/// </summary>
Basic,

/// <summary>
/// Uses Managed Identity authentication.
/// </summary>
ManagedIdentity,

/// <summary>
/// Uses Service Principal authentication. You need to have a <see cref="ServicePrincipalDatasourceCredential"/>
/// in the server in order to use this type of authentication.
/// </summary>
ServicePrincipal,

/// <summary>
/// Uses Service Principal authentication, but the client ID and the client secret must be
/// stored in a Key Vault resource. You need to have a <see cref="ServicePrincipalInKeyVaultDatasourceCredential"/>
/// in the server in order to use this type of authentication.
/// </summary>
ServicePrincipalInKeyVault
};

/// <summary>
/// The method used to authenticate to this <see cref="AzureDataExplorerDataFeedSource"/>. Be aware that some
/// authentication types require you to have a <see cref="DatasourceCredential"/> in the service. In this
/// case, you also need to set the property <see cref="DatasourceCredentialId"/> to specify which credential
/// to use. Defaults to <see cref="AuthenticationType.Basic"/>.
/// </summary>
public AuthenticationType? Authentication { get; set; }

/// <summary>
/// The ID of the <see cref="DatasourceCredential"/> to use for authentication. The type of authentication to use
/// must also be specified in the property <see cref="Authentication"/>.
/// </summary>
public string DatasourceCredentialId { get; set; }

/// <summary>
/// The query to retrieve the data to be ingested.
/// </summary>
Expand All @@ -65,5 +115,35 @@ public void UpdateConnectionString(string connectionString)
Argument.AssertNotNullOrEmpty(connectionString, nameof(connectionString));
ConnectionString = connectionString;
}

internal AuthenticationTypeEnum? GetAuthenticationTypeEnum() => Authentication switch
{
null => default(AuthenticationTypeEnum?),
AuthenticationType.Basic => AuthenticationTypeEnum.Basic,
AuthenticationType.ManagedIdentity => AuthenticationTypeEnum.ManagedIdentity,
AuthenticationType.ServicePrincipal => AuthenticationTypeEnum.ServicePrincipal,
AuthenticationType.ServicePrincipalInKeyVault => AuthenticationTypeEnum.ServicePrincipalInKV,
_ => throw new InvalidOperationException($"Unknown authentication type: {Authentication}")
};

internal void SetAuthentication(AuthenticationTypeEnum? authentication)
{
if (authentication == AuthenticationTypeEnum.Basic)
{
Authentication = AuthenticationType.Basic;
}
else if (authentication == AuthenticationTypeEnum.ManagedIdentity)
{
Authentication = AuthenticationType.ManagedIdentity;
}
else if (authentication == AuthenticationTypeEnum.ServicePrincipal)
{
Authentication = AuthenticationType.ServicePrincipal;
}
else if (authentication == AuthenticationTypeEnum.ServicePrincipalInKV)
{
Authentication = AuthenticationType.ServicePrincipalInKeyVault;
}
}
}
}
Loading

0 comments on commit 755b7e2

Please sign in to comment.