# compute engine tasks

这个目录下存放目前诊断引擎支持的所有任务，每个目录为一个独立的任务。

## log-diag

日志诊断任务，过滤特定时间段的日志，输出异常信息。

*注意*：该任务会自动针对每个集群，每分钟执行一次，无需手动调用

### args

```
{
  "cluster": "1311285575352848384",
  "start_ts": 1655119080,
  "stop_ts": 1655119140
}
```

- cluster: 要诊断的集群 id
- start_ts: 日志的开始时间
- stop_ts: 日志的结束时间

### data

```
{
  "abnormal": true,
  "advice": [
    {
      "category": [
        "perf"
      ],
      "component": "tikv",
      "conditions": [
        "peer is not leader"
      ],
      "content": {
        "key": "log_diag_133"
      },
      "count": 63,
      "id": 133,
      "instance": "ip-10-250-12-182.ap-northeast-2.compute.internal-db-tikv-32",
      "level": "warning",
      "name": "TiKV peer is not leader",
      "type": "End-to-End"
    }
  ]
}
```

- abnormal: 是否诊断出异常
- advice: 针对出现的异常的建议

## realtime-diag-summary

汇总指定时间段内的 `log-diag` 和 `metrics-advisor` 任务执行结果。

### args

```
{
  "cluster": "1311285575352848384", 
  "start_ts": 1654580000, 
  "stop_ts": 1654590000
}
```

- cluster: 要诊断的集群 id
- start_ts, stop_ts: 过滤 `log-diag` 和 `metrics-advisor` 任务的创建时间范围

### data

```
{
  "abnormal": true,
  "content": [
    {
      "advice": [
        {
          "category": [
            "perf"
          ],
          "component": "tikv",
          "content": {
            "key": "log_diag_133"
          },
          "id": 133,
          "instance": "ip-10-250-12-182.ap-northeast-2.compute.internal-db-tikv-32",
          "level": "warning",
          "name": "TiKV peer is not leader",
          "qualified": false,
          "type": "End-to-End"
        }
      ],
      "timestamp": 1655975040,
      "type": "log"
    }
  ]
}
```

- abnormal: 目标集群在该时间段内是否存在异常
- content:
  - timestamp: 异常出现时间
  - type: 对应诊断的类型，有 log 和 metric
  - advice:
    - id: 对应的规则 ID（也是 issue id)
    - name: 异常信息
    - component: 出现异常的组件
    - category: 异常的影响
    - content:
      - key: 建议内容的 i18n key 
      - variables: key 中的变量替换
    - level: info | warning | error
    - qualified: 是否经过验证
    - type: End-to-End | Non-End-to-End

## metrics-advisor

Metrics 诊断任务，对指定集群的指定时间段 metrics 进行分析评评估，给出相应的诊断建议。

### args

```
{
  "cluster": "1311285575352848384",
  "start_ts": 1655119080,
  "stop_ts": 1655119140
}
```

- cluster: 要诊断的集群 id
- start_ts: metrics 的开始时间
- stop_ts: metrics 的结束时间

### data

```
{
    "abnormal": true,
    "advice": [
      {
        "level": "warning",
        "category": "",
        "component": "",
        "type": "Non-End-to-End",
        "content": {
          "key": "metrics_diag_1",
          "variables": null
        }
      },
      {
        "level": "warning",
        "category": "",
        "component": "",
        "type": "Non-End-to-End",
        "content": {
          "key": "metrics_diag_2",
          "variables": {
            "var_1": "11.1",
            "var_2": "2.3"
          }
        }
      }
    ]
}
```

- abnormal: 是否诊断出异常
- advice: 以列表形式给出 N 条建议，每条建议包含
  - level: 告警等级
  - type: 类别，含 End-to-End 和 Non-End-to-End
  - content: 建议文本

## comparison-report

两个时间段的对比计算任务，含 metrics/logs/configuration 三类对比，返回对比结果。

### args

```
{
  "cluster": "1311285575352848384",
  "start_ts_1": 1655119080,
  "stop_ts_1": 1655119140,
  "start_ts_2": 1655219080,
  "stop_ts_2": 1655219140
}
```

- cluster: 要诊断的集群 id
- start_ts_1: 第一个时间段的起始时刻
- stop_ts_1: 第一个时间段的终了时刻
- start_ts_2: 第二个时间段的起始时刻
- stop_ts_2: 第二个时间段的终了时刻

### data

```
{
  ...
}
```
