# タスク実行に関するレポート作成にコンポーネントのオブザーバビリティメトリクスを使用

/monitoring/observability/metrics/componentでPOSTを使い、タスク実行に関するレポートをビルドします。

## 手順

1. 分析が必要なタスクのIDを取得します。

   タスクIDは、Talend Management Consoleの[Task details] (タスクの詳細)にあります。API経由でこのIDを取得しなければならない場合は、[アーティファクトのバージョンをアップデートする必要があるタスクを取得](https://help.qlik.com/talend/r/ja-JP/Cloud/use-api-to-update-artifact-in-tasks/get-tasks-to-be-updated)をご覧ください。
2. 次のAPIリクエストを発行し、このタスクの一定期間の実行履歴を検索します。
   ```
   method: GET
   endpoint: 
         https://api.<env>.cloud.talend.com/processing/executables/tasks/{taskId}/executions?from={start_timestamp_ms}&to={end_timestamp_ms}
   headers: {
    "Authorization": "Bearer <personanl_access_token>"
   }
   payload: N/A
   ```

   レスポンスで実行回数を数え、失敗した実行があればそれを見つけ出します。
3. 次のAPIリクエストを発行し、各タスク実行における特定タイプのコンポーネントの実行時間を確認します。
   ```
   method: POST
   endpoint: 
         https://api.<env>.cloud.talend.com/monitoring/observability/metrics/component
   headers: {
    "Authorization": "Bearer <personanl_access_token>"
   }
   payload: {
       "startTime": "job start time", 
       "endTime": "job end time", 
       "environmentId": "environment id value",
       "sortBy": "component_execution_duration_milliseconds",
       "sortOrder": "desc";
       "filters": [
           {
               "field": "task_id ",
               "operator": "in", 
               "value": ["ID_of_the_task_to_analyze"]
           },
           {
               "field": "connector_type ",
               "operator": "in", 
               "value": ["a_component_type_such_as_tMongoDBConnection"]
           }
       ]
   }
   ```
4. レスポンスを分析し、このタイプのコンポーネントがタスク実行に応じてどのように実行時間が変化するかを識別します。

## タスクの結果

このレポートを通して、タスクの実行中に変化するコンポーネントの動作の状況を把握できます。

以下は、/monitoring/observability/metrics/componentでのPOSTリクエストのレスポンスの例です。

```
{
  "items": [
    {
      "account_id": "2be59707-2230-45dc-a43d-db7e6d798425",
      "engine_id": "a60bb1c0-7669-407f-9326-138af05da18a",
      "engine_type": "CLOUD",
      "engine_version": "2.10.7",
      "workspace_id": "6093f6a36f01d639680d31cd",
      "task_id": "610d3b7da8abfa32ffb6506b",
      "task_execution_id": "2b252f47-ccfd-4c13-9c4a-d864b599086f",
      "operator": "xxx",
      "operator_type": "HUMAN",
      "process_id": "0329f8d4-1c69-3372-9233-d38ac6ef03a8",
      "job_name": "MainJob",
      "pid": "20210806181617_2Y68h",
      "father_pid": "20210806181617_2Y68h",
      "root_pid": "20210806181617_2Y68h",
      "connector_type": "tMongoDBConnection",
      "connector_label": "tMongoDBConnection_1",
      "connector_id": "tMongoDBConnection_1",
      "component_start_time_seconds": 1628266578
    },
    {
      "account_id": "2be59707-2230-45dc-a43d-db7e6d798425",
      "engine_id": "a60bb1c0-7669-407f-9326-138af05da18a",
      "engine_type": "CLOUD",
      "engine_version": "2.10.7",
      "workspace_id": "6093f6a36f01d639680d31cd",
      "task_id": "610d3b7da8abfa32ffb6506b",
      "task_execution_id": "2b252f47-ccfd-4c13-9c4a-d864b599086f",
      "operator": "xxx",
      "operator_type": "HUMAN",
      "process_id": "0329f8d4-1c69-3372-9233-d38ac6ef03a8",
      "job_name": "MainJob",
      "pid": "20210806181617_2Y68h",
      "father_pid": "20210806181617_2Y68h",
      "root_pid": "20210806181617_2Y68h",
      "connector_type": "tRowGenerator",
      "connector_label": "tRowGenerator_1",
      "connector_id": "tRowGenerator_1",
      "target_connector_type": "tFlowMeter",
      "target_label": "tFlowMeter_row1",
      "target_id": "tFlowMeter_row1",
      "connection_type": "row1",
      "connection_name": "output",
      "component_start_time_seconds": 1628266578,
      "component_connection_rows_total": 5000000,
      "component_execution_duration_milliseconds": 491585
    },
    ...
  ],
  "limit": 50,
  "offset": 0,
  "total": 7
}
```