Skip to content

Commit

Permalink
Merge branch '2347-debug-dialtesting' into 'dev'
Browse files Browse the repository at this point in the history
Resolve "拨测 debug 接口补充额外信息"

See merge request cloudcare-tools/datakit!3161
  • Loading branch information
谭彪 committed Aug 21, 2024
2 parents f0001a3 + 8ba3fc6 commit 3f08338
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion internal/export/doc/en/inputs/dialtesting_json.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ The public fields of dialing test tasks are defined as follows:
| `success_when` | object | Y | See below for details |
| `advance_options` | object | N | See below for details |
| `post_url` | string | N | Send the dialing test result to the workspace pointed by the Token, and if it is not filled in, send it to the workspace where the current DataKit is located |
| `tags_info` | string | N | Custom tags, such as `[{"name": "tag1"}, {"name": "tag2"}]` |
| `tags_info` | string | N | Custom tags, such as `t1,t2` |
| `workspace_language` | string | N | Workspace language, such as `zh``en` |

#### HTTP Dial Test {#http}
Expand Down
2 changes: 1 addition & 1 deletion internal/export/doc/zh/inputs/dialtesting_json.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ monitor :
| `success_when` | object | Y | 详见下文 |
| `advance_options` | object | N | 详见下文 |
| `post_url` | string | N | 将拨测结果发往该 Token 所指向的工作空间,如果不填写,则发给当前 DataKit 所在工作空间 |
| `tags_info` | string | N | 拨测任务自定义标签,如: `[{"name": "tag1"}, {"name": "tag2"}]` |
| `tags_info` | string | N | 拨测任务自定义标签,如: `t1,t2` |
| `workspace_language` | string | N | 当前工作空间语言,如:`zh``en` |

#### HTTP 拨测 {#http}
Expand Down
9 changes: 6 additions & 3 deletions internal/httpapi/api_dialtesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ func apiDebugDialtestingHandler(w http.ResponseWriter, req *http.Request, whatev
return nil, uhttp.Error(ErrInvalidRequest, err.Error())
}
if err := defDialtestingMock.debugRun(t); err != nil {
l.Errorf("[%s] %s", tid, err.Error())
return nil, uhttp.Error(ErrInvalidRequest, err.Error())
l.Warnf("[%s] %s", tid, err.Error())
}

_, fields := defDialtestingMock.getResults(t)
tags, fields := defDialtestingMock.getResults(t)

failReason, ok := fields["fail_reason"].(string)
if ok {
Expand All @@ -128,6 +127,10 @@ func apiDebugDialtestingHandler(w http.ResponseWriter, req *http.Request, whatev
traceroute, _ = fields["traceroute"].(string)
}

for k, v := range tags {
fields[k] = v
}

return &dialtestingDebugResponse{
Cost: time.Since(start).String(),
ErrorMessage: failReason,
Expand Down
9 changes: 0 additions & 9 deletions internal/httpapi/api_dialtesting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ func TestApiDebugDialtestingHandler(t *testing.T) {
errInit: uhttp.Error(ErrInvalidRequest, "ddd"),
errExpect: uhttp.Error(ErrInvalidRequest, "invalid request"),
},
{
name: "test dial invalid request2",
t: &dialtestingDebugRequest{
TaskType: "HTTP",
Task: &dt.HTTPTask{},
},
errRun: uhttp.Error(ErrInvalidRequest, "ddd"),
errExpect: uhttp.Error(ErrInvalidRequest, "invalid request"),
},
{
name: "test dial status stop",
t: &dialtestingDebugRequest{
Expand Down

0 comments on commit 3f08338

Please sign in to comment.