Add some datadog shit
This commit is contained in:
parent
c54c1565ca
commit
da0021a9b3
|
@ -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 {
|
||||
|
|
17
app/start.go
17
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("/")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user