次の方法で共有


JavaScript 用 Azure LoadTest クライアント ライブラリ - バージョン 1.0.0

このパッケージには、Azure LoadTest クライアント用の同型 SDK (Node.jsとブラウザーの両方で実行されます) が含まれています。

LoadTest クライアントは、LoadTest リソースへのアクセスを提供し、状態操作です。

ソースコード | パッケージ (NPM) | API リファレンス ドキュメント | サンプル

はじめに

現在サポートされている環境

詳細については、Microsoft のサポート ポリシーを参照してください。

前提条件

@azure/arm-loadtesting パッケージのインストール

を使用して、JavaScript 用の Azure LoadTest クライアント ライブラリを npmインストールします。

npm install @azure/arm-loadtesting

LoadTestClient を作成して認証する

Azure LoadTest API にアクセスするためのクライアント オブジェクトを作成するには、Azure LoadTest リソースの と がcredential必要endpointです。 Azure LoadTest クライアントは、Azure Active Directory 資格情報を使用して認証できます。 Azure Portal で Azure LoadTest リソースのエンドポイントを見つけることができます。

@azure/ID ライブラリまたは既存の AAD トークンからの資格情報を使用して、Azure Active Directory で認証できます。

次に示す DefaultAzureCredential プロバイダー、または Azure SDK で提供されているその他の資格情報プロバイダーを使用するには、パッケージを @azure/identity インストールしてください。

npm install @azure/identity

また、サービス プリンシパルに適切なロールを割り当てることで、 新しい AAD アプリケーションを登録し、Azure LoadTest へのアクセス 権を付与する必要があります (注: などの "Owner" ロールは、必要なアクセス許可を付与しません)。 環境変数として、AAD アプリケーションのクライアント ID、テナント ID、およびクライアント シークレットの値を設定します。 AZURE_CLIENT_IDAZURE_TENANT_IDAZURE_CLIENT_SECRET

Azure AD アプリケーションを作成する方法の詳細については、 このガイドを参照してください。

const { LoadTestClient } = require("@azure/arm-loadtesting");
const { DefaultAzureCredential } = require("@azure/identity");
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new LoadTestClient(new DefaultAzureCredential(), subscriptionId);

// For client-side applications running in the browser, use this code instead:
// const credential = new InteractiveBrowserCredential({
//   tenantId: "<YOUR_TENANT_ID>",
//   clientId: "<YOUR_CLIENT_ID>"
// });
// const client = new LoadTestClient(credential, subscriptionId);

Azure Load Testing のリソースを作成する

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

loadTestResourceCreatePayload = {
  location: "westus2"
};

const resource = await client.loadTests.beginCreateOrUpdateAndWait(
  "sample-rg",
  "sample-loadtesting-resource",
  loadTestResourceCreatePayload
);

console.log(resource);

マネージド ID とカスタマー マネージド キー暗号化を使用して、新しい Azure Load Testing リソースを作成します。

loadTestResourceCreatePayload = {
  location: "westus2",
  tags: { team: "testing" },
  identity: {
    type: 'SystemAssigned, UserAssigned',
    userAssignedIdentities: {
      '/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity1': {}
    }
  },
  encryption: {
    identity: {
      type: 'UserAssigned',
      resourceId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity1'
    },
    keyUrl: 'https://sample-kv.vault.azure.net/keys/cmkkey/2d1ccd5c50234ea2a0858fe148b69cde'
  }
};

const resource = await client.loadTests.beginCreateOrUpdateAndWait(
  "sample-rg",
  "sample-loadtesting-resource",
  loadTestResourceCreatePayload
);

console.log(resource);

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

let resourceName = 'sample-loadtesting-resource';
let resourceGroupName = 'sample-rg';

const resource = await client.loadTests.get(
  resourceGroupName,
  resourceName
);

console.log(resource);

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

loadTestResourcePatchPayload = {
  tags: { team: "testing-dev" },
  identity: {
    type: 'SystemAssigned, UserAssigned',
    userAssignedIdentities: {
      // removing a user-assigned managed identity by assigning the value in the payload as null
      '/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity1': null,
      '/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity2': {}
    }
  },
  encryption: {
    // use system-assigned managed identity for CMK encryption
    identity: {
      type: 'SystemAssigned',
      resourceId: null
    },
    keyUrl: 'https://sample-kv.vault.azure.net/keys/cmkkey/2d1ccd5c50234ea2a0858fe148b69cde'
  }
};

const resource = await client.loadTests.beginUpdateAndWait(
  "sample-rg",
  "sample-loadtesting-resource",
  loadTestResourcePatchPayload
);

console.log(resource);

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

let resourceName = 'sample-loadtesting-resource';
let resourceGroupName = 'sample-rg';

const result = await client.loadTests.beginDeleteAndWait(
  resourceGroupName,
  resourceName
);

JavaScript バンドル

ブラウザーでこのクライアント ライブラリを使用するには、まず bundler を使用する必要があります。 これを行う方法の詳細については、 バンドルに関するドキュメントを参照してください。

主要な概念

LoadTestClient

LoadTestClient は、Azure LoadTest クライアント ライブラリを使用する開発者向けの主要なインターフェイスです。 このクライアント オブジェクトのメソッドを調べて、アクセスできる Azure LoadTest サービスのさまざまな機能を理解します。

トラブルシューティング

ログの記録

ログの記録を有効にすると、エラーに関する有用な情報を明らかにするのに役立つ場合があります。 HTTP 要求と応答のログを表示するには、環境変数 AZURE_LOG_LEVELinfo に設定します。 または、@azure/loggersetLogLevel を呼び出して、実行時にログ記録を有効にすることもできます。

const { setLogLevel } = require("@azure/logger");
setLogLevel("info");

ログを有効にする方法の詳細については、@azure/logger パッケージに関するドキュメントを参照してください。

次の手順

このライブラリの使用方法の詳細な例については、 サンプル ディレクトリを参照してください。

共同作成

このライブラリに投稿する場合、コードをビルドしてテストする方法の詳細については、投稿ガイドを参照してください。

インプレッション数