Skip to content

Commit

Permalink
fix: should not ignore slowThreshold (#4655)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan authored Feb 14, 2025
1 parent 6a0672b commit 790302b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions zrpc/internal/serverinterceptors/statinterceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (

// StatConf defines the static configuration for stat interceptor.
type StatConf struct {
SlowThreshold time.Duration `json:",optional"`
SlowThreshold time.Duration `json:",default=500ms"`
IgnoreContentMethods []string `json:",optional"`
}

Expand Down Expand Up @@ -63,7 +63,8 @@ func UnaryStatInterceptor(metrics *stat.Metrics, conf StatConf) grpc.UnaryServer
}

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,
Expand Down
5 changes: 3 additions & 2 deletions zrpc/internal/serverinterceptors/statinterceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func Test_isSlow(t *testing.T) {
args{
duration: time.Millisecond * 501,
},
false,
true,
nil,
},
{
Expand All @@ -251,7 +251,8 @@ func Test_isSlow(t *testing.T) {
t.Cleanup(func() {
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)
})
}
}

0 comments on commit 790302b

Please sign in to comment.