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,
|
DB: db,
|
||||||
RequestData: data,
|
RequestData: data,
|
||||||
C: c,
|
C: c,
|
||||||
|
Doggo: doggo,
|
||||||
}
|
}
|
||||||
if token != "" {
|
if token != "" {
|
||||||
tokenReal, exists := GetTokenFull(token, db)
|
tokenReal, exists := GetTokenFull(token, db)
|
||||||
|
@ -85,16 +86,6 @@ func initialCaretaker(c *gin.Context, f func(md common.MethodData) common.CodeMe
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := f(md)
|
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") {
|
if md.HasQuery("pls200") {
|
||||||
c.Writer.WriteHeader(200)
|
c.Writer.WriteHeader(200)
|
||||||
} else {
|
} else {
|
||||||
|
|
13
app/start.go
13
app/start.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"git.zxq.co/ripple/rippleapi/app/peppy"
|
"git.zxq.co/ripple/rippleapi/app/peppy"
|
||||||
"git.zxq.co/ripple/rippleapi/app/v1"
|
"git.zxq.co/ripple/rippleapi/app/v1"
|
||||||
"git.zxq.co/ripple/rippleapi/common"
|
"git.zxq.co/ripple/rippleapi/common"
|
||||||
|
"github.com/DataDog/datadog-go/statsd"
|
||||||
"github.com/getsentry/raven-go"
|
"github.com/getsentry/raven-go"
|
||||||
"github.com/gin-gonic/contrib/gzip"
|
"github.com/gin-gonic/contrib/gzip"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -17,6 +18,7 @@ import (
|
||||||
var (
|
var (
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
cf common.Conf
|
cf common.Conf
|
||||||
|
doggo *statsd.Client
|
||||||
)
|
)
|
||||||
|
|
||||||
var commonClusterfucks = map[string]string{
|
var commonClusterfucks = map[string]string{
|
||||||
|
@ -41,6 +43,7 @@ func Start(conf common.Conf, dbO *sqlx.DB) *gin.Engine {
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.Use(gzip.Gzip(gzip.DefaultCompression))
|
r.Use(gzip.Gzip(gzip.DefaultCompression))
|
||||||
|
|
||||||
|
// sentry
|
||||||
if conf.SentryDSN != "" {
|
if conf.SentryDSN != "" {
|
||||||
ravenClient, err := raven.New(conf.SentryDSN)
|
ravenClient, err := raven.New(conf.SentryDSN)
|
||||||
ravenClient.SetRelease(common.Version)
|
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")
|
api := r.Group("/api")
|
||||||
{
|
{
|
||||||
p := api.Group("/")
|
p := api.Group("/")
|
||||||
|
|
|
@ -41,6 +41,8 @@ func TokenNewPOST(md common.MethodData) common.CodeMessager {
|
||||||
return ErrBadJSON
|
return ErrBadJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
|
md.Doggo.Incr("tokens.new", nil, 1)
|
||||||
|
|
||||||
var miss []string
|
var miss []string
|
||||||
if data.Username == "" && data.UserID == 0 {
|
if data.Username == "" && data.UserID == 0 {
|
||||||
miss = append(miss, "username|id")
|
miss = append(miss, "username|id")
|
||||||
|
|
|
@ -3,6 +3,7 @@ package common
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/DataDog/datadog-go/statsd"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
@ -13,6 +14,7 @@ type MethodData struct {
|
||||||
DB *sqlx.DB
|
DB *sqlx.DB
|
||||||
RequestData RequestData
|
RequestData RequestData
|
||||||
C *gin.Context
|
C *gin.Context
|
||||||
|
Doggo *statsd.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// Err logs an error into gin.
|
// Err logs an error into gin.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user