.NET 用 Microsoft Azure Load Testing 管理クライアント ライブラリ

Microsoft Azure Load Testing は、大規模な負荷を生成できるフル マネージドのロード テスト サービスです。 サービスは、アプリケーションがどこにホストされているかにかかわらず、そのトラフィックをシミュレートします。 開発者、テスト担当者、品質保証 (QA) エンジニアは、それを使って、アプリケーションのパフォーマンス、スケーラビリティ、または容量を最適化できます。

このライブラリでは、Microsoft Azure Load Testing リソースの管理がサポートされています。

このライブラリは 、新しい Azure SDK ガイドラインに従い、多くのコア機能を提供します。

- Support MSAL.NET, Azure.Identity is out of box for supporting MSAL.NET.
- Support [OpenTelemetry](https://opentelemetry.io/) for distributed tracing.
- HTTP pipeline with custom policies.
- Better error-handling.
- Support uniform telemetry across all languages.

作業の開始

パッケージをインストールする

NuGet を使用して .NET 用の Microsoft Azure Load Testing 管理ライブラリをインストールします。

dotnet add package Azure.ResourceManager.LoadTesting

前提条件

クライアントの認証

認証されたクライアントを作成し、Microsoft Azure リソースとの対話を開始するには、 こちらのクイックスタート ガイドを参照してください。

主要な概念

Microsoft Azure SDK for .NETの主な概念については、こちらを参照してください

ドキュメント

ドキュメントは、このパッケージの使用方法を学習するのに役立ちます。

新しい Azure Load Testing リソースを作成する

Azure Load Testing リソースを作成する前に、リソース グループが必要です。

ArmClient armClient = new ArmClient(new DefaultAzureCredential());
SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupCollection rgCollection = subscription.GetResourceGroups();
// With the collection, we can create a new resource group with an specific name
string rgName = "sample-rg";
AzureLocation location = AzureLocation.WestUS2;
ArmOperation<ResourceGroupResource> resourceGroupLro = await rgCollection.CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location));
ResourceGroupResource resourceGroup = lro.Value;

Azure Load Testing リソースを作成します。

LoadTestingResourceCollection loadTestingCollection = _resourceGroup.GetLoadTestingResources();
string loadTestResourceName = "sample-loadtest";
LoadTestingResourceData inputPayload = new LoadTestingResourceData(AzureLocation.WestUS2);
ArmOperation<LoadTestingResource> loadTestingLro = await loadTestingCollection.CreateOrUpdateAsync(WaitUntil.Completed, loadTestResourceName, inputPayload);

LoadTestingResource resource = loadTestingLro.Value;

CMK 暗号化で構成された Azure Load Testing リソースを作成します。

LoadTestingResourceCollection loadTestingCollection = _resourceGroup.GetLoadTestingResources();
string loadTestResourceName = "sample-loadtest";
LoadTestingResourceData inputPayload = new LoadTestingResourceData(AzureLocation.WestUS2);

// Managed identity properties
ResourceIdentifier identityId = new ResourceIdentifier("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity1");
inputPayload.Identity = new ManagedServiceIdentity(ManagedServiceIdentityType.SystemAssignedUserAssigned);
inputPayload.Identity.UserAssignedIdentities.Add(identityId, new UserAssignedIdentity());

// CMK encryption properties
inputPayload.Encryption = new LoadTestingCmkEncryptionProperties();
inputPayload.Encryption.KeyUri = new Uri("https://sample-kv.vault.azure.net/keys/cmkkey/2d1ccd5c50234ea2a0858fe148b69cde");
inputPayload.Encryption.Identity = new LoadTestingCmkIdentity();
inputPayload.Encryption.Identity.IdentityType = LoadTestingCmkIdentityType.UserAssigned;
inputPayload.Encryption.Identity.ResourceId = identityId;

ArmOperation<LoadTestingResource> loadTestingLro = await loadTestingCollection.CreateOrUpdateAsync(WaitUntil.Completed, loadTestResourceName, inputPayload);

LoadTestingResource resource = loadTestingLro.Value;

Azure Load Testing リソースの詳細を取得する

LoadTestingResourceCollection loadTestingCollection = _resourceGroup.GetLoadTestingResources();

string loadTestResourceName = "sample-loadtest";
Response<LoadTestingResource> loadTestingResponse = await loadTestingCollection.GetAsync(loadTestResourceName);

LoadTestingResource resource = loadTestingResponse.Value;

Azure Load Testing リソースを更新する

システム割り当てマネージド ID を使用して CMK 暗号化を構成するように Azure Load Testing リソースを更新します。

LoadTestingResourceCollection loadTestingCollection = _resourceGroup.GetLoadTestingResources();
string loadTestResourceName = "sample-loadtest";
Response<LoadTestingResource> loadTestingResponse = await loadTestingCollection.GetAsync(loadTestResourceName);
LoadTestingResource resource = loadTestingResponse.Value;

ResourceIdentifier identityId = new ResourceIdentifier("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity1");
LoadTestingResourcePatch resourcePatchPayload = new LoadTestingResourcePatch {
    Encryption = new LoadTestingCmkEncryptionProperties
    {
        Identity = new LoadTestingCmkIdentity
        {
            // make sure that system-assigned managed identity is enabled on this resource and the identity has been granted required permissions to access the key.
            IdentityType = LoadTestingCmkIdentityType.SystemAssigned,
            ResourceId = null
        },
        KeyUri = new Uri("https://sample-kv.vault.azure.net/keys/cmkkey/2d1ccd5c50234ea2a0858fe148b69cde")
    }
};

