forked from TrueCloudLab/frostfs-node
[#1608] qos: Add client grpc interceptors
`qos` client interceptors replace internal IO tags `writecache`, `policer` and `background` with `internal` IO tag for outcomming RPC. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
dc6aea7b79
commit
acec938b2d
5 changed files with 70 additions and 14 deletions
51
internal/qos/grpc.go
Normal file
51
internal/qos/grpc.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package qos
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-qos/tagging"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewSetCriticalIOTagUnaryServerInterceptor() grpc.UnaryServerInterceptor {
|
||||
return func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
|
||||
ctx = tagging.ContextWithIOTag(ctx, IOTagCritical.String())
|
||||
return handler(ctx, req)
|
||||
}
|
||||
}
|
||||
|
||||
func NewAdjustOutgoingIOTagUnaryClientInterceptor() grpc.UnaryClientInterceptor {
|
||||
return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
||||
rawTag, ok := tagging.IOTagFromContext(ctx)
|
||||
if !ok {
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
}
|
||||
tag, err := FromRawString(rawTag)
|
||||
if err != nil {
|
||||
tag = IOTagClient
|
||||
}
|
||||
if tag == IOTagBackground || tag == IOTagPolicer || tag == IOTagWritecache {
|
||||
tag = IOTagInternal
|
||||
}
|
||||
ctx = tagging.ContextWithIOTag(ctx, tag.String())
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func NewAdjustOutgoingIOTagStreamClientInterceptor() grpc.StreamClientInterceptor {
|
||||
return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) {
|
||||
rawTag, ok := tagging.IOTagFromContext(ctx)
|
||||
if !ok {
|
||||
return streamer(ctx, desc, cc, method, opts...)
|
||||
}
|
||||
tag, err := FromRawString(rawTag)
|
||||
if err != nil {
|
||||
tag = IOTagClient
|
||||
}
|
||||
if tag == IOTagBackground || tag == IOTagPolicer || tag == IOTagWritecache {
|
||||
tag = IOTagInternal
|
||||
}
|
||||
ctx = tagging.ContextWithIOTag(ctx, tag.String())
|
||||
return streamer(ctx, desc, cc, method, opts...)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue