概要

Multistep API tests allow you to chain several HTTP requests or gRPC requests at once to proactively monitor and ensure that the sophisticated journeys on your key services are available at anytime, and from anywhere. If you want to perform single requests to your services, use API tests.

以下を実現できます。

  • 認証を必要とする API エンドポイントで HTTP リクエストを実行します (たとえば、トークンを介して)
  • API レベルで主要なビジネストランザクションを監視します
  • エンドツーエンドのモバイルアプリケーションのジャーニーをシミュレートします
マルチステップ API テストの複数のテストステップ

サービスの 1 つが応答遅延を起こしたり、予期しない方法 (たとえば、予期しない応答本文やステータスコード) で応答を開始した場合、テストはチームに警告するCI パイプラインをブロックする、または障害のあるデプロイをロールバックすることができます。

Multistep API テストは、Datadog 管理ロケーションおよびプライベートロケーションから実行できるため、外部と内部の両方でシステムを完全にカバーできます。

構成

テストに名前を付けてタグを付ける

  1. Multistep API テストに名前を付けます。
  2. Multistep API テストに env タグおよび他のタグを追加します。これらのタグを使用して、Synthetic Monitoring & Continuous Testing ページで Synthetic テストをフィルタリングできます。

ロケーションを選択する

Multistep API テストのロケーションを選択します。Multistep API テストは、ネットワークの外部または内部のどちらからテストを実行するかの好みによって、管理ロケーションとプライベートロケーションの両方から実行できます。

Datadog’s out-of-the-box managed locations allow you to test public-facing websites and endpoints from regions where your customers are located.

AmericasAPACEMEA
Canada Central (AWS)Hong Kong (AWS)Cape Town (AWS)
Northern California (AWS)Mumbai (AWS)Frankfurt (AWS)
Northern Virginia (AWS)Seoul (AWS)Ireland (AWS)
Ohio (AWS)Singapore (AWS)London (AWS)
Oregon (AWS)Sydney (AWS)Paris (AWS)
São Paulo (AWS)Tokyo (AWS)Stockholm (AWS)
Virginia (Azure)Osaka (AWS)Milan (AWS)
Jakarta (AWS)Bahrain (AWS)

The Datadog for Government site (US1-FED) uses the following managed location:

Americas
US-West

ステップを定義する

To create an API request step, click Create Your First Step.

Multistep API テストリクエストを作成する

デフォルトでは、最大 10 個のテストステップを作成することができます。この制限を増やすには、Datadog サポートに連絡してください。

リクエストを定義する

  1. ステップに名前を付けます。

  2. リクエストタイプとして HTTP または gRPC を選択します。

    See the HTTP Tests documentation to create an HTTP request and add assertions. Assertions are optional in multistep API tests.

    See the gRPC Tests documentation to create a gRPC request and add assertions for a behavior check or a health check. Assertions are optional in multistep API tests.

実行パラメーターの追加

Continue with test if this step fails をクリックすると、ステップに失敗しても次のステップに進むことができます。こうすることで、テストが後始末をすることができます。例えば、あるテストでは、リソースを作成し、そのリソースに対していくつかのアクションを実行し、そのリソースを削除して終了することができます。

中間ステップの 1 つが失敗した場合、テスト終了時にリソースが削除され、誤検出が発生しないようにするため、すべての中間ステップでこの設定を有効にしたいと思います。

このテストでは、エンドポイントが期待通りに応答しない場合、アラートが生成されます。テストが失敗した場合、Y ミリ秒後に X 回再試行することができます。再試行の間隔は、警告の感性に合うようにカスタマイズしてください。

応答から変数を抽出する

Optionally, extract variables from the response of your API request by parsing its response headers or body. The value of the variable updates each time the API request step runs.

変数のパースを開始するには、Extract a variable from response content をクリックします。

  1. Variable Name を入力します。変数名に使用できるのは大文字、数字、アンダースコアのみです。また、3 文字以上にする必要があります。

  2. 変数をレスポンスのヘッダーから抽出するか、本文から抽出するか決定します。

    • Extract the value from response header: use the full response header of your API request as the variable value, or parse it with a regex.
    • Extract the value from response body: use the full response body of your API request as the variable value or parse it with a regex, a JSONPath, or a XPath.
Extract variables from API requests in Multistep API test

1 つのテストステップにつき最大 10 個の変数を抽出することができます。一度作成すると、この変数はマルチステップ API テストの次のステップで使用することができます。詳しくは、変数の使用を参照してください。

テストの頻度を指定する

Multistep API テストは次の頻度で実行できます。

  • On a schedule: 最も重要なエンドポイントにユーザーが常にアクセスできるようにします。Datadog でマルチステップ API テストを実行する頻度を選択します。
  • Within your CI/CD pipelines: 欠陥のあるコードがカスタマーエクスペリエンスに影響を与える可能性があることを恐れずに出荷を開始します。
  • On-demand: チームにとって最も意味のあるときにいつでもテストを実行します。

Define alert conditions

Set alert conditions to determine the circumstances under which you want a test to fail and trigger an alert.

Alerting rule

When you set the alert conditions to: An alert is triggered if any assertion fails for X minutes from any n of N locations, an alert is triggered only if these two conditions are true:

  • At least one location was in failure (at least one assertion failed) during the last X minutes;
  • At one moment during the last X minutes, at least n locations were in failure.

Fast retry

