cli: allow DB stats tracking via environment variable
This commit is contained in:
parent
0ff189d229
commit
40d2aa0c11
@ -53,6 +53,7 @@ import {
|
||||
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
|
||||
import { JsonMessage, runRpcServer } from "@gnu-taler/taler-util/twrpc";
|
||||
import {
|
||||
AccessStats,
|
||||
createNativeWalletHost,
|
||||
createNativeWalletHost2,
|
||||
Wallet,
|
||||
@ -237,16 +238,21 @@ export interface WalletContext {
|
||||
): Promise<T>;
|
||||
}
|
||||
|
||||
interface CreateWalletResult {
|
||||
wallet: Wallet;
|
||||
getStats: () => AccessStats;
|
||||
}
|
||||
|
||||
async function createLocalWallet(
|
||||
walletCliArgs: WalletCliArgsType,
|
||||
notificationHandler?: (n: WalletNotification) => void,
|
||||
): Promise<Wallet> {
|
||||
): Promise<CreateWalletResult> {
|
||||
const dbPath = walletCliArgs.wallet.walletDbFile ?? defaultWalletDbPath;
|
||||
const myHttpLib = createPlatformHttpLib({
|
||||
enableThrottling: walletCliArgs.wallet.noThrottle ? false : true,
|
||||
requireTls: walletCliArgs.wallet.noHttp,
|
||||
});
|
||||
const wallet = await createNativeWalletHost({
|
||||
const wh = await createNativeWalletHost2({
|
||||
persistentStoragePath: dbPath !== ":memory:" ? dbPath : undefined,
|
||||
httpLib: myHttpLib,
|
||||
notifyHandler: (n) => {
|
||||
@ -269,10 +275,10 @@ async function createLocalWallet(
|
||||
|
||||
applyVerbose(walletCliArgs.wallet.verbose);
|
||||
try {
|
||||
await wallet.handleCoreApiRequest("initWallet", "native-init", {
|
||||
await wh.wallet.handleCoreApiRequest("initWallet", "native-init", {
|
||||
skipDefaults: walletCliArgs.wallet.skipDefaults,
|
||||
});
|
||||
return wallet;
|
||||
return { wallet: wh.wallet, getStats: wh.getDbStats };
|
||||
} catch (e) {
|
||||
const ed = getErrorDetailFromException(e);
|
||||
console.error("Operation failed: " + summarizeTalerErrorDetail(ed));
|
||||
@ -307,16 +313,20 @@ async function withWallet<T>(
|
||||
w.close();
|
||||
return res;
|
||||
} else {
|
||||
const w = await createLocalWallet(walletCliArgs, waiter.notify);
|
||||
const wh = await createLocalWallet(walletCliArgs, waiter.notify);
|
||||
const ctx: WalletContext = {
|
||||
client: w.client,
|
||||
client: wh.wallet.client,
|
||||
waitForNotificationCond: waiter.waitForNotificationCond,
|
||||
makeCoreApiRequest(operation, payload) {
|
||||
return w.handleCoreApiRequest(operation, "my-req", payload);
|
||||
return wh.wallet.handleCoreApiRequest(operation, "my-req", payload);
|
||||
},
|
||||
};
|
||||
const result = await f(ctx);
|
||||
w.stop();
|
||||
wh.wallet.stop();
|
||||
if (process.env.TALER_WALLET_DBSTATS) {
|
||||
console.log("database stats:");
|
||||
console.log(j2s(wh.getStats()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -330,7 +340,8 @@ async function withLocalWallet<T>(
|
||||
walletCliArgs: WalletCliArgsType,
|
||||
f: (w: { client: WalletCoreApiClient; ws: Wallet }) => Promise<T>,
|
||||
): Promise<T> {
|
||||
const w = await createLocalWallet(walletCliArgs);
|
||||
const wh = await createLocalWallet(walletCliArgs);
|
||||
const w = wh.wallet;
|
||||
const res = await f({ client: w.client, ws: w });
|
||||
w.stop();
|
||||
return res;
|
||||
@ -1030,8 +1041,7 @@ peerCli
|
||||
const resp = await wallet.client.call(
|
||||
WalletApiOperation.ConfirmPeerPullDebit,
|
||||
{
|
||||
peerPullDebitId:
|
||||
args.confirmIncomingPayPull.peerPullDebitId,
|
||||
peerPullDebitId: args.confirmIncomingPayPull.peerPullDebitId,
|
||||
},
|
||||
);
|
||||
console.log(JSON.stringify(resp, undefined, 2));
|
||||
@ -1046,8 +1056,7 @@ peerCli
|
||||
const resp = await wallet.client.call(
|
||||
WalletApiOperation.ConfirmPeerPushCredit,
|
||||
{
|
||||
peerPushCreditId:
|
||||
args.confirmIncomingPayPush.peerPushCreditId,
|
||||
peerPushCreditId: args.confirmIncomingPayPush.peerPushCreditId,
|
||||
},
|
||||
);
|
||||
console.log(JSON.stringify(resp, undefined, 2));
|
||||
@ -1174,7 +1183,8 @@ advancedCli
|
||||
})
|
||||
.action(async (args) => {
|
||||
logger.info(`serving at ${args.serve.unixPath}`);
|
||||
const w = await createLocalWallet(args);
|
||||
const wh = await createLocalWallet(args);
|
||||
const w = wh.wallet;
|
||||
w.runTaskLoop()
|
||||
.then((res) => {
|
||||
logger.warn("task loop exited unexpectedly");
|
||||
|
@ -108,10 +108,13 @@ async function makeSqliteDb(
|
||||
filename: args.persistentStoragePath ?? ":memory:",
|
||||
});
|
||||
myBackend.enableTracing = false;
|
||||
if (process.env.TALER_WALLET_DBSTATS) {
|
||||
myBackend.trackStats = true;
|
||||
}
|
||||
const myBridgeIdbFactory = new BridgeIDBFactory(myBackend);
|
||||
return {
|
||||
getStats() {
|
||||
throw Error("not implemented");
|
||||
return myBackend.accessStats;
|
||||
},
|
||||
idbFactory: myBridgeIdbFactory,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user