give blank method for datadog-agent

This commit is contained in:
Ulric Qin 2022-03-28 16:41:31 +08:00
parent db29adff5d
commit b260a20646
3 changed files with 52 additions and 27 deletions

View File

@ -276,7 +276,7 @@ func LoggerWithConfig(conf LoggerConfig) gin.HandlerFunc {
param.Path = path
// fmt.Fprint(out, formatter(param))
logger.Debug(formatter(param))
logger.Info(formatter(param))
// if c.Request.Method != "GET" {
// logger.Debug(readBody(rdr1))

View File

@ -67,6 +67,10 @@ func configRoute(r *gin.Engine, version string) {
// use apiKey not basic auth
r.POST("/datadog/api/v1/series", datadogSeries)
r.POST("/datadog/api/v1/check_run", datadogCheckRun)
r.GET("/datadog/api/v1/validate", datadogValidate)
r.POST("/datadog/api/v1/metadata", datadogMetadata)
r.POST("/datadog/intake/", datadogIntake)
if len(config.C.BasicAuth) > 0 {
auth := gin.BasicAuth(config.C.BasicAuth)

View File

@ -139,6 +139,52 @@ func (m *DatadogMetric) ToProm() (*prompb.TimeSeries, string, error) {
return pt, ident, nil
}
func datadogCheckRun(c *gin.Context) {
c.String(200, "not implemented")
}
func datadogValidate(c *gin.Context) {
c.String(200, "not implemented")
}
func datadogIntake(c *gin.Context) {
c.String(200, "not implemented")
}
func datadogMetadata(c *gin.Context) {
// body, err := readDatadogBody(c)
// fmt.Println("metadata:", string(body), err)
c.String(200, "not implemented")
}
func readDatadogBody(c *gin.Context) ([]byte, error) {
var bs []byte
var err error
enc := c.GetHeader("Content-Encoding")
if enc == "gzip" {
r, e := gzip.NewReader(c.Request.Body)
if e != nil {
return nil, e
}
defer r.Close()
bs, err = ioutil.ReadAll(r)
} else if enc == "deflate" {
r, e := zlib.NewReader(c.Request.Body)
if e != nil {
return nil, e
}
defer r.Close()
bs, err = ioutil.ReadAll(r)
} else {
defer c.Request.Body.Close()
bs, err = ioutil.ReadAll(c.Request.Body)
}
return bs, err
}
func datadogSeries(c *gin.Context) {
apiKey, has := c.GetQuery("api_key")
if !has {
@ -161,32 +207,7 @@ func datadogSeries(c *gin.Context) {
}
}
var bs []byte
var err error
enc := c.GetHeader("Content-Encoding")
if enc == "gzip" {
r, err := gzip.NewReader(c.Request.Body)
if err != nil {
c.String(400, err.Error())
return
}
defer r.Close()
bs, err = ioutil.ReadAll(r)
} else if enc == "deflate" {
r, err := zlib.NewReader(c.Request.Body)
if err != nil {
c.String(400, err.Error())
return
}
defer r.Close()
bs, err = ioutil.ReadAll(r)
} else {
defer c.Request.Body.Close()
bs, err = ioutil.ReadAll(c.Request.Body)
}
bs, err := readDatadogBody(c)
if err != nil {
c.String(400, err.Error())
return