feat: metrics: do not log oauth callback

This commit is contained in:
Paul Pan 2024-01-06 21:55:44 +08:00
parent 84a79c5460
commit c36d68eddd
Signed by: Paul
GPG Key ID: D639BDF5BA578AF4
3 changed files with 13 additions and 1 deletions

View File

@ -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)

View File

@ -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
}
@ -34,7 +35,8 @@ type service struct {
counter *prometheus.CounterVec
hist *prometheus.HistogramVec
logPaths []string
logPaths []string
ignorePaths []string
}
func (s *service) HealthCheck() error {

View File

@ -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())
// +------+