mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 18:00:00 +08:00
fix: should not ignore slowThreshold (#4655)
This commit is contained in:
@@ -25,7 +25,7 @@ var (
|
|||||||
|
|
||||||
// StatConf defines the static configuration for stat interceptor.
|
// StatConf defines the static configuration for stat interceptor.
|
||||||
type StatConf struct {
|
type StatConf struct {
|
||||||
SlowThreshold time.Duration `json:",optional"`
|
SlowThreshold time.Duration `json:",default=500ms"`
|
||||||
IgnoreContentMethods []string `json:",optional"`
|
IgnoreContentMethods []string `json:",optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,8 @@ func UnaryStatInterceptor(metrics *stat.Metrics, conf StatConf) grpc.UnaryServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isSlow(duration, durationThreshold time.Duration) bool {
|
func isSlow(duration, durationThreshold time.Duration) bool {
|
||||||
return durationThreshold > 0 && duration > durationThreshold
|
return duration > slowThreshold.Load() ||
|
||||||
|
(durationThreshold > 0 && duration > durationThreshold)
|
||||||
}
|
}
|
||||||
|
|
||||||
func logDuration(ctx context.Context, method string, req any, duration time.Duration,
|
func logDuration(ctx context.Context, method string, req any, duration time.Duration,
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ func Test_isSlow(t *testing.T) {
|
|||||||
args{
|
args{
|
||||||
duration: time.Millisecond * 501,
|
duration: time.Millisecond * 501,
|
||||||
},
|
},
|
||||||
false,
|
true,
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -251,7 +251,8 @@ func Test_isSlow(t *testing.T) {
|
|||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
slowThreshold = syncx.ForAtomicDuration(defaultSlowThreshold)
|
slowThreshold = syncx.ForAtomicDuration(defaultSlowThreshold)
|
||||||
})
|
})
|
||||||
assert.Equalf(t, tt.want, isSlow(tt.args.duration, tt.args.staticSlowThreshold), "isSlow(%v, %v)", tt.args.duration, tt.args.staticSlowThreshold)
|
assert.Equalf(t, tt.want, isSlow(tt.args.duration, tt.args.staticSlowThreshold),
|
||||||
|
"isSlow(%v, %v)", tt.args.duration, tt.args.staticSlowThreshold)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user