This product is not supported for your selected
Datadog site. (
).
概要
開始する前に、お使いの言語で Test Optimization がすでに設定されていることを確認してください。このガイドでは、テストにカスタムメジャーを追加して使用する方法について説明します。
カスタムメジャーをテストに追加する
カスタムメジャーをテストに追加します。ネイティブインスツルメンテーションでは、プログラマティック API を使用できます。
it('sum function can sum', () => {
const testSpan = require('dd-trace').scope().active()
testSpan.setTag('test.memory.rss', process.memoryUsage().rss)
// test continues normally
// ...
})
カスタムメトリクスを追加するには、opentracing-util ライブラリをコンパイル時の依存関係としてプロジェクトに追加します。
import io.opentracing.Span;
import io.opentracing.util.GlobalTracer;
// ...
// inside your test
final Span span = GlobalTracer.get().activeSpan();
if (span != null) {
span.setTag("test.memory.usage", 1e8);
}
// test continues normally
// ...
from ddtrace import tracer
import os, psutil
# Declare `ddspan` as argument to your test
def test_simple_case(ddspan):
# Set your tags
process = psutil.Process()
ddspan.set_tag("test.memory.rss", process.memory_info().rss)
# test continues normally
# ...
// inside your test
var scope = Tracer.Instance.ActiveScope; // from Datadog.Trace;
if (scope != null) {
scope.Span.SetTag("test.memory.usage", 1e8);
}
// test continues normally
// ...
require 'datadog/ci'
# inside your test
Datadog::CI.active_test&.set_tag('test.memory.usage', 1e8)
# test continues normally
# ...
import DatadogSDKTesting
// inside your test
DDTest.current?.setTag(key: "test.memory.usage", value: 1e8)
// test continues normally
// ...
datadog-ci の場合、DD_MEASURES 環境変数または --measures CLI 引数を使用します。
DD_MEASURES="test.memory.usage:1000" datadog-ci junit upload --service my-service --measures test.request.rate:30 report.xml
ファセットを作成する
テストに追加したカスタムメジャーのファセットを作成するには、Test Runs ページに移動し、ファセットリストの + Add をクリックします。
ファセットのタイプが数値を表す Measure であることを確認します。
カスタムメジャーの使用を開始するには、Add をクリックします。
メジャーの推移をグラフ化する
Timeseries の視覚化を選択することで、時系列でのメジャーの推移をプロットできます。
たとえば、この視覚化を使用して、テストのメモリ使用量の推移を追跡することができます。
グラフをエクスポートする
グラフをダッシュボードやノートブックにエクスポートし、Export ボタンをクリックすると、それに基づいてモニターを作成することができます。
モニターを追加する
CI テストモニターを作成して、メジャーの値が特定のしきい値を上回ったり下回ったりした場合にアラートを受けます。
たとえば、このタイプのアラートは、メモリ使用量が特定のしきい値に達したことを知らせるために使用できます。
参考資料