Skip to content

Commit

Permalink
feat: support ABORTED status in ::status:: directive of exec probe
Browse files Browse the repository at this point in the history
  • Loading branch information
macrat committed May 1, 2021
1 parent 0288c80 commit d420081
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ hello world
This output is reporting latency is `123.456ms`, status is `FAILURE`, and message is `hello world`.

- `::latency::`: Reports the latency of service in milliseconds.
- `::status::`: Reports the status of service in `healthy`, `failure`, or `unknown`.
- `::status::`: Reports the status of service in `healthy`, `failure`, `aborted`, or `unknown`.

Ayd uses the last value if found multiple reports in single output.

Expand Down
11 changes: 2 additions & 9 deletions probe/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,10 @@ func getLatencyByMessage(message string, default_ time.Duration) (replacedMessag
}

func getStatusByMessage(message string, default_ store.Status) (replacedMessage string, status store.Status) {
statusRe := regexp.MustCompile("(?m)^::status::((?i:healthy|failure|unknown))(?:\n|$)")
statusRe := regexp.MustCompile("(?m)^::status::((?i:healthy|failure|aborted|unknown))(?:\n|$)")

if m := statusRe.FindAllStringSubmatch(message, -1); m != nil {
switch strings.ToLower(m[len(m)-1][1]) {
case "healthy":
status = store.STATUS_HEALTHY
case "failure":
status = store.STATUS_FAILURE
case "unknown":
status = store.STATUS_UNKNOWN
}
status = store.ParseStatus(strings.ToUpper(m[len(m)-1][1]))
return strings.Trim(statusRe.ReplaceAllString(message, ""), "\n"), status
}

Expand Down
1 change: 1 addition & 0 deletions probe/exec_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestGetStatusByMessage(t *testing.T) {
}{
{"::status::healthy", store.STATUS_UNKNOWN, "", store.STATUS_HEALTHY},
{"::status::Failure", store.STATUS_UNKNOWN, "", store.STATUS_FAILURE},
{"::status::aborted", store.STATUS_UNKNOWN, "", store.STATUS_ABORTED},
{"::status::UNKNOWN", store.STATUS_HEALTHY, "", store.STATUS_UNKNOWN},
{"::status::abcdefg", store.STATUS_UNKNOWN, "::status::abcdefg", store.STATUS_UNKNOWN},
{"hello\n::status::FAILURE\nworld", store.STATUS_UNKNOWN, "hello\nworld", store.STATUS_FAILURE},
Expand Down

0 comments on commit d420081

Please sign in to comment.