From da0021a9b31e62ebea098cb1421bb7a58244fbbc Mon Sep 17 00:00:00 2001 From: Howl Date: Sun, 2 Oct 2016 19:47:31 +0200 Subject: [PATCH] Add some datadog shit --- app/method.go | 11 +---------- app/start.go | 17 +++++++++++++++-- app/v1/token.go | 2 ++ common/method_data.go | 2 ++ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/method.go b/app/method.go index 7af3908..debb8fe 100644 --- a/app/method.go +++ b/app/method.go @@ -45,6 +45,7 @@ func initialCaretaker(c *gin.Context, f func(md common.MethodData) common.CodeMe DB: db, RequestData: data, C: c, + Doggo: doggo, } if token != "" { tokenReal, exists := GetTokenFull(token, db) @@ -85,16 +86,6 @@ func initialCaretaker(c *gin.Context, f func(md common.MethodData) common.CodeMe } resp := f(md) - if resp.GetCode() == 0 { - // Dirty hack to set the code - type setCoder interface { - SetCode(int) - } - if newver, can := resp.(setCoder); can { - newver.SetCode(500) - } - } - if md.HasQuery("pls200") { c.Writer.WriteHeader(200) } else { diff --git a/app/start.go b/app/start.go index 609ec50..dcd6761 100644 --- a/app/start.go +++ b/app/start.go @@ -7,6 +7,7 @@ import ( "git.zxq.co/ripple/rippleapi/app/peppy" "git.zxq.co/ripple/rippleapi/app/v1" "git.zxq.co/ripple/rippleapi/common" + "github.com/DataDog/datadog-go/statsd" "github.com/getsentry/raven-go" "github.com/gin-gonic/contrib/gzip" "github.com/gin-gonic/gin" @@ -15,8 +16,9 @@ import ( ) var ( - db *sqlx.DB - cf common.Conf + db *sqlx.DB + cf common.Conf + doggo *statsd.Client ) var commonClusterfucks = map[string]string{ @@ -41,6 +43,7 @@ func Start(conf common.Conf, dbO *sqlx.DB) *gin.Engine { r := gin.Default() r.Use(gzip.Gzip(gzip.DefaultCompression)) + // sentry if conf.SentryDSN != "" { ravenClient, err := raven.New(conf.SentryDSN) ravenClient.SetRelease(common.Version) @@ -51,6 +54,16 @@ func Start(conf common.Conf, dbO *sqlx.DB) *gin.Engine { } } + // datadog + doggo, err := statsd.New("127.0.0.1:8125") + if err != nil { + fmt.Println(err) + } + doggo.Namespace = "api." + r.Use(func(c *gin.Context) { + doggo.Incr("requests", nil, 1) + }) + api := r.Group("/api") { p := api.Group("/") diff --git a/app/v1/token.go b/app/v1/token.go index d2b2f03..d96fe8f 100644 --- a/app/v1/token.go +++ b/app/v1/token.go @@ -41,6 +41,8 @@ func TokenNewPOST(md common.MethodData) common.CodeMessager { return ErrBadJSON } + md.Doggo.Incr("tokens.new", nil, 1) + var miss []string if data.Username == "" && data.UserID == 0 { miss = append(miss, "username|id") diff --git a/common/method_data.go b/common/method_data.go index 15ecb78..c60c187 100644 --- a/common/method_data.go +++ b/common/method_data.go @@ -3,6 +3,7 @@ package common import ( "encoding/json" + "github.com/DataDog/datadog-go/statsd" "github.com/gin-gonic/gin" "github.com/jmoiron/sqlx" ) @@ -13,6 +14,7 @@ type MethodData struct { DB *sqlx.DB RequestData RequestData C *gin.Context + Doggo *statsd.Client } // Err logs an error into gin.