概要

WebSocket テストでは、エンドポイントで WebSocket 接続を積極的に開き、応答と、全体的な応答時間や期待されるヘッダーなどの定義された条件を確認することができます。

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

構成

You may create a test using one of the following options:

  • Create a test from a template:

    1. Hover over one of the pre-populated templates and click View Template. This opens a side panel displaying pre-populated configuration information, including: Test Details, Request Details, Assertions, Alert Conditions, and Monitor Settings.
    2. Click +Create Test to open the Define Request page, where you can review and edit the pre-populated configuration options. The fields presented are identical to those available when creating a test from scratch.
    3. Click Save Details to submit your API test.

  • Build a test from scratch:

    1. テストを一から作成するには、+ Start from scratch テンプレートをクリックし、WebSocket リクエストタイプを選択します。
    2. テストを実行する URL を指定します。
    3. テストで送信したい文字列を入力します。
    4. Advanced Options (オプション) をテストに追加します。

    • Timeout: テストがタイムアウトするまでの時間を秒単位で指定します。
    • Request headers: WebSocket 接続を開始する HTTP リクエストに追加するヘッダーを定義します。デフォルトのヘッダー (たとえば、user-agent ヘッダー) をオーバーライドすることもできます。
    • Cookies: クッキーを定義して WebSocket 接続を開始する HTTP リクエストに追加します。複数のクッキーを設定するには、次の書式を使用します <COOKIE_NAME1>=<COOKIE_VALUE1>; <COOKIE_NAME2>=<COOKIE_VALUE2>
    • HTTP Basic Auth: HTTP 基本認証資格情報を追加します。

  1. WebSocket テストに名前を付けます。

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

  3. Send をクリックして、リクエストの構成をテストします。画面の右側に応答プレビューが表示されます。

    WebSocket リクエストを定義する
  4. Click Create Test to submit your API test.

スニペット

When setting up a new Synthetic Monitoring API test, use snippets to automatically fill in basic auth, performance, and regions, rather than selecting these options manually. The following snippets are available:

  • Basic Auth: Automatically test your APIs using pre-populated basic auth headers, JavaScript, bearer token, and API/app key auth variables.

  • Performance: Automatically configure a test with the shortest frequency (one minute), perform a gRPC health check, and test for overall response time latency with a breakdown of network timing.

  • Regions: Automatically test your API endpoint against a location in each of the three primary geographic regions (AMER, APAC and EMEA).

    Screenshot of the left hand side of an API test creation, showing the snippets example

アサーションを定義する

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

タイプ演算子値の型
response timeis less than整数 (ms)
文字列応答containsdoes not containisis not
matchesdoes not match
文字列
正規表現
ヘッダーcontainsdoes not containisis not
matchesdoes not match
文字列
正規表現

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

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

アサーションで OR ロジックを実行するには、matches regex あるいは does not match regex コンパレータを使用して、(0|100) のように同じアサーションタイプに対して複数の期待値を設定した正規表現を定義します。文字列レスポンスまたはヘッダーアサーションの値が 0 あるいは 100 の場合、テストは成功です。

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

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

ロケーションを選択する

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

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

AWS:

AmericasAsia PacificEMEA
Canada CentralHong KongBahrain
Northern CaliforniaJakartaCape Town
Northern VirginiaMumbaiFrankfurt
OhioOsakaIreland
OregonSeoulLondon
São PauloSingaporeMilan
SydneyParis
TokyoStockholm

GCP:

AmericasAsia PacificEMEA
DallasTokyoFrankfurt
Los Angeles
Oregon
Virginia

Azure:

RegionLocation
AmericasVirginia

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

RegionLocation
AmericasUS-West

テストの頻度を指定する

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

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

Notification messages include the message defined in this section and information about the failing locations. Pre-filled monitor messages are included in the message body section:

Synthetic Monitoring monitor section for API tests, highlighting the pre-filled monitor messages
  1. Specify how often you want your test to re-send the notification message in case of test failure. To prevent renotification on failing tests, check the option Stop re-notifying on X occurrences.

  2. Click Save & Start Recording to save your test configuration and monitor.

For more information, see Synthetic Monitoring notifications.

Create local variables

To create a local variable, click + All steps > Variables. 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.

変数を使用する

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

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

テストの失敗

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

これらの理由には以下が含まれます。

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. は、テスト時間 (リクエスト+アサーション) が最大時間 (60.5s) に達したことを示しています。
WEBSOCKET
WebSocket 接続が閉じられたか、開くことができません。WEBSOCKET エラーには次のようなものがあります。
  • WEBSOCKET: Received message longer than the maximum supported length. は応答メッセージの長さが最大長 (50kb) に達したことを示します。

権限

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

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

アクセス制限

Use granular access control to limit who has access to your test based on roles, teams, or individual users:

  1. Open the permissions section of the form.
  2. Click Edit Access.
Set permissions for your test from Private Locations configuration form
  1. Click Restrict Access.
  2. Select teams, roles, or users.
  3. Click Add.
  4. Select the level of access you want to associate with each of them.
  5. Click Done.
You can view results from a Private Location even without Viewer access to that Private Location.
Access levelView test configurationEdit test configurationView test resultsRun test
No access
ViewerYesYes
EditorYesYesYesYes

その他の参考資料