feat: metrics: do not log oauth callback
This commit is contained in:
parent
84a79c5460
commit
c36d68eddd
@ -13,6 +13,10 @@ func (s *service) SetLogPaths(paths []string) {
|
|||||||
s.logPaths = paths
|
s.logPaths = paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *service) SetIgnorePaths(paths []string) {
|
||||||
|
s.ignorePaths = paths
|
||||||
|
}
|
||||||
|
|
||||||
func (s *service) Handler() gin.HandlerFunc {
|
func (s *service) Handler() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
url := c.Request.URL.String()
|
url := c.Request.URL.String()
|
||||||
@ -23,6 +27,11 @@ func (s *service) Handler() gin.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if utils.Contains(s.ignorePaths, func(path string) bool { return strings.HasPrefix(url, path) }) {
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
c.Next()
|
c.Next()
|
||||||
elapsed := float64(time.Since(start)) / float64(time.Millisecond)
|
elapsed := float64(time.Since(start)) / float64(time.Millisecond)
|
||||||
|
@ -14,6 +14,7 @@ var _ Service = (*service)(nil)
|
|||||||
type Service interface {
|
type Service interface {
|
||||||
Record(method, url string, success bool, httpCode int, errCode e.Status, elapsed float64)
|
Record(method, url string, success bool, httpCode int, errCode e.Status, elapsed float64)
|
||||||
SetLogPaths(paths []string)
|
SetLogPaths(paths []string)
|
||||||
|
SetIgnorePaths(paths []string)
|
||||||
Handler() gin.HandlerFunc
|
Handler() gin.HandlerFunc
|
||||||
HealthCheck() error
|
HealthCheck() error
|
||||||
}
|
}
|
||||||
@ -35,6 +36,7 @@ type service struct {
|
|||||||
hist *prometheus.HistogramVec
|
hist *prometheus.HistogramVec
|
||||||
|
|
||||||
logPaths []string
|
logPaths []string
|
||||||
|
ignorePaths []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) HealthCheck() error {
|
func (s *service) HealthCheck() error {
|
||||||
|
@ -98,6 +98,7 @@ func (s *service) initRouters(conf *model.Config, injector *do.Injector) *gin.En
|
|||||||
|
|
||||||
// Prometheus middleware
|
// Prometheus middleware
|
||||||
s.metric.SetLogPaths([]string{"/api"})
|
s.metric.SetLogPaths([]string{"/api"})
|
||||||
|
s.metric.SetIgnorePaths([]string{"/api/v1/oauth/callback"})
|
||||||
r.Use(s.metric.Handler())
|
r.Use(s.metric.Handler())
|
||||||
|
|
||||||
// +------+
|
// +------+
|
||||||
|
Loading…
Reference in New Issue
Block a user