Skip to content

Commit

Permalink
[plugin] Outputs backend response time in anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyanliu authored and Jack47 committed Dec 21, 2017
1 parent ca3adfe commit 0c021c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/model/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,16 @@ func (p *Plugin) dismissInstance(instance *wrappedPlugin) (bool, uint64) {
for {
count, err := p.counter.RefCount(inst)
if err != nil {
logger.Errorf("[BUG: query reference count of plugin %s instance failed: %v]", inst.Name(), err)
logger.Errorf("[BUG: query reference count of plugin %s instance failed: %v]",
inst.Name(), err)
break
}

if count == 0 {
break
}

logger.Debugf("[spin to wait wait old plugin instance closes]")
logger.Debugf("[spin to wait old plugin instance closes]")
time.Sleep(time.Millisecond)
}

Expand Down
31 changes: 18 additions & 13 deletions src/plugins/http_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,23 @@ func (h *httpOutput) send(ctx pipelines.PipelineContext, t task.Task, req *http.

return resp, responseDuration, nil
case err := <-e:
responseDuration := common.Since(requestStartAt)

msg := err.Error()
if m, err := url.QueryUnescape(msg); err == nil {
msg = m
}

t.SetError(fmt.Errorf("%s", msg), task.ResultServiceUnavailable)
return nil, 0, err
return nil, responseDuration, err
case <-t.Cancel():
cancel()

responseDuration := common.Since(requestStartAt)

err := fmt.Errorf("task is cancelled by %s", t.CancelCause())
t.SetError(err, task.ResultTaskCancelled)
return nil, 0, err
return nil, responseDuration, err
}
}

Expand Down Expand Up @@ -400,14 +406,17 @@ func (h *httpOutput) Run(ctx pipelines.PipelineContext, t task.Task) error {
req.Host = req.Header.Get("Host") // https://github.com/golang/go/issues/7682

resp, responseDuration, err := h.send(ctx, t, req)
if err != nil {
if t.ResultCode() == task.ResultTaskCancelled &&
len(h.conf.RequestBodyIOKey) == 0 { // has no rewind for rerun plugin
if err != nil && t.ResultCode() == task.ResultTaskCancelled &&
len(h.conf.RequestBodyIOKey) == 0 { // has no rewind for rerun plugin
return t.Error()
}

return t.Error()
} else {
return nil
}
if len(h.conf.ResponseDurationKey) != 0 {
t.WithValue(h.conf.ResponseDurationKey, responseDuration)
}

if err != nil {
return nil
}

closeRespBody := func() {
Expand Down Expand Up @@ -442,10 +451,6 @@ func (h *httpOutput) Run(ctx pipelines.PipelineContext, t task.Task) error {
t.WithValue(h.conf.ResponseRemoteKey, req.URL.String())
}

if len(h.conf.ResponseDurationKey) != 0 {
t.WithValue(h.conf.ResponseDurationKey, responseDuration)
}

if len(h.conf.ExpectedResponseCodes) > 0 {
match := false
for _, expected := range h.conf.ExpectedResponseCodes {
Expand Down

0 comments on commit 0c021c1

Please sign in to comment.