ArmOperation<LoadTestingResource> loadTestingLro = await resource.UpdateAsync(WaitUntil.Completed, resourcePatchPayload);

LoadTestingResource updatedResource = loadTestingLro.Value;

Azure Load Testing リソースを更新して、ユーザー割り当てマネージド ID を更新します。

LoadTestingResourceCollection loadTestingCollection = _resourceGroup.GetLoadTestingResources();
string loadTestResourceName = "sample-loadtest";
Response<LoadTestingResource> loadTestingResponse = await loadTestingCollection.GetAsync(loadTestResourceName);
LoadTestingResource resource = loadTestingResponse.Value;

ResourceIdentifier identityId1 = new ResourceIdentifier("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity1");
ResourceIdentifier identityId2 = new ResourceIdentifier("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity2");

LoadTestingResourcePatch resourcePatchPayload = new LoadTestingResourcePatch();
resourcePatchPayload.Identity = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned);
// removes user-assigned identity with resourceId <identityId1> (if already assigned to the load testing resource)
resourcePatchPayload.Identity.UserAssignedIdentities.Add(identityId1, null);
resourcePatchPayload.Identity.UserAssignedIdentities.Add(identityId2, new UserAssignedIdentity());

ArmOperation<LoadTestingResource> loadTestingLro = await resource.UpdateAsync(WaitUntil.Completed, resourcePatchPayload);
LoadTestingResource updatedResource = loadTestingLro.Value;

Azure Load Testing リソースを削除する

LoadTestingResourceCollection loadTestingCollection = _resourceGroup.GetLoadTestingResources();
string loadTestResourceName = "sample-loadtest";
Response<LoadTestingResource> loadTestingResponse = await loadTestingCollection.GetAsync(loadTestResourceName);
LoadTestingResource resource = loadTestingResponse.Value;

ArmOperation loadTestDeleteResponse = await resource.DeleteAsync(WaitUntil.Completed);

クォータ操作

Load Testing クォータ コレクションを取得します。

LoadTestingQuotaCollection QuotaCollection = _subscription.GetAllLoadTestingQuota(AzureLocation.WestUS2);
// Use the quotaCollection for all the quota operations.

特定のクォータ バケットのクォータ値を取得します。

LoadTestingQuotaCollection QuotaCollection = _subscription.GetAllLoadTestingQuota(AzureLocation.WestUS2);

// Get the quota values for a particular quota bucket
Response<LoadTestingQuotaResource> quotaResponse = await QuotaCollection.GetAsync("maxConcurrentTestRuns");
LoadTestingQuotaResource quotaBucket = quotaResponse.Value;

すべてのクォータ バケットのクォータ値を取得します。

LoadTestingQuotaCollection QuotaCollection = _subscription.GetAllLoadTestingQuota(AzureLocation.WestUS2);

// Get the quota values for a all quota buckets
List<LoadTestingQuotaResource> quotaBuckets = await QuotaCollection.GetAllAsync().ToEnumerableAsync();

クォータの可用性を確認します。

LoadTestingQuotaCollection QuotaCollection = _subscription.GetAllLoadTestingQuota(AzureLocation.WestUS2);

Response<LoadTestingQuotaResource> quotaResponse = await QuotaCollection.GetAsync("maxConcurrentTestRuns");
LoadTestingQuotaResource quotaResource = quotaResponse.Value;

LoadTestingQuotaBucketDimensions dimensions = new LoadTestingQuotaBucketDimensions("<subscription-id>", AzureLocation.WestUS2);
LoadTestingQuotaBucketContent quotaAvailabilityPayload = new LoadTestingQuotaBucketContent(
    quotaResponse.Value.Data.Id,
    quotaResource.Data.Name,
    quotaResource.Data.ResourceType,
    null,
    quotaResource.Data.Usage,
    quotaResource.Data.Limit,
    50, // new quota value
    dimensions);

Response<LoadTestingQuotaAvailabilityResult> checkAvailabilityResult = await quotaResponse.Value.CheckLoadTestingQuotaAvailabilityAsync(quotaAvailabilityPayload);
// IsAvailable property indicates whether the requested quota is available.
Console.WriteLine(checkAvailabilityResult.Value.IsAvailable);

.NET 用管理ライブラリを使用するためのコード サンプルは、次の場所にあります。

トラブルシューティング

次のステップ

Microsoft Azure SDK の詳細については、 こちらの Web サイトを参照してください。

共同作成

このリポジトリへの投稿の詳細については、 投稿ガイドを参照してください。

このプロジェクトでは、共同作成と提案を歓迎しています。 ほとんどの共同作成では、共同作成者使用許諾契約書 (CLA) にご同意いただき、ご自身の共同作成内容を使用する権利を Microsoft に供与する権利をお持ちであり、かつ実際に供与することを宣言していただく必要があります。 詳細については、 https://cla.microsoft.com を参照してください。

pull request を送信すると、CLA を提供して PR (ラベルやコメントなど) を適宜装飾する必要があるかどうかを CLA ボットが自動的に決定します。 ボットによって提供される手順に従ってください。 このアクションは、CLA を使用してすべてのリポジトリで 1 回だけ実行する必要があります。

このプロジェクトは、「Microsoft のオープン ソースの倫理規定」を採用しています。 詳しくは、倫理規定についてよくある質問に関する記事を参照するか、opencode@microsoft.com 宛てに質問またはコメントをお送りください。