feat: fix prometheus filter bugs (#1792)

* fix: fix prometheus

* fix: count latency with prefix api

* fix: latency should not be counted when startTime is nil
This commit is contained in:
OutOfEastGate
2023-04-26 22:18:48 +08:00
committed by GitHub
parent 4c1915b014
commit e4c36d407f
5 changed files with 40 additions and 42 deletions

View File

@ -183,3 +183,14 @@ func wrapErrorResponse(err error) *Response {
return &Response{Status: "error", Msg: err.Error()}
}
}
func (c *ApiController) Finish() {
if strings.HasPrefix(c.Ctx.Input.URL(), "/api") {
startTime := c.Ctx.Input.GetData("startTime")
if startTime != nil {
latency := time.Since(startTime.(time.Time)).Milliseconds()
object.ApiLatency.WithLabelValues(c.Ctx.Input.Method(), c.Ctx.Input.URL()).Observe(float64(latency))
}
}
c.Controller.Finish()
}