Skip to content

Commit

Permalink
fix: (metrics) remove metrics constant from httpwrapper package
Browse files Browse the repository at this point in the history
  • Loading branch information
laouji committed Jan 2, 2025
1 parent 6850621 commit 664a12f
Show file tree
Hide file tree
Showing 41 changed files with 101 additions and 103 deletions.
2 changes: 0 additions & 2 deletions internal/connectors/httpwrapper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"golang.org/x/oauth2"
)

const MetricOperationContextKey string = "_metric_operation_context_key"

var (
ErrStatusCodeUnexpected = errors.New("unexpected status code")
ErrStatusCodeClientError = fmt.Errorf("%w: http client error", ErrStatusCodeUnexpected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type Balance struct {
Expand Down Expand Up @@ -43,7 +43,7 @@ func (c *client) GetAccounts(ctx context.Context, page int, pageSize int, fromOp
return nil, err
}

ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_accounts")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_accounts")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.endpoint+"/api/v1/accounts", http.NoBody)
if err != nil {
Expand Down Expand Up @@ -80,7 +80,7 @@ func (c *client) GetAccount(ctx context.Context, accountID string) (*Account, er
if err := c.ensureAccessTokenIsValid(ctx); err != nil {
return nil, err
}
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "get_account")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "get_account")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/api/v1/accounts/%s", c.endpoint, accountID), http.NoBody)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"strconv"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

func (c *client) login(ctx context.Context) error {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "authenticate")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "authenticate")

req, err := http.NewRequestWithContext(ctx, http.MethodGet,
c.authorizationEndpoint+"/api/v1/authorizations/authorize", http.NoBody)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type DebtorInformation struct {
Expand Down Expand Up @@ -94,7 +94,7 @@ func (c *client) GetPayments(ctx context.Context, page int, pageSize int) ([]Pay
return nil, err
}

ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_payments")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_payments")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.endpoint+"/api/v1/payments/singles", http.NoBody)
if err != nil {
Expand Down Expand Up @@ -129,7 +129,7 @@ func (c *client) GetPayment(ctx context.Context, paymentID string) (*Payment, er
return nil, err
}

ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "get_payment")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "get_payment")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/api/v1/payments/singles/%s", c.endpoint, paymentID), http.NoBody)
if err != nil {
Expand All @@ -153,7 +153,7 @@ func (c *client) GetPaymentStatus(ctx context.Context, paymentID string) (*Statu
if err := c.ensureAccessTokenIsValid(ctx); err != nil {
return nil, err
}
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "get_payment_status")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "get_payment_status")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/api/v1/payments/singles/%s/status", c.endpoint, paymentID), http.NoBody)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type PaymentAccount struct {
Expand Down Expand Up @@ -38,7 +38,7 @@ func (c *client) InitiateTransferOrPayouts(ctx context.Context, transferRequest
return nil, err
}

ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "create_transfers_payouts")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "create_transfers_payouts")

body, err := json.Marshal(transferRequest)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type Account struct {
Expand All @@ -20,7 +20,7 @@ func (c *client) GetAccounts(ctx context.Context, page int, pageSize int) ([]*Ac
if err := c.ensureLogin(ctx); err != nil {
return nil, 0, err
}
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_accounts")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_accounts")

req, err := http.NewRequestWithContext(ctx, http.MethodPost,
c.buildEndpoint("v2/accounts/find"), http.NoBody)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"net/url"
"strings"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

func (c *client) authenticate(ctx context.Context) error {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "authenticate")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "authenticate")

form := make(url.Values)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type Balance struct {
Expand All @@ -20,7 +20,7 @@ type Balance struct {
}

func (c *client) GetBalances(ctx context.Context, page int, pageSize int) ([]*Balance, int, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_balances")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_balances")

if err := c.ensureLogin(ctx); err != nil {
return nil, 0, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type Beneficiary struct {
Expand All @@ -19,7 +19,7 @@ type Beneficiary struct {
}

func (c *client) GetBeneficiaries(ctx context.Context, page int, pageSize int) ([]*Beneficiary, int, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_beneficiaries")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_beneficiaries")

if err := c.ensureLogin(ctx); err != nil {
return nil, 0, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/url"
"strings"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
"github.com/formancehq/payments/internal/models"
)

Expand All @@ -16,7 +16,7 @@ type Contact struct {
}

func (c *client) GetContactID(ctx context.Context, accountID string) (*Contact, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_contacts")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_contacts")

if err := c.ensureLogin(ctx); err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type PayoutRequest struct {
Expand Down Expand Up @@ -54,7 +54,7 @@ type PayoutResponse struct {
}

func (c *client) InitiatePayout(ctx context.Context, payoutRequest *PayoutRequest) (*PayoutResponse, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "initiate_payout")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "initiate_payout")

if err := c.ensureLogin(ctx); err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

//nolint:tagliatelle // allow different styled tags in client
Expand All @@ -29,7 +29,7 @@ func (c *client) GetTransactions(ctx context.Context, page int, pageSize int, up
return nil, 0, fmt.Errorf("page must be greater than 0")
}

ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_transactions")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_transactions")

if err := c.ensureLogin(ctx); err != nil {
return nil, 0, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type TransferRequest struct {
Expand Down Expand Up @@ -55,7 +55,7 @@ type TransferResponse struct {
}

func (c *client) InitiateTransfer(ctx context.Context, transferRequest *TransferRequest) (*TransferResponse, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "initiate_transfer")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "initiate_transfer")

if err := c.ensureLogin(ctx); err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"

"github.com/formancehq/go-libs/v2/errorsutils"
"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type OwnerAddress struct {
Expand All @@ -33,7 +33,7 @@ type CreateIBANBankAccountRequest struct {
}

func (c *client) CreateIBANBankAccount(ctx context.Context, userID string, req *CreateIBANBankAccountRequest) (*BankAccount, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "create_iban_bank_account")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "create_iban_bank_account")

endpoint := fmt.Sprintf("%s/v2.01/%s/users/%s/bankaccounts/iban", c.endpoint, c.clientID, userID)
return c.createBankAccount(ctx, endpoint, req)
Expand All @@ -49,7 +49,7 @@ type CreateUSBankAccountRequest struct {
}

func (c *client) CreateUSBankAccount(ctx context.Context, userID string, req *CreateUSBankAccountRequest) (*BankAccount, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "create_us_bank_account")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "create_us_bank_account")

endpoint := fmt.Sprintf("%s/v2.01/%s/users/%s/bankaccounts/us", c.endpoint, c.clientID, userID)
return c.createBankAccount(ctx, endpoint, req)
Expand All @@ -66,7 +66,7 @@ type CreateCABankAccountRequest struct {
}

func (c *client) CreateCABankAccount(ctx context.Context, userID string, req *CreateCABankAccountRequest) (*BankAccount, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "create_ca_bank_account")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "create_ca_bank_account")

