概要

HTTP テストでは、アプリケーションの API エンドポイントに HTTP リクエストを送信し、応答時間、ステータスコード、ヘッダー、本文のコンテンツなど、定義された条件と応答を確認することができます。

HTTP テストは、ネットワークの外部または内部からのテストの実行の好みに応じて、管理ロケーションプライベートロケーションの両方から実行することができます。HTTP テストは、スケジュール、オンデマンド、または CI/CD パイプライン内で直接実行することができます。

構成

HTTP テストの作成を選択した後、テストのリクエストを定義します。

リクエストを定義する

  1. HTTP Method を選択し、クエリする URL を指定します。使用可能なメソッドは、GETPOSTPATCHPUTHEADDELETEOPTIONS です。httphttps の両方の URL がサポートされています。

    See Advanced options for more options.
  2. HTTP テストに名前を付けます。

  3. HTTP テストに env タグとその他のタグを追加します。次に、これらのタグを使用して、Synthetic Monitoring & Continuous Testing ページで Synthetic テストをフィルタリングできます。

    HTTP リクエストを定義する

Test URL をクリックして、リクエストのコンフィギュレーションをテストします。画面の右側に応答プレビューが表示されます。

高度なオプション

  • HTTP version: Select HTTP/1.1 only, HTTP/2 only, or HTTP/2 fallback to HTTP/1.1.
  • Follow redirects: 選択すると、リクエストを実行するときに HTTP テストで最大 10 個のリダイレクトをフォローします。
  • Ignore server certificate error: 選択すると、SSL 証明書の検証時にエラーが発生した場合でも、HTTP テストが接続を続行します。
  • Timeout: テストがタイムアウトするまでの時間を秒単位で指定します。
  • Request headers: HTTP リクエストに追加するヘッダーを定義します。デフォルトのヘッダー (たとえば、user-agent ヘッダー) をオーバーライドすることもできます。
  • Cookies: HTTP リクエストに追加するクッキーを定義します。<COOKIE_NAME1>=<COOKIE_VALUE1>; <COOKIE_NAME2>=<COOKIE_VALUE2> の形式を使用して複数のクッキーを設定します。
  • クライアント証明書: クライアント証明書 (.crt) と関連する秘密キー (.key) を PEM 形式でアップロードして、mTLS を介して認証します。openssl ライブラリを使用して証明書を変換することができます。たとえば、PKCS12 証明書を PEM 形式の秘密キーと証明書に変換します。

    openssl pkcs12 -in <CERT>.p12 -out <CERT_KEY>.key -nodes -nocerts
    openssl pkcs12 -in <CERT>.p12 -out <CERT>.cert -nokeys
    
  • HTTP Basic Auth: HTTP 基本認証資格情報を追加します。

  • Digest Auth: ダイジェスト認証の資格情報を追加します。

  • NTLM: NTLM 認証の資格情報を追加します。NTLMv2 と NTLMv1 の両方をサポートします。

  • AWS Signature v4: Enter your Access Key ID and Secret Access Key. Datadog generates the signature for your request. This option uses the basic implementation of SigV4. Specific signatures such as Amazon S3 are not supported out-of-the box.
    For “Single Chunk” transfer requests to Amazon S3 buckets, add x-amz-content-sha256 containing the sha256-encoded body of the request as a header (for an empty body: x-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855).

  • OAuth 2.0: クライアント資格情報またはリソース所有者のパスワードのどちらかを付与するかを選択し、アクセストークンの URL を入力します。選択内容に応じて、クライアント ID とシークレット、またはユーザー名とパスワードを入力します。ドロップダウンメニューから、API トークンを基本認証ヘッダーとして送信するか、クライアント資格情報を本文に送信するかを選択します。オプションで、オーディエンス、リソース、スコープなどの追加情報を提供できます (Resource Owner Password を選択した場合は、クライアント ID とシークレットも提供します)。

  • Encode parameters: エンコーディングが必要なクエリパラメーターの名前と値を追加します。
  • Body type: HTTP リクエストに追加するリクエスト本文のタイプ (application/jsonapplication/octet-streamapplication/x-www-form-urlencodedmultipart/form-datatext/htmltext/plaintext/xmlGraphQL、または None) を選択します。
  • Request body: HTTP リクエスト本文の内容を追加します。
    • application/jsonapplication/x-www-form-urlencodedtext/htmltext/plaintext/xmlGraphQL では、リクエスト本文のサイズは最大 50 キロバイトに制限されます。
    • application/octet-stream では、リクエスト本文は 3 メガバイトのファイル 1 つに制限されます。
    • multipart/form-data では、リクエスト本文はそれぞれ 3 メガバイトのファイル 3 つに制限されます。
  • Proxy URL: HTTP リクエストが通過する必要があるプロキシの URL (http://<YOUR_USER>:<YOUR_PWD>@<YOUR_IP>:<YOUR_PORT>) を指定します。
  • Proxy header: プロキシへの HTTP リクエストに含めるヘッダーを追加します。
  • Do not save response body: 応答の本文が実行時に保存されないようにするには、このオプションを選択します。テスト結果に機密データを含めたくない場合に有用です。障害発生時のトラブルシューティングに影響を及ぼす可能性があるため、慎重に使用してください。セキュリティに関する推奨の詳細は、Synthetic Monitoring Security をご確認ください。

Define variables for your HTTP API tests with JavaScript:

<div class="shortcode-wrapper shortcode-img expand"><figure class="text-center"><a href="https://datadog-docs-staging.imgix.net/images/synthetics/api_tests/http_javascript.66fe410698cb2c156ee0634db040393e.png?fit=max&amp;auto=format" class="pop" data-bs-toggle="modal" data-bs-target="#popupImageModal"><picture class=""  style="width:90%;"  >
        <img 
            class="img-fluid" 
            srcset="https://datadog-docs-staging.imgix.net/images/synthetics/api_tests/http_javascript.66fe410698cb2c156ee0634db040393e.png?auto=format" 
            style="width:90%;"  alt="Define HTTP API test with Javascript"  />
      </picture></a></figure>
</div>

アサーションを定義する

アサーションは、期待されるテスト結果が何であるかを定義します。Test URL をクリックすると、response timestatus codeheadercontent-type の基本的なアサーションが、取得された応答に基づいて追加されます。テストで監視するには、少なくとも 1 つのアサーションを定義する必要があります。

タイプ演算子値の型
本文containsdoes not containisis not
matchesdoes not match
jsonpathxpath
文字列
正規表現
ヘッダーcontainsdoes not containisis not
matchesdoes not match
文字列
正規表現
response timeis less than整数 (ms)
ステータスコードisis not
matchesdoes not match
整数
正規表現

HTTP テストでは、brdeflategzipidentitycontent-encoding ヘッダーを使用して本文を解凍することが可能です。

New Assertion をクリックするか、応答プレビューを直接クリックすることで、API テストごとに最大 20 個のアサーションを作成できます。

HTTP テストが成功または失敗するためのアサーションを定義する

アサーションで OR ロジックを実行するには、matches regex コンパレータを使って (200|302) のように複数の期待値を持つ正規表現を定義します。たとえば、サーバーが 200 あるいは 302 というステータスコードで応答したときに HTTP テストを成功させたいことがあるでしょう。ステータスコードが 200 あるいは 302 であれば、 status code アサーションは成功します。bodyheader アサーションに OR ロジックを追加することもできます。

テストがレスポンス本文にアサーションを含まない場合、本文のペイロードはドロップし、Synthetics Worker で設定されたタイムアウト制限内でリクエストに関連するレスポンスタイムを返します。

テストがレスポンス本文に対するアサーションを含み、タイムアウトの制限に達した場合、Assertions on the body/response cannot be run beyond this limit というエラーが表示されます。

ロケーションを選択する

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

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

テストの頻度を指定する

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

  • On a schedule: 最も重要なエンドポイントにユーザーが常にアクセスできるようにします。Datadog で HTTP テストを実行する頻度を選択します。
  • 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.

変数を使用する

HTTP テストの URL、高度なオプション、アサーションで、Settings ページで定義されたグローバル変数を使用することができます。

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

テストの失敗

テストが 1 つ以上のアサーションを満たさない場合、またはリクエストが途中で失敗した場合、テストは FAILED と見なされます。場合によっては、エンドポイントに対するアサーションをテストせずにテストが実際に失敗することがあります。

よくあるエラーは以下の通りです。

CONNREFUSED
ターゲットマシーンが積極的に拒否したため、接続できませんでした。
CONNRESET
接続がリモートサーバーによって突然閉じられました。Web サーバーにエラーが発生した、応答中にシステムが停止した、Web サーバーへの接続が失われた、などの原因が考えられます。
DNS
テスト URL に対応する DNS エントリが見つかりませんでした。原因としては、テスト URL の誤構成や DNS エントリの誤構成が考えられます。
Error performing HTTP/2 request
リクエストを実行できませんでした。詳細は専用のエラーページを参照してください。
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. は、テスト時間 (リクエスト+アサーション) が最大時間 (60.5s) に達したことを示しています。
MALFORMED_RESPONSE
リモートサーバーが HTTP 仕様に準拠していないペイロードで応答しました。

権限

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

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

アクセス制限

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

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

テストの権限の設定

その他の参考資料

PREVIEWING: alai97/reorganize-some-sections-in-dora-metrics