mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 00:40:00 +08:00
fix(zrpc): fix slow threshold priority in stat interceptor (#5310)
Co-authored-by: qiuwenhao <qiushaotest@qq.com>
This commit is contained in:
@@ -63,8 +63,12 @@ func UnaryStatInterceptor(metrics *stat.Metrics, conf StatConf) grpc.UnaryServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isSlow(duration, durationThreshold time.Duration) bool {
|
func isSlow(duration, durationThreshold time.Duration) bool {
|
||||||
return duration > slowThreshold.Load() ||
|
// Prioritize explicit config over global setting
|
||||||
(durationThreshold > 0 && duration > durationThreshold)
|
if durationThreshold > 0 {
|
||||||
|
return duration > durationThreshold
|
||||||
|
}
|
||||||
|
|
||||||
|
return duration > slowThreshold.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func logDuration(ctx context.Context, method string, req any, duration time.Duration,
|
func logDuration(ctx context.Context, method string, req any, duration time.Duration,
|
||||||
|
|||||||
@@ -252,6 +252,15 @@ func Test_isSlow(t *testing.T) {
|
|||||||
SetSlowThreshold(time.Millisecond * 100)
|
SetSlowThreshold(time.Millisecond * 100)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"config_priority_fix",
|
||||||
|
args{
|
||||||
|
duration: time.Millisecond * 600,
|
||||||
|
staticSlowThreshold: time.Millisecond * 1000,
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user