Skip to content

Commit

Permalink
Merge pull request cockroachdb#110 from crowdflux/feature/sentry_inte…
Browse files Browse the repository at this point in the history
…gration

Feature/sentry integration
  • Loading branch information
govindamurali authored Feb 6, 2017
2 parents e1ff564 + 6797def commit 88c82f0
Show file tree
Hide file tree
Showing 40 changed files with 222 additions and 97 deletions.
3 changes: 2 additions & 1 deletion app/DAL/call_back_unit_pipe/call_back_unit_pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/crowdflux/angel/app/models"
"github.com/crowdflux/angel/app/models/uuid"
"github.com/crowdflux/angel/app/plog"
"github.com/crowdflux/angel/app/plog/log_tags"
"github.com/streadway/amqp"
"sync"
)
Expand Down Expand Up @@ -36,7 +37,7 @@ func (fmcr *CBU) ConfirmReceive() {

err := fmcr.delivery.Ack(false)
if err != nil {
plog.Error("CBU", err, "error while ack", "RequestOject: ", fmcr.FluOutputObj)
plog.Error("CBU", err, plog.M("Error while ack"), plog.MP(log_tags.POSTBACK_REQUEST, fmcr.FluOutputObj))
panic(err)
}
})
Expand Down
6 changes: 3 additions & 3 deletions app/DAL/clients/postgres/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ func (pg *transactionalPostgres) SelectJoin(holder interface{}, query string, ar

func (pg *transactionalPostgres) Commit() {
if err := pg.trans.Commit(); err != nil {
plog.Error("Postgres client", err, "Error occured while Commit transaction")
plog.Error("Postgres client", err, plog.Message("Error occured while Commit transaction"))
panic(err)
}
}

func (pg *transactionalPostgres) Rollback() {
if err := pg.trans.Rollback(); err != nil {
plog.Error("Postgres client", err, "Error occured in Rollback transaction")
plog.Error("Postgres client", err, plog.Message("Error occured in Rollback transaction"))
panic(err)
}
}
Expand All @@ -69,7 +69,7 @@ func GetTransactionClient() *transactionalPostgres {

tx, err := gorpDbMap.Begin()
if err != nil {
plog.Error("Postgres client", err, "Error occured in creating transaction")
plog.Error("Postgres client", err, plog.Message("Error occured in creating transaction"))
panic(err)
}

Expand Down
3 changes: 2 additions & 1 deletion app/DAL/feed_line/feed_line_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package feed_line
import (
"github.com/crowdflux/angel/app/models"
"github.com/crowdflux/angel/app/plog"
"github.com/crowdflux/angel/app/plog/log_tags"
"github.com/streadway/amqp"
"sync"
)
Expand All @@ -28,7 +29,7 @@ func (flu *FLU) ConfirmReceive() {

err := flu.delivery.Ack(false)
if err != nil {
plog.Error("FLU", err, "error while ack", "fluId: "+flu.FeedLineUnit.ID.String())
plog.Error("FLU", err, plog.Message("Error while ack "), plog.MessageWithParam(log_tags.FLU_ID, flu.FeedLineUnit.ID))
panic(err)
}
})
Expand Down
3 changes: 2 additions & 1 deletion app/DAL/repositories/feed_line_repo/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/crowdflux/angel/app/models"
"github.com/crowdflux/angel/app/models/uuid"
"github.com/crowdflux/angel/app/plog"
"github.com/crowdflux/angel/app/plog/log_tags"
"gopkg.in/mgo.v2/bson"
)

Expand Down Expand Up @@ -132,7 +133,7 @@ func SyncAllBack() {

err = inpQ.mgo.C("feedline_input").UpdateId(updateFlu.ID, updateFlu)
if err != nil {
plog.Error("feedline", err, updateFlu)
plog.Error("feedline", err, plog.Message("Flu not updated"), plog.MessageWithParam(log_tags.FLU, updateFlu))
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/DAL/repositories/feed_line_repo/input_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (i *inputQueue) Add(flu models.FeedLineUnit) (id uuid.UUID, err error) {
if e, ok := err.(*mgo.LastError); ok && e.Code == 11000 {
return uuid.Nil, ErrDuplicateReferenceId
} else {
plog.Error("Input queue", err, "mongo insert failed")
plog.Error("Input queue", err, plog.Message("Mongo insert failed"))
}
}
return flu.ID, err
Expand Down
21 changes: 20 additions & 1 deletion app/plog/log_levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package plog
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/crowdflux/angel/app/config"
"github.com/getsentry/raven-go"
"runtime"
)

Expand All @@ -16,8 +18,25 @@ func Fatal(tag string, err error, args ...interface{}) {
}
}

