chore: refactor set in collection package (#5016)

This commit is contained in:
Kevin Wan
2025-07-18 21:25:40 +08:00
committed by GitHub
parent bf6ef5f033
commit 3c9b6335fb
5 changed files with 74 additions and 441 deletions

View File

@@ -43,8 +43,8 @@ func SetSlowThreshold(threshold time.Duration) {
// UnaryStatInterceptor returns a func that uses given metrics to report stats.
func UnaryStatInterceptor(metrics *stat.Metrics, conf StatConf) grpc.UnaryServerInterceptor {
staticNotLoggingContentMethods := collection.NewSet()
staticNotLoggingContentMethods.AddStr(conf.IgnoreContentMethods...)
staticNotLoggingContentMethods := collection.NewSet[string]()
staticNotLoggingContentMethods.Add(conf.IgnoreContentMethods...)
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler) (resp any, err error) {
@@ -68,7 +68,7 @@ func isSlow(duration, durationThreshold time.Duration) bool {
}
func logDuration(ctx context.Context, method string, req any, duration time.Duration,
ignoreMethods *collection.Set, durationThreshold time.Duration) {
ignoreMethods *collection.Set[string], durationThreshold time.Duration) {
var addr string
client, ok := peer.FromContext(ctx)
if ok {
@@ -92,7 +92,7 @@ func logDuration(ctx context.Context, method string, req any, duration time.Dura
}
}
func shouldLogContent(method string, ignoreMethods *collection.Set) bool {
func shouldLogContent(method string, ignoreMethods *collection.Set[string]) bool {
_, ok := ignoreContentMethods.Load(method)
return !ok && !ignoreMethods.Contains(method)
}