From 044667a1bf9b60480666abb709e30463683b6aa8 Mon Sep 17 00:00:00 2001 From: Himanshu Date: Thu, 6 Oct 2016 20:11:45 +0530 Subject: [PATCH] adding rawstring in fluresponse from flumonitor to put in logs --- app/services/flu_svc/flu_output/flu_monitor.go | 16 ++++++++-------- app/services/flu_svc/flu_output/flu_utils.go | 8 +++++--- app/services/flu_svc/flu_output/transport.go | 3 ++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/services/flu_svc/flu_output/flu_monitor.go b/app/services/flu_svc/flu_output/flu_monitor.go index 8045c0962a7e..5f528413e3ef 100644 --- a/app/services/flu_svc/flu_output/flu_monitor.go +++ b/app/services/flu_svc/flu_output/flu_monitor.go @@ -123,7 +123,7 @@ func sendBackResp(projectIdsToSend []uuid.UUID) { } else { completedFLUs := deleteFromFeedLinePipe(projectId, fluOutObj) - go putDbLog(completedFLUs, "Invalid FLU Resp ", *fluResp) + go putDbLog(completedFLUs, "ERROR", *fluResp) } } @@ -158,10 +158,10 @@ func getFluOutputObj(flp feedLineValue) (fluOutputObj []fluOutputStruct) { return } -func sendBackToClient(projectId uuid.UUID, fluProjectResp []fluOutputStruct) (*Response, status_codes.StatusCode) { +func sendBackToClient(projectId uuid.UUID, fluProjectResp []fluOutputStruct) (*FluResponse, status_codes.StatusCode) { if len(fluProjectResp) < 1 { - return &Response{}, status_codes.NoFluToSend + return &FluResponse{}, status_codes.NoFluToSend } plog.Info("Flu output", "sendBackToClient", projectId) @@ -170,7 +170,7 @@ func sendBackToClient(projectId uuid.UUID, fluProjectResp []fluOutputStruct) (*R fpsModel, err := fpsRepo.Get(projectId) if utilities.IsValidError(err) { plog.Error("DB Error:", err) - return &Response{}, status_codes.UnknownFailure + return &FluResponse{}, status_codes.UnknownFailure } url := fpsModel.PostBackUrl @@ -182,7 +182,7 @@ func sendBackToClient(projectId uuid.UUID, fluProjectResp []fluOutputStruct) (*R jsonBytes, err := json.Marshal(sendResp) if err != nil { plog.Error("JSON Marshalling Error:", err) - return &Response{}, status_codes.UnknownFailure + return &FluResponse{}, status_codes.UnknownFailure } jsonBytes = utilities.ReplaceEscapeCharacters(jsonBytes) plog.Trace("Sending JSON:", string(jsonBytes)) @@ -202,7 +202,7 @@ func sendBackToClient(projectId uuid.UUID, fluProjectResp []fluOutputStruct) (*R resp, err := client.Do(req) if err != nil { plog.Error("HTTP Error:", err) - return &Response{}, status_codes.UnknownFailure + return &FluResponse{}, status_codes.UnknownFailure } fluResp, status := validationErrorCallback(resp) @@ -223,7 +223,7 @@ func addSendBackAuth(req *http.Request, fpsModel models.ProjectConfiguration, bo } } -func validationErrorCallback(resp *http.Response) (*Response, status_codes.StatusCode) { +func validationErrorCallback(resp *http.Response) (*FluResponse, status_codes.StatusCode) { defer resp.Body.Close() fluResp := ParseFluResponse(resp) @@ -234,7 +234,7 @@ func validationErrorCallback(resp *http.Response) (*Response, status_codes.Statu } else { //If any invalid flu response code is in our InvalidationCodeArray, then we log[ERROR] it for _, invalidFlu := range fluResp.Invalid_Flus { - if IsValidInternalError(invalidFlu.Flu_Id) { + if IsValidInternalError(invalidFlu.Error) { return fluResp, status_codes.FluRespFailure } } diff --git a/app/services/flu_svc/flu_output/flu_utils.go b/app/services/flu_svc/flu_output/flu_utils.go index f53a489ad721..707c9c0b128c 100644 --- a/app/services/flu_svc/flu_output/flu_utils.go +++ b/app/services/flu_svc/flu_output/flu_utils.go @@ -12,8 +12,8 @@ import ( "github.com/crowdflux/angel/app/plog" ) -func ParseFluResponse(resp *http.Response) *Response { - fluResp := &Response{} +func ParseFluResponse(resp *http.Response) *FluResponse { + fluResp := &FluResponse{} fluResp.HttpStatusCode = resp.StatusCode body, _ := ioutil.ReadAll(resp.Body) @@ -21,6 +21,7 @@ func ParseFluResponse(resp *http.Response) *Response { plog.Info("response Headers:", resp.Header) plog.Info("response Headers:", resp) plog.Info("response Body:", string(body)) + fluResp.RawResponse = string(body) err := json.Unmarshal(body, fluResp) if err != nil { @@ -78,7 +79,8 @@ func IsValidInternalError(internalCode string) bool { return false } -func putDbLog(completedFLUs []models.FeedLineUnit, message string, resp Response) { +func putDbLog(completedFLUs []models.FeedLineUnit, message string, resp FluResponse) { + dbLogArr := make([]models.FeedLineLog, len(completedFLUs)) jsObj := models.JsonF{} jsonBytes, _ := json.Marshal(resp) diff --git a/app/services/flu_svc/flu_output/transport.go b/app/services/flu_svc/flu_output/transport.go index c4cc918d857b..1f51e3ad6413 100644 --- a/app/services/flu_svc/flu_output/transport.go +++ b/app/services/flu_svc/flu_output/transport.go @@ -3,10 +3,11 @@ package flu_output import "github.com/crowdflux/angel/app/models/status_codes" //TODO rest will be added later -type Response struct { +type FluResponse struct { HttpStatusCode int FluStatusCode status_codes.StatusCode Invalid_Flus []invalidFlu `json:"invalid_flus"` + RawResponse string } type invalidFlu struct { Flu_Id string `json:"flu_id"`