endpoint := fmt.Sprintf("%s/v2.01/%s/users/%s/bankaccounts/ca", c.endpoint, c.clientID, userID)
return c.createBankAccount(ctx, endpoint, req)
Expand All @@ -81,7 +81,7 @@ type CreateGBBankAccountRequest struct {
}

func (c *client) CreateGBBankAccount(ctx context.Context, userID string, req *CreateGBBankAccountRequest) (*BankAccount, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "create_gb_bank_account")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "create_gb_bank_account")

endpoint := fmt.Sprintf("%s/v2.01/%s/users/%s/bankaccounts/gb", c.endpoint, c.clientID, userID)
return c.createBankAccount(ctx, endpoint, req)
Expand All @@ -97,7 +97,7 @@ type CreateOtherBankAccountRequest struct {
}

func (c *client) CreateOtherBankAccount(ctx context.Context, userID string, req *CreateOtherBankAccountRequest) (*BankAccount, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "create_other_bank_account")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "create_other_bank_account")

endpoint := fmt.Sprintf("%s/v2.01/%s/users/%s/bankaccounts/other", c.endpoint, c.clientID, userID)
return c.createBankAccount(ctx, endpoint, req)
Expand Down Expand Up @@ -130,7 +130,7 @@ type BankAccount struct {
}

func (c *client) GetBankAccounts(ctx context.Context, userID string, page, pageSize int) ([]BankAccount, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_bank_accounts")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_bank_accounts")

endpoint := fmt.Sprintf("%s/v2.01/%s/users/%s/bankaccounts", c.endpoint, c.clientID, userID)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, http.NoBody)
Expand Down
4 changes: 2 additions & 2 deletions internal/connectors/plugins/public/mangopay/client/payin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"

"github.com/formancehq/go-libs/v2/errorsutils"
"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type PayinResponse struct {
Expand All @@ -29,7 +29,7 @@ type PayinResponse struct {
}

func (c *client) GetPayin(ctx context.Context, payinID string) (*PayinResponse, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "get_payin")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "get_payin")

endpoint := fmt.Sprintf("%s/v2.01/%s/payins/%s", c.endpoint, c.clientID, payinID)

Expand Down
6 changes: 3 additions & 3 deletions internal/connectors/plugins/public/mangopay/client/payout.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"

"github.com/formancehq/go-libs/v2/errorsutils"
"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type PayoutRequest struct {
Expand Down Expand Up @@ -45,7 +45,7 @@ type PayoutResponse struct {
}

func (c *client) InitiatePayout(ctx context.Context, payoutRequest *PayoutRequest) (*PayoutResponse, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "initiate_payout")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "initiate_payout")

endpoint := fmt.Sprintf("%s/v2.01/%s/payouts/bankwire", c.endpoint, c.clientID)

Expand All @@ -70,7 +70,7 @@ func (c *client) InitiatePayout(ctx context.Context, payoutRequest *PayoutReques
}

func (c *client) GetPayout(ctx context.Context, payoutID string) (*PayoutResponse, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "get_payout")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "get_payout")

endpoint := fmt.Sprintf("%s/v2.01/%s/payouts/%s", c.endpoint, c.clientID, payoutID)

Expand Down
4 changes: 2 additions & 2 deletions internal/connectors/plugins/public/mangopay/client/refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"

"github.com/formancehq/go-libs/v2/errorsutils"
"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type Refund struct {
Expand All @@ -30,7 +30,7 @@ type Refund struct {
}

func (c *client) GetRefund(ctx context.Context, refundID string) (*Refund, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "get_refund")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "get_refund")

endpoint := fmt.Sprintf("%s/v2.01/%s/refunds/%s", c.endpoint, c.clientID, refundID)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/formancehq/go-libs/v2/errorsutils"
"github.com/formancehq/payments/internal/connectors/httpwrapper"
"github.com/formancehq/payments/internal/connectors/metrics"
)

type Payment struct {
Expand All @@ -31,7 +31,7 @@ type Payment struct {
}

func (c *client) GetTransactions(ctx context.Context, walletsID string, page, pageSize int, afterCreatedAt time.Time) ([]Payment, error) {
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_transactions")
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_transactions")

endpoint := fmt.Sprintf("%s/v2.01/%s/wallets/%s/transactions", c.endpoint, c.clientID, walletsID)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, http.NoBody)
Expand Down
Loading

0 comments on commit 664a12f

Please sign in to comment.