add basic metrics collection logic
This commit is contained in:
parent
8be9de6675
commit
71933dd2e9
@ -216,6 +216,7 @@ TEH_handler_auditors (
|
||||
return MHD_YES; /* failure */
|
||||
ret = TEH_DB_run_transaction (connection,
|
||||
"add auditor denom sig",
|
||||
TEH_MT_OTHER,
|
||||
&res,
|
||||
&add_auditor_denom_sig,
|
||||
&awc);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <gnunet/gnunet_json_lib.h>
|
||||
#include "taler_json_lib.h"
|
||||
#include "taler_mhd_lib.h"
|
||||
#include "taler-exchange-httpd_db.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
|
||||
TEH_DB_run_transaction (struct MHD_Connection *connection,
|
||||
const char *name,
|
||||
enum TEH_MetricType mt,
|
||||
MHD_RESULT *mhd_ret,
|
||||
TEH_DB_TransactionCallback cb,
|
||||
void *cb_cls)
|
||||
@ -149,6 +135,8 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
|
||||
NULL);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
GNUNET_assert (mt < TEH_MT_COUNT);
|
||||
TEH_METRICS_num_requests[mt]++;
|
||||
for (unsigned int retries = 0;
|
||||
retries < MAX_TRANSACTION_COMMIT_RETRIES;
|
||||
retries++)
|
||||
@ -190,6 +178,7 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
|
||||
(-1 == (int) *mhd_ret) );
|
||||
if (0 <= qs)
|
||||
return GNUNET_OK;
|
||||
TEH_METRICS_num_conflict[mt]++;
|
||||
}
|
||||
TALER_LOG_ERROR ("Transaction `%s' commit failed %u times\n",
|
||||
name,
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include <microhttpd.h>
|
||||
#include "taler_exchangedb_plugin.h"
|
||||
#include "taler-exchange-httpd_metrics.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 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);
|
||||
* NULL if we are not running with a @a connection and thus
|
||||
* must not queue MHD replies
|
||||
@ -79,6 +81,7 @@ typedef enum GNUNET_DB_QueryStatus
|
||||
enum GNUNET_GenericReturnValue
|
||||
TEH_DB_run_transaction (struct MHD_Connection *connection,
|
||||
const char *name,
|
||||
enum TEH_MetricType mt,
|
||||
MHD_RESULT *mhd_ret,
|
||||
TEH_DB_TransactionCallback cb,
|
||||
void *cb_cls);
|
||||
|
@ -497,6 +497,7 @@ TEH_handler_deposit (struct MHD_Connection *connection,
|
||||
if (GNUNET_OK !=
|
||||
TEH_DB_run_transaction (connection,
|
||||
"execute deposit",
|
||||
TEH_MT_DEPOSIT,
|
||||
&mhd_ret,
|
||||
&deposit_transaction,
|
||||
&dc))
|
||||
|
@ -246,6 +246,7 @@ handle_track_transaction_request (
|
||||
if (GNUNET_OK !=
|
||||
TEH_DB_run_transaction (connection,
|
||||
"handle deposits GET",
|
||||
TEH_MT_OTHER,
|
||||
&mhd_ret,
|
||||
&deposits_get_transaction,
|
||||
&ctx))
|
||||
|
@ -351,6 +351,7 @@ TEH_handler_kyc_check (
|
||||
(void) GNUNET_TIME_round_abs (&now);
|
||||
ret = TEH_DB_run_transaction (rc->connection,
|
||||
"kyc check",
|
||||
TEH_MT_OTHER,
|
||||
&res,
|
||||
&kyc_check,
|
||||
kyp);
|
||||
|
@ -678,6 +678,7 @@ TEH_handler_kyc_proof (
|
||||
|
||||
ret = TEH_DB_run_transaction (kpc->rc->connection,
|
||||
"check proof kyc",
|
||||
TEH_MT_OTHER,
|
||||
&res,
|
||||
&persist_kyc_ok,
|
||||
kpc);
|
||||
|
@ -140,6 +140,7 @@ TEH_handler_kyc_wallet (
|
||||
0);
|
||||
ret = TEH_DB_run_transaction (rc->connection,
|
||||
"check wallet kyc",
|
||||
TEH_MT_OTHER,
|
||||
&res,
|
||||
&wallet_kyc_check,
|
||||
&krc);
|
||||
|
@ -193,6 +193,7 @@ TEH_handler_link (struct TEH_RequestContext *rc,
|
||||
if (GNUNET_OK !=
|
||||
TEH_DB_run_transaction (rc->connection,
|
||||
"run link",
|
||||
TEH_MT_OTHER,
|
||||
&mhd_ret,
|
||||
&link_transaction,
|
||||
&ctx))
|
||||
|
@ -187,6 +187,7 @@ TEH_handler_management_auditors (
|
||||
|
||||
ret = TEH_DB_run_transaction (connection,
|
||||
"add auditor",
|
||||
TEH_MT_OTHER,
|
||||
&res,
|
||||
&add_auditor,
|
||||
&aac);
|
||||
|
@ -176,6 +176,7 @@ TEH_handler_management_auditors_AP_disable (
|
||||
|
||||
ret = TEH_DB_run_transaction (connection,
|
||||
"del auditor",
|
||||
TEH_MT_OTHER,
|
||||
&res,
|
||||
&del_auditor,
|
||||
&dac);
|
||||
|
@ -454,6 +454,7 @@ TEH_handler_management_post_keys (
|
||||
|
||||
res = TEH_DB_run_transaction (connection,
|
||||
"add keys",
|
||||
TEH_MT_OTHER,
|
||||
&ret,
|
||||
&add_keys,
|
||||
&akc);
|
||||
|
@ -177,6 +177,7 @@ TEH_handler_management_post_wire_disable (
|
||||
|
||||
res = TEH_DB_run_transaction (connection,
|
||||
"del wire",
|
||||
TEH_MT_OTHER,
|
||||
&ret,
|
||||
&del_wire,
|
||||
&awc);
|
||||
|
@ -212,6 +212,7 @@ TEH_handler_management_post_wire (
|
||||
|
||||
res = TEH_DB_run_transaction (connection,
|
||||
"add wire",
|
||||
TEH_MT_OTHER,
|
||||
&ret,
|
||||
&add_wire,
|
||||
&awc);
|
||||
|
@ -221,6 +221,7 @@ TEH_handler_management_post_wire_fees (
|
||||
|
||||
res = TEH_DB_run_transaction (connection,
|
||||
"add wire fee",
|
||||
TEH_MT_OTHER,
|
||||
&ret,
|
||||
&add_fee,
|
||||
&afc);
|
||||
|
@ -432,6 +432,7 @@ handle_melt (struct MHD_Connection *connection,
|
||||
if (GNUNET_OK !=
|
||||
TEH_DB_run_transaction (connection,
|
||||
"run melt",
|
||||
TEH_MT_MELT,
|
||||
&mhd_ret,
|
||||
&melt_transaction,
|
||||
rmc))
|
||||
|
@ -29,6 +29,11 @@
|
||||
#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
|
||||
TEH_handler_metrics (struct TEH_RequestContext *rc,
|
||||
const char *const args[])
|
||||
|
@ -26,6 +26,34 @@
|
||||
#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.
|
||||
*
|
||||
|
@ -477,6 +477,7 @@ verify_and_execute_recoup (
|
||||
if (GNUNET_OK !=
|
||||
TEH_DB_run_transaction (connection,
|
||||
"run recoup",
|
||||
TEH_MT_OTHER,
|
||||
&mhd_ret,
|
||||
&recoup_transaction,
|
||||
&pc))
|
||||
|
@ -724,6 +724,7 @@ resolve_refreshes_reveal_denominations (struct MHD_Connection *connection,
|
||||
if ( (GNUNET_OK ==
|
||||
TEH_DB_run_transaction (connection,
|
||||
"reveal pre-check",
|
||||
TEH_MT_REVEAL_PRECHECK,
|
||||
&ret,
|
||||
&refreshes_reveal_preflight,
|
||||
rctx)) &&
|
||||
@ -745,6 +746,7 @@ resolve_refreshes_reveal_denominations (struct MHD_Connection *connection,
|
||||
if (GNUNET_OK !=
|
||||
TEH_DB_run_transaction (connection,
|
||||
"run reveal",
|
||||
TEH_MT_REVEAL,
|
||||
&ret,
|
||||
&refreshes_reveal_transaction,
|
||||
rctx))
|
||||
@ -756,6 +758,7 @@ resolve_refreshes_reveal_denominations (struct MHD_Connection *connection,
|
||||
if (GNUNET_OK ==
|
||||
TEH_DB_run_transaction (connection,
|
||||
"persist reveal",
|
||||
TEH_MT_REVEAL_PERSIST,
|
||||
&ret,
|
||||
&refreshes_reveal_persist,
|
||||
rctx))
|
||||
|
@ -447,6 +447,7 @@ verify_and_execute_refund (struct MHD_Connection *connection,
|
||||
if (GNUNET_OK !=
|
||||
TEH_DB_run_transaction (connection,
|
||||
"run refund",
|
||||
TEH_MT_OTHER,
|
||||
&mhd_ret,
|
||||
&refund_transaction,
|
||||
(void *) refund))
|
||||
|
@ -315,6 +315,7 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
|
||||
if (GNUNET_OK !=
|
||||
TEH_DB_run_transaction (rc->connection,
|
||||
"get reserve history",
|
||||
TEH_MT_OTHER,
|
||||
&mhd_ret,
|
||||
&reserve_history_transaction,
|
||||
&rsc))
|
||||
|
@ -515,6 +515,7 @@ TEH_handler_transfers_get (struct TEH_RequestContext *rc,
|
||||
if (GNUNET_OK !=
|
||||
TEH_DB_run_transaction (rc->connection,
|
||||
"run transfers GET",
|
||||
TEH_MT_OTHER,
|
||||
&mhd_ret,
|
||||
&get_transfer_deposits,
|
||||
&ctx))
|
||||
|
@ -521,6 +521,7 @@ TEH_handler_withdraw (struct TEH_RequestContext *rc,
|
||||
if (GNUNET_OK !=
|
||||
TEH_DB_run_transaction (rc->connection,
|
||||
"run withdraw",
|
||||
TEH_MT_WITHDRAW,
|
||||
&mhd_ret,
|
||||
&withdraw_transaction,
|
||||
&wc))
|
||||
|
Loading…
Reference in New Issue
Block a user