Azure Veri Gezgini için veritabanı ve tablo ilkeleri oluşturma

Azure Veri Gezgini, günlük ve telemetri verileri için hızlı ve yüksek oranda ölçeklenebilir veri keşfetme hizmetidir. Bu makalede, C# veya Python kullanarak Azure Veri Gezgini için veritabanı ve tablo ilkeleri oluşturacaksınız.

Önkoşullar

Paketleri yükleme

Kimlik doğrulama

Bu makaledeki örnekleri çalıştırmak için kaynaklara erişebilen bir Azure AD uygulamasına ve hizmet sorumlusuna ihtiyacınız vardır. Gerekirse bir Azure AD uygulaması oluşturun ve abonelikte uygun rol atamaları verin. Dizin (kiracı) Kimliği, Uygulama Kimliği ve İstemci Gizli Anahtarı'nı kaydedin.

Yeni Azure AD uygulamasını veritabanına sorumlu olarak eklemeniz gerekebilir. Daha fazla bilgi için bkz. Azure Veri Gezgini veritabanı izinlerini yönetme.

Veritabanı bekletme ilkesini değiştirme

Aşağıdaki örnek, 10 günlük yumuşak silme süresine sahip bir bekletme ilkesi ayarlar.

var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; // Azure AD Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; // Application ID
var clientSecret = "PlaceholderClientSecret"; // Application secret
var subscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
// Create a confidential authentication client for Azure AD:
var authClient = ConfidentialClientApplicationBuilder.Create(clientId)
    .WithAuthority($"https://login.microsoftonline.com/{tenantId}")
    .WithClientSecret(clientSecret) // can be replaced by .WithCertificate to authenticate with an X.509 certificate
    .Build();
// Acquire application token
var result = authClient.AcquireTokenForClient(
    new[] { "https://management.core.windows.net/.default" } // Define scopes for accessing Azure management plane
).ExecuteAsync().Result;
var credentials = new TokenCredentials(result.AccessToken, result.TokenType);
var kustoManagementClient = new KustoManagementClient(credentials) { SubscriptionId = subscriptionId };
var resourceGroupName = "testrg";
// The cluster and database that are created as part of the prerequisites
var clusterName = "mykustocluster";
var databaseName = "mykustodatabase";
var databasePatch = new ReadWriteDatabase(softDeletePeriod: TimeSpan.FromDays(10));
await kustoManagementClient.Databases.UpdateAsync(resourceGroupName, clusterName, databaseName, databasePatch);

Veritabanı önbellek ilkesini değiştirme

Aşağıdaki örnek, veritabanı için bir önbellek ilkesi ayarlar. Önceki beş günlük veriler küme SSD'sinde olacaktır.

var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; // Azure AD Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; // Application ID
var clientSecret = "PlaceholderClientSecret"; // Application secret
var subscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
// Create a confidential authentication client for Azure AD:
var authClient = ConfidentialClientApplicationBuilder.Create(clientId)
    .WithAuthority($"https://login.microsoftonline.com/{tenantId}")
    .WithClientSecret(clientSecret) // can be replaced by .WithCertificate to authenticate with an X.509 certificate
    .Build();
// Acquire application token
var result = authClient.AcquireTokenForClient(
    new[] { "https://management.core.windows.net/.default" } // Define scopes for accessing Azure management plane
).ExecuteAsync().Result;
var credentials = new TokenCredentials(result.AccessToken, result.TokenType);
var kustoManagementClient = new KustoManagementClient(credentials) { SubscriptionId = subscriptionId };
var resourceGroupName = "testrg";
// The cluster and database that are created as part of the prerequisites
var clusterName = "mykustocluster";
var databaseName = "mykustodatabase";
var databasePatch = new ReadWriteDatabase(hotCachePeriod: TimeSpan.FromDays(10));
await kustoManagementClient.Databases.UpdateAsync(resourceGroupName, clusterName, databaseName, databasePatch);

Tablo önbelleği ilkesini değiştirme

Aşağıdaki örnek Kusto Veri SDK'sını kullanarak tablo için bir önbellek ilkesi ayarlar. Bu kod parçacığı, kümenin sık erişimli önbelleğini (yerel SSD'ler) en son beş günlük verileri barındıracak şekilde yapılandırır.

var kustoUri = "https://<clusterName>.<region>.kusto.windows.net/";
var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; // Azure AD Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; // Application ID
var clientSecret = "PlaceholderClientSecret"; // Application secret
var kustoConnectionStringBuilder = new KustoConnectionStringBuilder(kustoUri)
    .WithAadApplicationKeyAuthentication(clientId, clientSecret, tenantId);
using var kustoClient = KustoClientFactory.CreateCslAdminProvider(kustoConnectionStringBuilder);
var command = CslCommandGenerator.GenerateAlterTableCachingPolicyCommand(
    "<tableName>", hotSpan: TimeSpan.FromDays(5)
);
await kustoClient.ExecuteControlCommandAsync("<databaseName>", command);

Veritabanı için yeni bir sorumlu ekleme

Aşağıdaki örnek, veritabanı için yönetici sorumlusu olarak yeni bir Azure AD uygulaması ekler.

var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; // Azure AD Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; // Application ID
var clientSecret = "PlaceholderClientSecret"; // Application secret
var subscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
// Create a confidential authentication client for Azure AD:
var authClient = ConfidentialClientApplicationBuilder.Create(clientId)
    .WithAuthority($"https://login.microsoftonline.com/{tenantId}")
    .WithClientSecret(clientSecret) // can be replaced by .WithCertificate to authenticate with an X.509 certificate
    .Build();
// Acquire application token
var result = authClient.AcquireTokenForClient(
    new[] { "https://management.core.windows.net/.default" } // Define scopes for accessing Azure management plane
).ExecuteAsync().Result;
var credentials = new TokenCredentials(result.AccessToken, result.TokenType);
var kustoManagementClient = new KustoManagementClient(credentials) { SubscriptionId = subscriptionId };
var resourceGroupName = "testrg";
// The cluster and database that are created as part of the prerequisites
var clusterName = "mykustocluster";
var databaseName = "mykustodatabase";
var databasePrincipalListRequest = new DatabasePrincipalListRequest
{
    Value = new List<DatabasePrincipal> { new("Admin", "<databasePrincipalName>", "App", appId: clientId, tenantName: tenantId) }
};
await kustoManagementClient.Databases.AddPrincipalsAsync(resourceGroupName, clusterName, databaseName, databasePrincipalListRequest);

Sonraki adımlar