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