add basic metrics collection logic

This commit is contained in:
Christian Grothoff 2021-12-07 21:16:38 +01:00
parent 8be9de6675
commit 71933dd2e9
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
24 changed files with 63 additions and 16 deletions

View File

@ -216,6 +216,7 @@ TEH_handler_auditors (
return MHD_YES; /* failure */ return MHD_YES; /* failure */
ret = TEH_DB_run_transaction (connection, ret = TEH_DB_run_transaction (connection,
"add auditor denom sig", "add auditor denom sig",
TEH_MT_OTHER,
&res, &res,
&add_auditor_denom_sig, &add_auditor_denom_sig,
&awc); &awc);

View File

@ -24,6 +24,7 @@
#include <gnunet/gnunet_json_lib.h> #include <gnunet/gnunet_json_lib.h>
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include "taler_mhd_lib.h" #include "taler_mhd_lib.h"
#include "taler-exchange-httpd_db.h"
#include "taler-exchange-httpd_responses.h" #include "taler-exchange-httpd_responses.h"
@ -113,25 +114,10 @@ TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
} }
/**
* Run a database transaction for @a connection.
* Starts a transaction and calls @a cb. Upon success,
* attempts to commit the transaction. Upon soft failures,
* retries @a cb a few times. Upon hard or persistent soft
* errors, generates an error message for @a connection.
*
* @param connection MHD connection to run @a cb for, can be NULL
* @param name name of the transaction (for debugging)
* @param[out] mhd_ret set to MHD response code, if transaction failed;
* NULL if we are not running with a @a connection and thus
* must not queue MHD replies
* @param cb callback implementing transaction logic
* @param cb_cls closure for @a cb, must be read-only!
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
enum GNUNET_GenericReturnValue enum GNUNET_GenericReturnValue
TEH_DB_run_transaction (struct MHD_Connection *connection, TEH_DB_run_transaction (struct MHD_Connection *connection,
const char *name, const char *name,
enum TEH_MetricType mt,
MHD_RESULT *mhd_ret, MHD_RESULT *mhd_ret,
TEH_DB_TransactionCallback cb, TEH_DB_TransactionCallback cb,
void *cb_cls) void *cb_cls)
@ -149,6 +135,8 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
NULL); NULL);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
GNUNET_assert (mt < TEH_MT_COUNT);
TEH_METRICS_num_requests[mt]++;
for (unsigned int retries = 0; for (unsigned int retries = 0;
retries < MAX_TRANSACTION_COMMIT_RETRIES; retries < MAX_TRANSACTION_COMMIT_RETRIES;
retries++) retries++)
@ -190,6 +178,7 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
(-1 == (int) *mhd_ret) ); (-1 == (int) *mhd_ret) );
if (0 <= qs) if (0 <= qs)
return GNUNET_OK; return GNUNET_OK;
TEH_METRICS_num_conflict[mt]++;
} }
TALER_LOG_ERROR ("Transaction `%s' commit failed %u times\n", TALER_LOG_ERROR ("Transaction `%s' commit failed %u times\n",
name, name,

View File

@ -23,6 +23,7 @@
#include <microhttpd.h> #include <microhttpd.h>
#include "taler_exchangedb_plugin.h" #include "taler_exchangedb_plugin.h"
#include "taler-exchange-httpd_metrics.h"
#include <gnunet/gnunet_mhd_compat.h> #include <gnunet/gnunet_mhd_compat.h>
@ -69,6 +70,7 @@ typedef enum GNUNET_DB_QueryStatus
* *
* @param connection MHD connection to run @a cb for, can be NULL * @param connection MHD connection to run @a cb for, can be NULL
* @param name name of the transaction (for debugging) * @param name name of the transaction (for debugging)
* @param mt type of the requests, for metric generation
* @param[out] mhd_ret set to MHD response code, if transaction failed (returned #GNUNET_SYSERR); * @param[out] mhd_ret set to MHD response code, if transaction failed (returned #GNUNET_SYSERR);
* NULL if we are not running with a @a connection and thus * NULL if we are not running with a @a connection and thus
* must not queue MHD replies * must not queue MHD replies
@ -79,6 +81,7 @@ typedef enum GNUNET_DB_QueryStatus
enum GNUNET_GenericReturnValue enum GNUNET_GenericReturnValue
TEH_DB_run_transaction (struct MHD_Connection *connection, TEH_DB_run_transaction (struct MHD_Connection *connection,
const char *name, const char *name,
enum TEH_MetricType mt,
MHD_RESULT *mhd_ret, MHD_RESULT *mhd_ret,
TEH_DB_TransactionCallback cb, TEH_DB_TransactionCallback cb,
void *cb_cls); void *cb_cls);

View File

@ -497,6 +497,7 @@ TEH_handler_deposit (struct MHD_Connection *connection,
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (connection, TEH_DB_run_transaction (connection,
"execute deposit", "execute deposit",
TEH_MT_DEPOSIT,
&mhd_ret, &mhd_ret,
&deposit_transaction, &deposit_transaction,
&dc)) &dc))

View File

@ -246,6 +246,7 @@ handle_track_transaction_request (
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (connection, TEH_DB_run_transaction (connection,
"handle deposits GET", "handle deposits GET",
TEH_MT_OTHER,
&mhd_ret, &mhd_ret,
&deposits_get_transaction, &deposits_get_transaction,
&ctx)) &ctx))

View File

@ -351,6 +351,7 @@ TEH_handler_kyc_check (
(void) GNUNET_TIME_round_abs (&now); (void) GNUNET_TIME_round_abs (&now);
ret = TEH_DB_run_transaction (rc->connection, ret = TEH_DB_run_transaction (rc->connection,
"kyc check", "kyc check",
TEH_MT_OTHER,
&res, &res,
&kyc_check, &kyc_check,
kyp); kyp);

View File

@ -678,6 +678,7 @@ TEH_handler_kyc_proof (
ret = TEH_DB_run_transaction (kpc->rc->connection, ret = TEH_DB_run_transaction (kpc->rc->connection,
"check proof kyc", "check proof kyc",
TEH_MT_OTHER,
&res, &res,
&persist_kyc_ok, &persist_kyc_ok,
kpc); kpc);

View File

@ -140,6 +140,7 @@ TEH_handler_kyc_wallet (
0); 0);
ret = TEH_DB_run_transaction (rc->connection, ret = TEH_DB_run_transaction (rc->connection,
"check wallet kyc", "check wallet kyc",
TEH_MT_OTHER,
&res, &res,
&wallet_kyc_check, &wallet_kyc_check,
&krc); &krc);

View File

@ -193,6 +193,7 @@ TEH_handler_link (struct TEH_RequestContext *rc,
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (rc->connection, TEH_DB_run_transaction (rc->connection,
"run link", "run link",
TEH_MT_OTHER,
&mhd_ret, &mhd_ret,
&link_transaction, &link_transaction,
&ctx)) &ctx))

View File

@ -187,6 +187,7 @@ TEH_handler_management_auditors (
ret = TEH_DB_run_transaction (connection, ret = TEH_DB_run_transaction (connection,
"add auditor", "add auditor",
TEH_MT_OTHER,
&res, &res,
&add_auditor, &add_auditor,
&aac); &aac);

View File

@ -176,6 +176,7 @@ TEH_handler_management_auditors_AP_disable (
ret = TEH_DB_run_transaction (connection, ret = TEH_DB_run_transaction (connection,
"del auditor", "del auditor",
TEH_MT_OTHER,
&res, &res,
&del_auditor, &del_auditor,
&dac); &dac);

View File

@ -454,6 +454,7 @@ TEH_handler_management_post_keys (
res = TEH_DB_run_transaction (connection, res = TEH_DB_run_transaction (connection,
"add keys", "add keys",
TEH_MT_OTHER,
&ret, &ret,
&add_keys, &add_keys,
&akc); &akc);

View File

@ -177,6 +177,7 @@ TEH_handler_management_post_wire_disable (
res = TEH_DB_run_transaction (connection, res = TEH_DB_run_transaction (connection,
"del wire", "del wire",
TEH_MT_OTHER,
&ret, &ret,
&del_wire, &del_wire,
&awc); &awc);

View File

@ -212,6 +212,7 @@ TEH_handler_management_post_wire (
res = TEH_DB_run_transaction (connection, res = TEH_DB_run_transaction (connection,
"add wire", "add wire",
TEH_MT_OTHER,
&ret, &ret,
&add_wire, &add_wire,
&awc); &awc);

View File

@ -221,6 +221,7 @@ TEH_handler_management_post_wire_fees (
res = TEH_DB_run_transaction (connection, res = TEH_DB_run_transaction (connection,
"add wire fee", "add wire fee",
TEH_MT_OTHER,
&ret, &ret,
&add_fee, &add_fee,
&afc); &afc);

View File

@ -432,6 +432,7 @@ handle_melt (struct MHD_Connection *connection,
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (connection, TEH_DB_run_transaction (connection,
"run melt", "run melt",
TEH_MT_MELT,
&mhd_ret, &mhd_ret,
&melt_transaction, &melt_transaction,
rmc)) rmc))

View File

@ -29,6 +29,11 @@
#include <jansson.h> #include <jansson.h>
unsigned long long TEH_METRICS_num_requests[TEH_MT_COUNT];
unsigned long long TEH_METRICS_num_conflict[TEH_MT_COUNT];
MHD_RESULT MHD_RESULT
TEH_handler_metrics (struct TEH_RequestContext *rc, TEH_handler_metrics (struct TEH_RequestContext *rc,
const char *const args[]) const char *const args[])

View File

@ -26,6 +26,34 @@
#include "taler-exchange-httpd.h" #include "taler-exchange-httpd.h"
/**
* Request types for which we collect metrics.
*/
enum TEH_MetricType
{
TEH_MT_OTHER = 0,
TEH_MT_DEPOSIT = 1,
TEH_MT_WITHDRAW = 2,
TEH_MT_MELT = 3,
TEH_MT_REVEAL_PRECHECK = 4,
TEH_MT_REVEAL = 5,
TEH_MT_REVEAL_PERSIST = 6,
TEH_MT_COUNT = 7 /* MUST BE LAST! */
};
/**
* Number of requests handled of the respective type.
*/
extern unsigned long long TEH_METRICS_num_requests[TEH_MT_COUNT];
/**
* Number of serialization errors encountered when
* handling requests of the respective type.
*/
extern unsigned long long TEH_METRICS_num_conflict[TEH_MT_COUNT];
/** /**
* Handle a "/metrics" request. * Handle a "/metrics" request.
* *

View File

@ -477,6 +477,7 @@ verify_and_execute_recoup (
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (connection, TEH_DB_run_transaction (connection,
"run recoup", "run recoup",
TEH_MT_OTHER,
&mhd_ret, &mhd_ret,
&recoup_transaction, &recoup_transaction,
&pc)) &pc))

View File

@ -724,6 +724,7 @@ resolve_refreshes_reveal_denominations (struct MHD_Connection *connection,
if ( (GNUNET_OK == if ( (GNUNET_OK ==
TEH_DB_run_transaction (connection, TEH_DB_run_transaction (connection,
"reveal pre-check", "reveal pre-check",
TEH_MT_REVEAL_PRECHECK,
&ret, &ret,
&refreshes_reveal_preflight, &refreshes_reveal_preflight,
rctx)) && rctx)) &&
@ -745,6 +746,7 @@ resolve_refreshes_reveal_denominations (struct MHD_Connection *connection,
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (connection, TEH_DB_run_transaction (connection,
"run reveal", "run reveal",
TEH_MT_REVEAL,
&ret, &ret,
&refreshes_reveal_transaction, &refreshes_reveal_transaction,
rctx)) rctx))
@ -756,6 +758,7 @@ resolve_refreshes_reveal_denominations (struct MHD_Connection *connection,
if (GNUNET_OK == if (GNUNET_OK ==
TEH_DB_run_transaction (connection, TEH_DB_run_transaction (connection,
"persist reveal", "persist reveal",
TEH_MT_REVEAL_PERSIST,
&ret, &ret,
&refreshes_reveal_persist, &refreshes_reveal_persist,
rctx)) rctx))

View File

@ -447,6 +447,7 @@ verify_and_execute_refund (struct MHD_Connection *connection,
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (connection, TEH_DB_run_transaction (connection,
"run refund", "run refund",
TEH_MT_OTHER,
&mhd_ret, &mhd_ret,
&refund_transaction, &refund_transaction,
(void *) refund)) (void *) refund))

View File

@ -315,6 +315,7 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (rc->connection, TEH_DB_run_transaction (rc->connection,
"get reserve history", "get reserve history",
TEH_MT_OTHER,
&mhd_ret, &mhd_ret,
&reserve_history_transaction, &reserve_history_transaction,
&rsc)) &rsc))

View File

@ -515,6 +515,7 @@ TEH_handler_transfers_get (struct TEH_RequestContext *rc,
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (rc->connection, TEH_DB_run_transaction (rc->connection,
"run transfers GET", "run transfers GET",
TEH_MT_OTHER,
&mhd_ret, &mhd_ret,
&get_transfer_deposits, &get_transfer_deposits,
&ctx)) &ctx))

View File

@ -521,6 +521,7 @@ TEH_handler_withdraw (struct TEH_RequestContext *rc,
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (rc->connection, TEH_DB_run_transaction (rc->connection,
"run withdraw", "run withdraw",
TEH_MT_WITHDRAW,
&mhd_ret, &mhd_ret,
&withdraw_transaction, &withdraw_transaction,
&wc)) &wc))