TEL-730: Log soft validation errors. (#4671)
This commit is contained in:
+34
-23
@@ -63,6 +63,17 @@ func NewSIPService(
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a new UnlikelyLogger, populated with values from the request context
|
||||
// (e.g. service, method, etc.).
|
||||
func unlikelyLoggerFromCtx(ctx context.Context) logger.UnlikelyLogger {
|
||||
var logFields []any
|
||||
logCtx, ok := ctx.Value(twirpLoggerKey{}).(*twirpLogger)
|
||||
if ok {
|
||||
logFields = logCtx.fields
|
||||
}
|
||||
return logger.GetLogger().WithUnlikelyValues(logFields...)
|
||||
}
|
||||
|
||||
func (s *SIPService) CreateSIPTrunk(ctx context.Context, req *livekit.CreateSIPTrunkRequest) (*livekit.SIPTrunkInfo, error) {
|
||||
if err := EnsureSIPAdminPermission(ctx); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
@@ -116,7 +127,7 @@ func (s *SIPService) CreateSIPInboundTrunk(ctx context.Context, req *livekit.Cre
|
||||
if s.store == nil {
|
||||
return nil, ErrSIPNotConnected
|
||||
}
|
||||
if err := req.Validate(); err != nil {
|
||||
if err := req.ValidateResult().LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
|
||||
return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err)
|
||||
}
|
||||
|
||||
@@ -155,7 +166,7 @@ func (s *SIPService) CreateSIPOutboundTrunk(ctx context.Context, req *livekit.Cr
|
||||
if s.store == nil {
|
||||
return nil, ErrSIPNotConnected
|
||||
}
|
||||
if err := req.Validate(); err != nil {
|
||||
if err := req.ValidateResult().LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
|
||||
return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err)
|
||||
}
|
||||
|
||||
@@ -180,7 +191,7 @@ func (s *SIPService) UpdateSIPInboundTrunk(ctx context.Context, req *livekit.Upd
|
||||
if s.store == nil {
|
||||
return nil, ErrSIPNotConnected
|
||||
}
|
||||
if err := req.Validate(); err != nil {
|
||||
if err := req.ValidateResult().LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
|
||||
return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err)
|
||||
}
|
||||
|
||||
@@ -201,8 +212,9 @@ func (s *SIPService) UpdateSIPInboundTrunk(ctx context.Context, req *livekit.Upd
|
||||
default:
|
||||
return nil, errors.New("missing or unsupported action")
|
||||
case livekit.UpdateSIPInboundTrunkRequestAction:
|
||||
info, err = a.Apply(info)
|
||||
if err != nil {
|
||||
var result livekit.ValidationResult
|
||||
info, result = a.ApplyResult(info)
|
||||
if err := result.LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -235,7 +247,7 @@ func (s *SIPService) UpdateSIPOutboundTrunk(ctx context.Context, req *livekit.Up
|
||||
if s.store == nil {
|
||||
return nil, ErrSIPNotConnected
|
||||
}
|
||||
if err := req.Validate(); err != nil {
|
||||
if err := req.ValidateResult().LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
|
||||
return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err)
|
||||
}
|
||||
|
||||
@@ -255,8 +267,9 @@ func (s *SIPService) UpdateSIPOutboundTrunk(ctx context.Context, req *livekit.Up
|
||||
default:
|
||||
return nil, errors.New("missing or unsupported action")
|
||||
case livekit.UpdateSIPOutboundTrunkRequestAction:
|
||||
info, err = a.Apply(info)
|
||||
if err != nil {
|
||||
var result livekit.ValidationResult
|
||||
info, result = a.ApplyResult(info)
|
||||
if err := result.LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -631,18 +644,16 @@ func (s *SIPService) CreateSIPParticipantRequest(ctx context.Context, req *livek
|
||||
return nil, ErrSIPNotConnected
|
||||
}
|
||||
req.Upgrade()
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err)
|
||||
}
|
||||
callID := sip.NewCallID()
|
||||
log := logger.GetLogger().WithUnlikelyValues(
|
||||
"callID", callID,
|
||||
"room", req.RoomName,
|
||||
"sipTrunk", req.SipTrunkId,
|
||||
"toUser", req.SipCallTo,
|
||||
"projectID", projectID,
|
||||
)
|
||||
if projectID != "" {
|
||||
log = log.WithValues("projectID", projectID)
|
||||
if err := req.ValidateResult().LogUnlikelySoftErrors(log); err != nil {
|
||||
return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err)
|
||||
}
|
||||
|
||||
var trunk *livekit.SIPOutboundTrunkInfo
|
||||
@@ -662,24 +673,23 @@ func (s *SIPService) CreateSIPParticipantRequest(ctx context.Context, req *livek
|
||||
} else if t := req.Trunk; t != nil && t.FromHost != "" {
|
||||
host = t.FromHost
|
||||
}
|
||||
return rpc.NewCreateSIPParticipantRequest(projectID, callID, host, wsUrl, token, req, trunk)
|
||||
internalReq, result := rpc.NewCreateSIPParticipantRequestResult(projectID, callID, host, wsUrl, token, req, trunk)
|
||||
if err := result.LogUnlikelySoftErrors(log); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return internalReq, nil
|
||||
}
|
||||
|
||||
func (s *SIPService) TransferSIPParticipant(ctx context.Context, req *livekit.TransferSIPParticipantRequest) (*emptypb.Empty, error) {
|
||||
log := logger.GetLogger().WithUnlikelyValues(
|
||||
"room", req.RoomName,
|
||||
"participant", req.ParticipantIdentity,
|
||||
"transferTo", req.TransferTo,
|
||||
"playDialtone", req.PlayDialtone,
|
||||
)
|
||||
AppendLogFields(ctx,
|
||||
"room", req.RoomName,
|
||||
"participant", req.ParticipantIdentity,
|
||||
"transferTo", req.TransferTo,
|
||||
"playDialtone", req.PlayDialtone,
|
||||
)
|
||||
log := unlikelyLoggerFromCtx(ctx)
|
||||
|
||||
ireq, err := s.transferSIPParticipantRequest(ctx, req)
|
||||
ireq, err := s.transferSIPParticipantRequest(ctx, req, log)
|
||||
if err != nil {
|
||||
log.Errorw("cannot create transfer sip participant request", err)
|
||||
return nil, wrapSIPContextError(err)
|
||||
@@ -715,7 +725,7 @@ func (s *SIPService) TransferSIPParticipant(ctx context.Context, req *livekit.Tr
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func (s *SIPService) transferSIPParticipantRequest(ctx context.Context, req *livekit.TransferSIPParticipantRequest) (*rpc.InternalTransferSIPParticipantRequest, error) {
|
||||
func (s *SIPService) transferSIPParticipantRequest(ctx context.Context, req *livekit.TransferSIPParticipantRequest, log logger.UnlikelyLogger) (*rpc.InternalTransferSIPParticipantRequest, error) {
|
||||
if req.RoomName == "" {
|
||||
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "Missing room name")
|
||||
}
|
||||
@@ -730,7 +740,8 @@ func (s *SIPService) transferSIPParticipantRequest(ctx context.Context, req *liv
|
||||
if err := EnsureAdminPermission(ctx, livekit.RoomName(req.RoomName)); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
if err := req.Validate(); err != nil {
|
||||
|
||||
if err := req.ValidateResult().LogUnlikelySoftErrors(log); err != nil {
|
||||
return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user