chore(logging): purchases logging (#567)

This commit is contained in:
Adam Uhlíř 2023-10-19 10:12:49 +02:00 committed by GitHub
parent 5b30bfd427
commit c28627d16f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 44 additions and 13 deletions

View File

@ -12,7 +12,7 @@ import ./marketplace
export market export market
logScope: logScope:
topics = "marketplace onchain market" topics = "marketplace onchain market"
type type
OnChainMarket* = ref object of Market OnChainMarket* = ref object of Market

View File

@ -1,10 +1,14 @@
import pkg/metrics import pkg/metrics
import pkg/chronicles
import ../statemachine import ../statemachine
import ./errorhandling import ./errorhandling
import ./error import ./error
declareCounter(codexPurchasesCancelled, "codex purchases cancelled") declareCounter(codexPurchasesCancelled, "codex purchases cancelled")
logScope:
topics = "marketplace purchases cancelled"
type PurchaseCancelled* = ref object of ErrorHandlingState type PurchaseCancelled* = ref object of ErrorHandlingState
method `$`*(state: PurchaseCancelled): string = method `$`*(state: PurchaseCancelled): string =
@ -13,6 +17,9 @@ method `$`*(state: PurchaseCancelled): string =
method run*(state: PurchaseCancelled, machine: Machine): Future[?State] {.async.} = method run*(state: PurchaseCancelled, machine: Machine): Future[?State] {.async.} =
codexPurchasesCancelled.inc() codexPurchasesCancelled.inc()
let purchase = Purchase(machine) let purchase = Purchase(machine)
warn "Request cancelled, withdrawing remaining funds", requestId = $purchase.requestId
await purchase.market.withdrawFunds(purchase.requestId) await purchase.market.withdrawFunds(purchase.requestId)
let error = newException(Timeout, "Purchase cancelled due to timeout") let error = newException(Timeout, "Purchase cancelled due to timeout")
return some State(PurchaseErrored(error: error)) return some State(PurchaseErrored(error: error))

View File

@ -1,8 +1,13 @@
import pkg/metrics import pkg/metrics
import pkg/chronicles
import ../statemachine import ../statemachine
import ../../utils/exceptions
declareCounter(codexPurchasesError, "codex purchases error") declareCounter(codexPurchasesError, "codex purchases error")
logScope:
topics = "marketplace purchases errored"
type PurchaseErrored* = ref object of PurchaseState type PurchaseErrored* = ref object of PurchaseState
error*: ref CatchableError error*: ref CatchableError
@ -12,4 +17,7 @@ method `$`*(state: PurchaseErrored): string =
method run*(state: PurchaseErrored, machine: Machine): Future[?State] {.async.} = method run*(state: PurchaseErrored, machine: Machine): Future[?State] {.async.} =
codexPurchasesError.inc() codexPurchasesError.inc()
let purchase = Purchase(machine) let purchase = Purchase(machine)
error "Purchasing error", error=state.error.msgDetail, requestId = purchase.requestId
purchase.future.fail(state.error) purchase.future.fail(state.error)

View File

@ -1,8 +1,12 @@
import pkg/metrics import pkg/metrics
import pkg/chronicles
import ../statemachine import ../statemachine
declareCounter(codexPurchasesFinished, "codex purchases finished") declareCounter(codexPurchasesFinished, "codex purchases finished")
logScope:
topics = "marketplace purchases finished"
type PurchaseFinished* = ref object of PurchaseState type PurchaseFinished* = ref object of PurchaseState
method `$`*(state: PurchaseFinished): string = method `$`*(state: PurchaseFinished): string =
@ -11,4 +15,5 @@ method `$`*(state: PurchaseFinished): string =
method run*(state: PurchaseFinished, machine: Machine): Future[?State] {.async.} = method run*(state: PurchaseFinished, machine: Machine): Future[?State] {.async.} =
codexPurchasesFinished.inc() codexPurchasesFinished.inc()
let purchase = Purchase(machine) let purchase = Purchase(machine)
info "Purchase finished", requestId = purchase.requestId
purchase.future.complete() purchase.future.complete()

View File

@ -1,4 +1,5 @@
import pkg/metrics import pkg/metrics
import pkg/chronicles
import ../statemachine import ../statemachine
import ./errorhandling import ./errorhandling
import ./finished import ./finished
@ -6,6 +7,9 @@ import ./failed
declareCounter(codexPurchasesStarted, "codex purchases started") declareCounter(codexPurchasesStarted, "codex purchases started")
logScope:
topics = "marketplace purchases started"
type PurchaseStarted* = ref object of ErrorHandlingState type PurchaseStarted* = ref object of ErrorHandlingState
method `$`*(state: PurchaseStarted): string = method `$`*(state: PurchaseStarted): string =
@ -17,6 +21,7 @@ method run*(state: PurchaseStarted, machine: Machine): Future[?State] {.async.}
let clock = purchase.clock let clock = purchase.clock
let market = purchase.market let market = purchase.market
info "All required slots filled, purchase started", requestId = purchase.requestId
let failed = newFuture[void]() let failed = newFuture[void]()
proc callback(_: RequestId) = proc callback(_: RequestId) =

View File

@ -1,9 +1,13 @@
import pkg/metrics import pkg/metrics
import pkg/chronicles
import ../statemachine import ../statemachine
import ./errorhandling import ./errorhandling
import ./started import ./started
import ./cancelled import ./cancelled
logScope:
topics = "marketplace purchases submitted"
declareCounter(codexPurchasesSubmitted, "codex purchases submitted") declareCounter(codexPurchasesSubmitted, "codex purchases submitted")
type PurchaseSubmitted* = ref object of ErrorHandlingState type PurchaseSubmitted* = ref object of ErrorHandlingState
@ -18,6 +22,8 @@ method run*(state: PurchaseSubmitted, machine: Machine): Future[?State] {.async.
let market = purchase.market let market = purchase.market
let clock = purchase.clock let clock = purchase.clock
info "Request submitted, waiting for slots to be filled", requestId = purchase.requestId
proc wait {.async.} = proc wait {.async.} =
let done = newFuture[void]() let done = newFuture[void]()
proc callback(_: RequestId) = proc callback(_: RequestId) =

View File

@ -4,7 +4,7 @@ import ./errorhandling
import ./errored import ./errored
logScope: logScope:
topics = "marketplace sales cancelled" topics = "marketplace sales cancelled"
type type
SaleCancelled* = ref object of ErrorHandlingState SaleCancelled* = ref object of ErrorHandlingState

View File

@ -7,7 +7,7 @@ import ../salesagent
import ../../utils/exceptions import ../../utils/exceptions
logScope: logScope:
topics = "marketplace sales errored" topics = "marketplace sales errored"
type SaleErrored* = ref object of SaleState type SaleErrored* = ref object of SaleState
error*: ref CatchableError error*: ref CatchableError

View File

@ -4,7 +4,7 @@ import ./errorhandling
import ./errored import ./errored
logScope: logScope:
topics = "marketplace sales failed" topics = "marketplace sales failed"
type type
SaleFailed* = ref object of ErrorHandlingState SaleFailed* = ref object of ErrorHandlingState

View File

@ -11,7 +11,7 @@ import ./proving
import ./provingsimulated import ./provingsimulated
logScope: logScope:
topics = "marketplace sales filled" topics = "marketplace sales filled"
type type
SaleFilled* = ref object of ErrorHandlingState SaleFilled* = ref object of ErrorHandlingState

View File

@ -8,7 +8,7 @@ import ./cancelled
import ./failed import ./failed
logScope: logScope:
topics = "marketplace sales filling" topics = "marketplace sales filling"
type type
SaleFilling* = ref object of ErrorHandlingState SaleFilling* = ref object of ErrorHandlingState

View File

@ -7,7 +7,7 @@ import ./cancelled
import ./failed import ./failed
logScope: logScope:
topics = "marketplace sales finished" topics = "marketplace sales finished"
type type
SaleFinished* = ref object of ErrorHandlingState SaleFinished* = ref object of ErrorHandlingState

View File

@ -5,7 +5,7 @@ import ../salesagent
import ./errorhandling import ./errorhandling
logScope: logScope:
topics = "marketplace sales ignored" topics = "marketplace sales ignored"
type type
SaleIgnored* = ref object of ErrorHandlingState SaleIgnored* = ref object of ErrorHandlingState

View File

@ -7,7 +7,7 @@ import ./cancelled
import ./failed import ./failed
logScope: logScope:
topics = "marketplace sales initial-proving" topics = "marketplace sales initial-proving"
type type
SaleInitialProving* = ref object of ErrorHandlingState SaleInitialProving* = ref object of ErrorHandlingState

View File

@ -8,7 +8,7 @@ import ./failed
import ./finished import ./finished
logScope: logScope:
topics = "marketplace sales payout" topics = "marketplace sales payout"
type type
SalePayout* = ref object of ErrorHandlingState SalePayout* = ref object of ErrorHandlingState

View File

@ -16,7 +16,7 @@ type
SalePreparing* = ref object of ErrorHandlingState SalePreparing* = ref object of ErrorHandlingState
logScope: logScope:
topics = "marketplace sales preparing" topics = "marketplace sales preparing"
method `$`*(state: SalePreparing): string = "SalePreparing" method `$`*(state: SalePreparing): string = "SalePreparing"

View File

@ -11,7 +11,7 @@ import ./errored
import ./payout import ./payout
logScope: logScope:
topics = "marketplace sales proving" topics = "marketplace sales proving"
type type
SlotNotFilledError* = object of CatchableError SlotNotFilledError* = object of CatchableError

View File

@ -9,7 +9,7 @@ import ./cancelled
import ./payout import ./payout
logScope: logScope:
topics = "marketplace sales unknown" topics = "marketplace sales unknown"
type type
SaleUnknown* = ref object of SaleState SaleUnknown* = ref object of SaleState