Your test can trigger retries X times after Y ms in case of a failed test result. Customize the retry interval to suit your alerting sensibility.

Location uptime is computed on a per-evaluation basis (whether the last test result before evaluation was up or down). The total uptime is computed based on the configured alert conditions. Notifications sent are based on the total uptime.

Configure the test monitor

A notification is sent by your test based on the alerting conditions previously defined. Use this section to define how and what to message your team.

  1. Similar to how you configure monitors, select users and/or services that should receive notifications either by adding an @notification to the message or by searching for team members and connected integrations with the dropdown menu.

  2. Enter the notification message for your test. This field allows standard Markdown formatting and supports the following conditional variables:

    Conditional VariableDescription
    {{ #is_alert }}Show when the test alerts.
    {{ ^is_alert }}Show unless the test alerts.
    {{ #is_recovery }}Show when the test recovers from alert.
    {{ ^is_recovery }}Show unless the test recovers from alert.
    {{ #is_renotify }}Show when the monitor renotifies.
    {{ ^is_renotify }}Show unless the monitor renotifies.
    {{ #is_priority }}Show when the monitor matches priority (P1 to P5).
    {{ ^is_priority }}Show unless the monitor matches priority (P1 to P5).
  3. Specify how often you want your test to re-send the notification message in case of test failure. To prevent renotification on failing tests, leave the option as Never renotify if the monitor has not been resolved.

  4. Click Create to save your test configuration and monitor.

For more information, see Using Synthetic Test Monitors.

Variables

Create local variables

To create a local variable, click Create a Local Variable. You can select one of the following available builtins to add to your variable string:

{{ numeric(n) }}
Generates a numeric string with n digits.
{{ alphabetic(n) }}
Generates an alphabetic string with n letters.
{{ alphanumeric(n) }}
Generates an alphanumeric string with n characters.
{{ date(n unit, format) }}
Generates a date in one of Datadog’s accepted formats with a value corresponding to the UTC date the test is initiated at + or - n units.
{{ timestamp(n, unit) }}
Generates a timestamp in one of Datadog’s accepted units with a value corresponding to the UTC timestamp the test is initiated at +/- n units.
{{ uuid }}
Generates a version 4 universally unique identifier (UUID).
{{ public-id }}
Injects the Public ID of your test.
{{ result-id }}
Injects the Result ID of your test run.

To obfuscate local variable values in test results, select Hide and obfuscate variable value. Once you have defined the variable string, click Add Variable.

変数の抽出

ローカル変数の作成に加えて、マルチステップ API テストの任意のステップから変数を抽出し、後続のステップで値を再挿入することが可能です。

Use variables

You can use the global variables defined in the Settings and the locally defined variables in the URL, advanced options, and assertions of your API tests.

変数のリストを表示するには、目的のフィールドに {{ と入力します。

テストの失敗

ステップが 1 つまたは複数のアサーションを満たさない場合、またはステップのリクエストが時期尚早に失敗した場合、テストは FAILED と見なされます。場合によっては、エンドポイントに対してアサーションをテストできずにテストが実際に失敗することがあります。これらの理由には次のものがあります。

CONNREFUSED
ターゲットマシーンが積極的に拒否したため、接続できませんでした。
CONNRESET
接続がリモートサーバーによって突然閉じられました。Web サーバーにエラーが発生した、応答中にシステムが停止した、Web サーバーへの接続が失われた、などの原因が考えられます。
DNS
テスト URL に対応する DNS エントリが見つかりませんでした。テスト URL の構成の誤りまたは DNS エントリの構成の誤りの原因が考えられます。
INVALID_REQUEST
テストのコンフィギュレーションが無効です (URL に入力ミスがあるなど)。
SSL
SSL 接続を実行できませんでした。詳細については、個別のエラーページを参照してください
TIMEOUT
リクエストを一定時間内に完了できなかったことを示します。TIMEOUT には 2 種類あります。
  • TIMEOUT: The request couldn't be completed in a reasonable time. は、リクエストの持続時間がテスト定義のタイムアウト (デフォルトは 60 秒に設定されています) に当たったことを示します。 各リクエストについて、ネットワークウォーターフォールに表示されるのは、リクエストの完了したステージのみです。例えば、Total response time だけが表示されている場合、DNS の解決中にタイムアウトが発生したことになります。
  • TIMEOUT: Overall test execution couldn't be completed in a reasonable time. indicates that the request and assertions duration hit the maximum duration (30 minutes).

For HTTP steps, see common HTTP step failures. For gRPC steps, see common gRPC step failures.

権限

デフォルトでは、Datadog 管理者および Datadog 標準ロールを持つユーザーのみが、Synthetic Multistep API テストを作成、編集、削除できます。Synthetic Multistep API テストの作成、編集、削除アクセスを取得するには、ユーザーをこれら 2 つのデフォルトのロールのいずれかにアップグレードします。

カスタムロール機能を使用している場合は、Synthetic Monitoring の synthetics_read および synthetics_write 権限を含むカスタムロールにユーザーを追加します。

アクセス制限

アカウントにカスタムロールを使用しているお客様は、アクセス制限が利用可能です。

組織内の役割に基づいて、Multistep API テストへのアクセスを制限することができます。Multistep API テストを作成する際に、(ユーザーのほかに) どのロールがテストの読み取りと書き込みを行えるかを選択します。

テストの権限の設定

その他の参考資料

PREVIEWING: evan.li/clarify-agentless