func Error(tag string, err error, args ...interface{}) {
// we can pass plog.Message here in place if raven.Interface
func Error(tag string, err error, args ...message) {
if levelError >= plogLevel {
if config.IsProduction() {
sentryItems := map[string]string{"tag": tag}
for _, arg := range args {
key := string(arg.Tag.Type)
value := fmt.Sprintf("%+v", arg.Params)

val, ok := sentryItems[key]
if !ok {
sentryItems[key] = value

} else {
sentryItems[key] = val + " ; " + value
}
}
raven.DefaultClient.CaptureError(err, sentryItems)
}
logr.WithFields(logrus.Fields{
"error": err,
"args": fmt.Sprintf("%+v", args),
Expand Down
32 changes: 32 additions & 0 deletions app/plog/log_tags/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package log_tags

import "tag"

var MESSAGE = &tag.Tag{"message"}

var USER_ID = &tag.Tag{"user_id"}
var CLIENT_ID = &tag.Tag{"client_id"}

var RESPONSE_BODY = &tag.Tag{"response_body"}
var REQUEST_BODY = &tag.Tag{"request_body"}

var HEADER = &tag.Tag{"header"}

var RECOVER = &tag.Tag{"recover"}

var FILE_NAME = &tag.Tag{"file_name"}
var FILE_PATH = &tag.Tag{"file_path"}
var ROW_NUM = &tag.Tag{"row_number"}
var COLUMN_NUM = &tag.Tag{"column_number"}

var FLU_ID = &tag.Tag{"flu_id"}
var MASTER_FLU_ID = &tag.Tag{"master_flu_id"}
var FLU_BUILD = &tag.Tag{"flu_build"}
var FLU = &tag.Tag{"flu"}
var PROJECT_ID = &tag.Tag{"project_id"}
var WORKFLOW_ID = &tag.Tag{"workflow_id"}
var PROJECT_TAG = &tag.Tag{"project_tag"}
var STEP_ID = &tag.Tag{"step_id"}

var POSTBACK_REQUEST = &tag.Tag{"postback_request"}
var POSTBACK_RESPONSE = &tag.Tag{"postback_reponse"}
28 changes: 28 additions & 0 deletions app/plog/message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package plog

import (
"github.com/crowdflux/angel/app/plog/log_tags"
"tag"
)

type message struct {
Tag tag.Tag `json:"Tag"`
Params interface{} `json:"params,omitempty"`
}

var MP = MessageWithParam
var M = Message

func MessageWithParam(tag *tag.Tag, param interface{}) message {
return message{
Tag: *tag,
Params: param,
}
}

func Message(param interface{}) message {
return message{
Tag: *log_tags.MESSAGE,
Params: param,
}
}
3 changes: 3 additions & 0 deletions app/plog/plog_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/crowdflux/angel/app/config"
"github.com/getsentry/raven-go"
"github.com/jasonlvhit/gocron"
"os"
"path/filepath"
Expand Down Expand Up @@ -51,6 +52,8 @@ func init() {

setLogger(logr, path, logTypeStr)

raven.SetDSN("https://b76a676d4e9744ffbdbfe40e522c4fb1:[email protected]/4")

logLevelStr := strings.ToUpper(config.PLOG_LEVEL.Get())

plogLevel = levels[logLevelStr]
Expand Down
18 changes: 13 additions & 5 deletions app/plog/plog_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package plog
package plog_test

import (
"github.com/crowdflux/angel/app/plog"
"github.com/crowdflux/angel/app/plog/log_tags"
"testing"
"time"
)
Expand All @@ -9,21 +11,27 @@ type s1 struct {
Id int
}

type s2 struct {
Id int
pc string
}

func (s1) Error() string {
return "fuck up"
}

func TestErrorMail(t *testing.T) {

t.SkipNow()
Error("testing", s1{124}, "")
Error("testing", s1{125}, "with message")
Error("testing", s1{124}, "with message & args", 123, "Asd")
plog.Error("testing", s1{124}, plog.MessageWithParam(log_tags.FLU_ID, s2{1212, "asdokads"}), plog.Message("Asd"))
plog.Error("testing", s1{124})
plog.Error("testing", s1{125}, plog.M("with message"))
plog.Error("testing", s1{124}, plog.MessageWithParam(log_tags.ROW_NUM, 123))
time.Sleep(time.Duration(10) * time.Second)
}

func TestCustomLogger(t *testing.T) {
c := NewLogger("somelog", "INFO", "FILE")
c := plog.NewLogger("somelog", "INFO", "FILE")

c.Info("testingjhoh", s1{124}, "")
c.Info("testihihjing", s1{125}, "with message")
Expand Down
5 changes: 5 additions & 0 deletions app/plog/vendor/tag/tag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package tag

type Tag struct {
Type string
}
2 changes: 1 addition & 1 deletion app/services/flu_logger_svc/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func dbLogSyncer(fluLogger feed_line_repo.IFluLogger) {
err := fluLogger.Log(bufferedFlogs)

if err != nil {
plog.Error("Feedline logger", err, "error saving logs to db")
plog.Error("Feedline logger", err, plog.Message("error saving logs to db"))
} else {

// confirm to the channel that the batch processing has been
Expand Down
2 changes: 1 addition & 1 deletion app/services/flu_svc/csv_upload_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func writeCsvError(csvWrite *csv.Writer, c chan []string, projectId, errFilePath
imdb.FluUploadCache.Set(projectId, fus)

if err := csvWrite.Write(row); err != nil {
plog.Error("CSVERR001", err, "error while writning csv")
plog.Error("csv_upload_helper", err, plog.M("error while writning csv"))
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/services/flu_svc/flu_monitor/call_back_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/crowdflux/angel/app/DAL/call_back_unit_pipe"
"github.com/crowdflux/angel/app/models"
"github.com/crowdflux/angel/app/plog"
"github.com/crowdflux/angel/app/plog/log_tags"
"net/http"
)

Expand All @@ -12,7 +13,7 @@ func getCallBackJob(pHandler *ProjectHandler, cbu *call_back_unit_pipe.CBU) func
return func() {
req, err := createRequest(cbu.ProjectConfig, cbu.FluOutputObj)
if err != nil {
plog.Error("FluMonitor", err, "Error while creating request", " fluOutputObj : ", cbu.FluOutputObj)
plog.Error("FluMonitor", err, plog.M("Error while creating request"), plog.MP(log_tags.POSTBACK_REQUEST, cbu.FluOutputObj))
}
client := http.DefaultClient
resp, err := client.Do(&req)
Expand Down
3 changes: 2 additions & 1 deletion app/services/flu_svc/flu_monitor/flu_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/crowdflux/angel/app/models"
"github.com/crowdflux/angel/app/models/uuid"
"github.com/crowdflux/angel/app/plog"
"github.com/crowdflux/angel/app/plog/log_tags"
"github.com/crowdflux/angel/app/services"
"github.com/crowdflux/angel/bulk_processor"
"sync"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (fm *FluMonitor) getOrCreateProjectHandler(flu models.FeedLineUnit) Project
pcRepo := project_configuration_repo.New()
pc, err := pcRepo.Get(flu.ProjectId)
if err != nil {
plog.Error("Error while getting Project configuration", err, " ProjectId:", flu.ProjectId)
plog.Error("Error while getting Project configuration", err, plog.MP(log_tags.PROJECT_ID, flu.ProjectId))
}

pHandler := NewProjectHandler(pc)
Expand Down
3 changes: 2 additions & 1 deletion app/services/flu_svc/flu_monitor/flu_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/crowdflux/angel/app/models/status_codes"
"github.com/crowdflux/angel/app/plog"
"github.com/crowdflux/angel/app/plog/log_tags"
)

type WebhookResponse struct {
Expand Down Expand Up @@ -34,7 +35,7 @@ func ParseFluResponse(resp *http.Response) *WebhookResponse {
}*/

plog.Error("Response Parsing Error: ", err, "fluResponse", fluResp)
plog.Error("Response Parsing Error: ", err, plog.MP(log_tags.POSTBACK_RESPONSE, fluResp))
return fluResp

}
Expand Down
2 changes: 1 addition & 1 deletion app/services/flu_svc/flu_monitor/request_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func createRequest(config models.ProjectConfiguration, fluOutputStructs []models
}{fluOutputStructs})

if err != nil {
plog.Error("FluMonitor", err, "JSON Marshalling Error:")
plog.Error("FluMonitor", err, plog.M("JSON Marshalling Error:"))
return request, err
}
jsonBytes = utilities.ReplaceEscapeCharacters(jsonBytes)
Expand Down
8 changes: 4 additions & 4 deletions app/services/flu_svc/flu_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (i *fluService) SyncInputFeedLine() error {

if err != nil {

plog.Error("Error occured while getting data", err)
plog.Error("Flu_svc", err, plog.Message("Error occured while getting data"))
return err
}

Expand All @@ -103,7 +103,7 @@ func (i *fluService) SyncInputFeedLine() error {
err = i.fluRepo.BulkInsert(flus)

if err != nil {
plog.Error("Bulk insert failed", err)
plog.Error("Flu_svc", err, plog.Message("Bulk insert failed"))
return err
}

Expand All @@ -119,7 +119,7 @@ func (i *fluService) SyncInputFeedLine() error {
err = fluInputQueue.MarkFinished(flus)

if err != nil {
plog.Error("Changing queue status failed", err)
plog.Error("Flu_svc", err, plog.Message("Changing queue status failed"))
return err
}
//plog.Info(len(flus), "flus processed")
Expand Down Expand Up @@ -174,7 +174,7 @@ func (i *fluService) CsvCheckBasicValidation(file multipart.File, fileName strin
cnt++

if err != nil {
plog.Error("FLU_SVC", err, " csv reading error")
plog.Error("Flu_svc", err, plog.M(" csv reading error"))
return err
}

Expand Down
Loading

0 comments on commit 88c82f0

Please sign in to comment.