Skip to content

[billing] Trigger ReconcileInvoices in ledger reconciler #12729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion components/usage/pkg/apiv1/billing_noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type BillingServiceNoop struct {
}

func (s *BillingServiceNoop) UpdateInvoices(_ context.Context, _ *v1.UpdateInvoicesRequest) (*v1.UpdateInvoicesResponse, error) {
log.Log.Infof("UpdateInvoices RPC invoked in no-op mode, no invoices will be updated.")
log.Infof("UpdateInvoices RPC invoked in no-op mode, no invoices will be updated.")
return &v1.UpdateInvoicesResponse{}, nil
}

func (s *BillingServiceNoop) ReconcileInvoices(_ context.Context, _ *v1.ReconcileInvoicesRequest) (*v1.ReconcileInvoicesResponse, error) {
log.Infof("ReconcileInvoices RPC invoked in no-op mode, no invoices will be updated.")
return &v1.ReconcileInvoicesResponse{}, nil
}
15 changes: 12 additions & 3 deletions components/usage/pkg/controller/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ func (r *UsageAndBillingReconciler) Reconcile() (err error) {
return nil
}

func NewLedgerReconciler(usageClient v1.UsageServiceClient) *LedgerReconciler {
func NewLedgerReconciler(usageClient v1.UsageServiceClient, billingClient v1.BillingServiceClient) *LedgerReconciler {
return &LedgerReconciler{
usageClient: usageClient,
usageClient: usageClient,
billingClient: billingClient,
}
}

type LedgerReconciler struct {
usageClient v1.UsageServiceClient
usageClient v1.UsageServiceClient
billingClient v1.BillingServiceClient
}

func (r *LedgerReconciler) Reconcile() error {
Expand All @@ -102,5 +104,12 @@ func (r *LedgerReconciler) Reconcile() error {
return fmt.Errorf("failed to reconcile usage with ledger: %w", err)
}

logger.Info("Starting invoice reconciliation.")
_, err = r.billingClient.ReconcileInvoices(ctx, &v1.ReconcileInvoicesRequest{})
if err != nil {
logger.WithError(err).Errorf("Failed to reconcile invoices.")
return fmt.Errorf("failed to reconcile invoices: %w", err)
}

return nil
}
8 changes: 3 additions & 5 deletions components/usage/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ func Start(cfg Config) error {
}

usageClient := v1.NewUsageServiceClient(selfConnection)
ctrl, err := controller.New(schedule, controller.NewUsageAndBillingReconciler(
usageClient,
v1.NewBillingServiceClient(selfConnection),
))
billingClient := v1.NewBillingServiceClient(selfConnection)
ctrl, err := controller.New(schedule, controller.NewUsageAndBillingReconciler(usageClient, billingClient))
if err != nil {
return fmt.Errorf("failed to initialize usage controller: %w", err)
}
Expand All @@ -128,7 +126,7 @@ func Start(cfg Config) error {
}
defer ctrl.Stop()

ledgerCtrl, err := controller.New(schedule, controller.NewLedgerReconciler(usageClient))
ledgerCtrl, err := controller.New(schedule, controller.NewLedgerReconciler(usageClient, billingClient))
if err != nil {
return fmt.Errorf("failed to initialize ledger controller: %w", err)
}
Expand Down