Merge pull request #15261 from influxdata/fix/http-checks

fix(http): prevent writing to http request multiple times
pull/15267/head
Michael Desa 2019-09-24 16:10:09 -04:00 committed by GitHub
commit 16ffb9013d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -170,6 +170,12 @@ type checksResponse struct {
}
func (h *CheckHandler) newCheckResponse(ctx context.Context, chk influxdb.Check, labels []*influxdb.Label) (*checkResponse, error) {
// TODO(desa): this should be handled in the check and not exposed in http land, but is currently blocking the FE. https://github.com/influxdata/influxdb/issues/15259
task, err := h.TaskService.FindTaskByID(ctx, chk.GetTaskID())
if err != nil {
return nil, err
}
// Ensure that we don't expose that this creates a task behind the scene
chk.ClearPrivateData()
@ -188,11 +194,6 @@ func (h *CheckHandler) newCheckResponse(ctx context.Context, chk influxdb.Check,
res.Labels = append(res.Labels, *l)
}
task, err := h.TaskService.FindTaskByID(ctx, chk.GetTaskID())
if err != nil {
return nil, err
}
res.Status = task.Status
return res, nil
@ -509,6 +510,7 @@ func (h *CheckHandler) handlePostCheck(w http.ResponseWriter, r *http.Request) {
cr, err := h.newCheckResponse(ctx, chk, []*influxdb.Label{})
if err != nil {
h.HandleHTTPError(ctx, err, w)
return
}
if err := encodeResponse(ctx, w, http.StatusCreated, cr); err != nil {