enhance: use the rate log in the privilege interceptor (#32037)

/kind improvement

Signed-off-by: SimFG <bang.fu@zilliz.com>
This commit is contained in:
SimFG 2024-04-09 16:19:17 +08:00 committed by GitHub
parent a0a4ec8b67
commit 420baacb6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View File

@ -88,10 +88,10 @@ func PrivilegeInterceptor(ctx context.Context, req interface{}) (context.Context
return ctx, nil
}
log := log.Ctx(ctx)
log.Debug("PrivilegeInterceptor", zap.String("type", reflect.TypeOf(req).String()))
log.RatedDebug(60, "PrivilegeInterceptor", zap.String("type", reflect.TypeOf(req).String()))
privilegeExt, err := funcutil.GetPrivilegeExtObj(req)
if err != nil {
log.Info("GetPrivilegeExtObj err", zap.Error(err))
log.RatedInfo(60, "GetPrivilegeExtObj err", zap.Error(err))
return ctx, nil
}
username, err := GetCurUserFromContext(ctx)

View File

@ -34,17 +34,17 @@ func GetVersion(m proto.GeneratedMessage) (string, error) {
func GetPrivilegeExtObj(m proto.GeneratedMessage) (commonpb.PrivilegeExt, error) {
_, md := descriptor.MessageDescriptorProto(m)
if md == nil {
log.Info("MessageDescriptorProto result is nil")
log.RatedInfo(60, "MessageDescriptorProto result is nil")
return commonpb.PrivilegeExt{}, fmt.Errorf("MessageDescriptorProto result is nil")
}
extObj, err := proto.GetExtension(md.Options, commonpb.E_PrivilegeExtObj)
if err != nil {
log.Info("GetExtension fail", zap.Error(err))
log.RatedInfo(60, "GetExtension fail", zap.Error(err))
return commonpb.PrivilegeExt{}, err
}
privilegeExt := extObj.(*commonpb.PrivilegeExt)
log.Debug("GetPrivilegeExtObj success", zap.String("resource_type", privilegeExt.ObjectType.String()), zap.String("resource_privilege", privilegeExt.ObjectPrivilege.String()))
log.RatedDebug(60, "GetPrivilegeExtObj success", zap.String("resource_type", privilegeExt.ObjectType.String()), zap.String("resource_privilege", privilegeExt.ObjectPrivilege.String()))
return commonpb.PrivilegeExt{
ObjectType: privilegeExt.ObjectType,
ObjectPrivilege: privilegeExt.ObjectPrivilege,