added logging

This commit is contained in:
Stephan D
2026-02-01 02:03:55 +01:00
parent 433a0af5b4
commit c16fa8104e
6 changed files with 26 additions and 9 deletions

View File

@@ -9,16 +9,23 @@ import (
"github.com/shopspring/decimal"
"github.com/tech/sendico/payments/orchestrator/storage/model"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
"go.uber.org/zap"
)
func ensureGatewayForAction(ctx context.Context, registry GatewayRegistry, cache map[model.Rail]*model.GatewayInstanceDescriptor, rail model.Rail, network string, amount *paymenttypes.Money, action model.RailOperation, instanceID string, dir sendDirection) (*model.GatewayInstanceDescriptor, error) {
func ensureGatewayForAction(ctx context.Context, logger mlogger.Logger, registry GatewayRegistry, cache map[model.Rail]*model.GatewayInstanceDescriptor, rail model.Rail, network string, amount *paymenttypes.Money, action model.RailOperation, instanceID string, dir sendDirection) (*model.GatewayInstanceDescriptor, error) {
if registry == nil {
return nil, merrors.InvalidArgument("plan builder: gateway registry is required")
}
if gw, ok := cache[rail]; ok && gw != nil {
if instanceID == "" || strings.EqualFold(gw.InstanceID, instanceID) {
if err := validateGatewayAction(gw, network, amount, action, dir); err != nil {
logger.Warn("Failed to validate gateway", zap.Error(err),
zap.String("instance_id", instanceID), zap.String("rail", string(rail)),
zap.String("network", network), zap.String("action", string(action)),
zap.String("direction", sendDirectionLabel(dir)), zap.Int("ralis_qty", len(cache)),
)
return nil, err
}
return gw, nil
@@ -26,6 +33,11 @@ func ensureGatewayForAction(ctx context.Context, registry GatewayRegistry, cache
}
gw, err := selectGateway(ctx, registry, rail, network, amount, action, instanceID, dir)
if err != nil {
logger.Warn("Failed to select gateway", zap.Error(err),
zap.String("instance_id", instanceID), zap.String("rail", string(rail)),
zap.String("network", network), zap.String("action", string(action)),
zap.String("direction", sendDirectionLabel(dir)), zap.Int("ralis_qty", len(cache)),
)
return nil, err
}
cache[rail] = gw
@@ -106,7 +118,7 @@ func selectGateway(ctx context.Context, registry GatewayRegistry, rail model.Rai
}
if len(eligible) == 0 {
if lastErr != nil {
return nil, merrors.InvalidArgument("plan builder: no eligible gateway instance found: " + lastErr.Error())
return nil, merrors.InvalidArgument("plan builder: no eligible gateway instance found, last error: " + lastErr.Error())
}
return nil, merrors.InvalidArgument("plan builder: no eligible gateway instance found")
}

View File

@@ -164,8 +164,13 @@ func (b *defaultPlanBuilder) buildPlanFromTemplate(ctx context.Context, payment
checkAmount = cloneMoney(providerSettlementAmount)
}
}
gw, err := ensureGatewayForAction(ctx, gateways, gatewaysByRail, tpl.Rail, network, checkAmount, action, instanceID, sendDirectionForRail(tpl.Rail))
gw, err := ensureGatewayForAction(ctx, b.logger, gateways, gatewaysByRail, tpl.Rail, network, checkAmount, action, instanceID, sendDirectionForRail(tpl.Rail))
if err != nil {
logger.Warn("Failed to ensure gateway for plan step", zap.Error(err),
zap.String("step_id", stepID), zap.String("rail", string(tpl.Rail)),
zap.String("gateway_network", network), zap.String("managed_wallet_network", managedWalletNetwork),
zap.Int("gateways_by_rail_count", len(gatewaysByRail)),
)
return nil, err
}
step.GatewayID = strings.TrimSpace(gw.ID)