From 00265d835ff11ef9b2f10408dff431e6f04e281a Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Mon, 21 Sep 2020 16:18:29 -0400 Subject: [PATCH] Record first successful redemption of any voucher, counter pair --- src/PaymentServer/Persistence.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/PaymentServer/Persistence.hs b/src/PaymentServer/Persistence.hs index 0c5ff96..dc499a4 100644 --- a/src/PaymentServer/Persistence.hs +++ b/src/PaymentServer/Persistence.hs @@ -37,6 +37,9 @@ import qualified Database.SQLite.Simple as Sqlite import Database.SQLite.Simple.FromRow ( FromRow(fromRow) ) + +import qualified Prometheus as P + import Data.Maybe ( listToMaybe ) @@ -259,6 +262,7 @@ redeemVoucherHelper isVoucherPaid lookupFingerprint lookupVoucherCounter markVou return $ Left NotPaid (True, Nothing) -> do markVoucherRedeemed (voucher, counter) fingerprint + P.incCounter voucherRedeemed return $ Right () (True, Just fingerprint') -> if fingerprint == fingerprint' then @@ -267,6 +271,18 @@ redeemVoucherHelper isVoucherPaid lookupFingerprint lookupVoucherCounter markVou return $ Left AlreadyRedeemed +metricName :: Text -> Text +metricName name = mappend "redemption." name + + +voucherRedeemed :: P.Counter +voucherRedeemed + = P.unsafeRegister + $ P.counter + $ P.Info (metricName "voucher_redeemed") + "The number of unique (voucher, counter) pairs which have been redeemed." + + -- | Create a new, empty MemoryVoucherDatabase. memory :: IO VoucherDatabaseState memory = do -- GitLab