All checks were successful
Build / Build Components (push) Successful in 2m24s
Pre-commit hooks / Pre-commit (push) Successful in 2m43s
Vulncheck / Vulncheck (push) Successful in 3m15s
Tests and linters / gopls check (push) Successful in 5m1s
OCI image / Build container images (push) Successful in 5m36s
Tests and linters / Lint (push) Successful in 6m17s
Tests and linters / Staticcheck (push) Successful in 6m16s
Tests and linters / Run gofumpt (push) Successful in 6m29s
Tests and linters / Tests (push) Successful in 9m40s
Tests and linters / Tests with -race (push) Successful in 9m41s
Tree sync is too much different from GC and rebuild to use the same tag for GC and tree sync. Change-Id: Ib44d5fa9a88daff507d759d0b0410cc9272e236f Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
86 lines
2.8 KiB
Go
86 lines
2.8 KiB
Go
package qos
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-qos/limiting"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-qos/tagging"
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
"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.IsLocal() {
|
|
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.IsLocal() {
|
|
tag = IOTagInternal
|
|
}
|
|
ctx = tagging.ContextWithIOTag(ctx, tag.String())
|
|
return streamer(ctx, desc, cc, method, opts...)
|
|
}
|
|
}
|
|
|
|
func NewMaxActiveRPCLimiterUnaryServerInterceptor(getLimiter func() limiting.Limiter) grpc.UnaryServerInterceptor {
|
|
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
|
|
if tag, ok := tagging.IOTagFromContext(ctx); ok && tag == IOTagCritical.String() {
|
|
return handler(ctx, req)
|
|
}
|
|
|
|
release, ok := getLimiter().Acquire(info.FullMethod)
|
|
if !ok {
|
|
return nil, new(apistatus.ResourceExhausted)
|
|
}
|
|
defer release()
|
|
|
|
return handler(ctx, req)
|
|
}
|
|
}
|
|
|
|
//nolint:contextcheck (grpc.ServerStream manages the context itself)
|
|
func NewMaxActiveRPCLimiterStreamServerInterceptor(getLimiter func() limiting.Limiter) grpc.StreamServerInterceptor {
|
|
return func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
|
|
if tag, ok := tagging.IOTagFromContext(ss.Context()); ok && tag == IOTagCritical.String() {
|
|
return handler(srv, ss)
|
|
}
|
|
|
|
release, ok := getLimiter().Acquire(info.FullMethod)
|
|
if !ok {
|
|
return new(apistatus.ResourceExhausted)
|
|
}
|
|
defer release()
|
|
|
|
return handler(srv, ss)
|
|
}
|
|
}
|