From 91800dd0726999329b8c1e63dabe5d7b44059240 Mon Sep 17 00:00:00 2001 From: pociej Date: Thu, 25 Apr 2024 16:35:14 +0200 Subject: [PATCH] chore: improve debug logs #38 --- backend/src/fastify.ts | 2 +- backend/src/services/file/routes.ts | 1 - backend/src/services/file/service.ts | 13 +++++++------ backend/src/services/payment/service.ts | 4 ---- backend/src/services/user/service.ts | 1 - backend/src/services/yagna/routes.ts | 1 - backend/src/services/yagna/service.ts | 17 ++++++++++++----- backend/src/services/yagna/worker.ts | 5 ----- golem-sdk-task-executor | 2 +- 9 files changed, 21 insertions(+), 25 deletions(-) diff --git a/backend/src/fastify.ts b/backend/src/fastify.ts index 988db9f..7a1682f 100644 --- a/backend/src/fastify.ts +++ b/backend/src/fastify.ts @@ -12,7 +12,7 @@ import { Yagna } from "./services/yagna/routes.js"; export const startupFastifyServer = async (): Promise => { const fastify = Fastify({ - logger: true, + logger: false, }); fastify.register(fastifySensible); diff --git a/backend/src/services/file/routes.ts b/backend/src/services/file/routes.ts index 0567b34..41bb21d 100644 --- a/backend/src/services/file/routes.ts +++ b/backend/src/services/file/routes.ts @@ -46,7 +46,6 @@ export const fileService = fastifyPlugin( if (!deposit) { throw new Error("Cant process file without deposit"); } - console.log("deposit", deposit); container.cradle.fileService.processFile( data?.filename, request.user._id, diff --git a/backend/src/services/file/service.ts b/backend/src/services/file/service.ts index 64b6548..ca4847e 100644 --- a/backend/src/services/file/service.ts +++ b/backend/src/services/file/service.ts @@ -8,6 +8,8 @@ import { Worker } from "../yagna/worker.js"; const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); const DIR_NAME = fileURLToPath(new URL("../../../../temp/", import.meta.url)); +import { debugLog } from "../../utils.js"; + export const fileService = ( GolemSDK: typeof sdk, contractAddress: any @@ -18,8 +20,6 @@ export const fileService = ( processFile: (fileName: string, userId: string, depositId: bigint) => void; init: () => void; } => { - console.log("creating file service", contractAddress); - return { resultStream: new Subject(), workers: {}, @@ -43,12 +43,10 @@ export const fileService = ( } } - console.log("Scanning file on Golem", fileName); - //TODO handle errors and timeouts //but it seems that there was no try to find another one //this is task executor abstraction so it should handle it for me - + debugLog("file", "Scanning file on Golem", fileName); const results = await worker.context ?.beginBatch() .uploadFile(`${DIR_NAME}${fileName}`, `/golem/workdir/${fileName}`) @@ -62,14 +60,17 @@ export const fileService = ( return JSON.parse((results[3].stdout || "null") as string); }, async processFile(fileName: string, userId: string) { + debugLog("file", "Processing file", fileName); const worker = await container.cradle.Yagna.getUserWorker(userId); worker.addFileToQueue(fileName); await worker.isFree(fileName); + debugLog("file", "Worker is free", fileName); worker.setState("busy"); const scanResult = await this.scanFileOnGolem(fileName, worker); + debugLog("file", "Scan result", fileName, scanResult); worker.setState("free"); + if (scanResult) { - console.log("scanResult", scanResult); this.resultStream.next({ result: scanResult.Viruses ? fileStatus.INFECTED : fileStatus.CLEAN, id: fileName, diff --git a/backend/src/services/payment/service.ts b/backend/src/services/payment/service.ts index c5dcde8..ce0e8ec 100644 --- a/backend/src/services/payment/service.ts +++ b/backend/src/services/payment/service.ts @@ -40,9 +40,6 @@ export const paymentService = ( functionName: "getDepositByNonce", args: [BigInt(nonce), user.walletAddress], }); - - console.log("data", data); - console.log("nonce", nonce); if (!data) { throw new Error( `Deposit not found with nonce ${nonce} and funder ${user.walletAddress}` @@ -61,7 +58,6 @@ export const paymentService = ( if (feeRatio < Number(serviceFee)) { documentDeposit.isValid = false; } - console.log("going to add deposit"); userService.addDeposit(userId, documentDeposit); }, }; diff --git a/backend/src/services/user/service.ts b/backend/src/services/user/service.ts index c616f36..ac1b9e8 100644 --- a/backend/src/services/user/service.ts +++ b/backend/src/services/user/service.ts @@ -27,7 +27,6 @@ export const userService: IUserService = { }, //@ts-ignore findById: async (userId: string) => { - console.log("find by id", userId); return userModel.findOne({ _id: userId }); }, //@ts-ignore diff --git a/backend/src/services/yagna/routes.ts b/backend/src/services/yagna/routes.ts index 33534d2..0195845 100644 --- a/backend/src/services/yagna/routes.ts +++ b/backend/src/services/yagna/routes.ts @@ -17,7 +17,6 @@ export const Yagna = fastifyPlugin((fastify: FastifyInstance, opts, done) => { }); } const allocation = await Yagna.getUserAllocation(requestUser._id); - console.log("allocation", allocation); if (!allocation) { reply.code(500).send({ message: "Unable to create allocation", diff --git a/backend/src/services/yagna/service.ts b/backend/src/services/yagna/service.ts index 2209e45..c452d92 100644 --- a/backend/src/services/yagna/service.ts +++ b/backend/src/services/yagna/service.ts @@ -115,7 +115,6 @@ export class Yagna { } releaseAgreement(activityId: string) { - console.log("releasing agreement", activityId); return this.activityService.terminateAgreement(activityId); } @@ -137,6 +136,7 @@ export class Yagna { //task executor creates allocation as well async createExecutor(userId: string) { + debugLog("payments", "creating executor", userId); const userService = container.cradle.userService; const userDeposit = await userService.getCurrentDeposit(userId); @@ -154,7 +154,11 @@ export class Yagna { expirationSec: Number(userDeposit.validTo) - dayjs().unix() - 1000, }; - console.log("crteaing executor", allocation); + //@ts-ignore + if (allocation?.id) { + debugLog("payments", "allocation already exists, reusing", allocation); + } + const executor = await TaskExecutor.create({ package: "pociejewski/clamav:latest", //here I would like to be able to pass SUBNET but i have to do that usiong env @@ -177,6 +181,7 @@ export class Yagna { //task executor creates agreement and activity async getUserWorker(userId: string): Promise { + debugLog("payments", "getting user worker", userId); return new Promise(async (resolve, reject) => { const worker = this.userContext.getWorker(userId); if (worker) { @@ -214,6 +219,11 @@ export class Yagna { newWorker.context = ctx; newWorker.setState("free"); + debugLog( + "payments", + "worker connected, agreement done", + ctx.activity.agreement.id + ); container.cradle.userService.setCurrentActivityId( userId, ctx.activity.agreement.id @@ -252,10 +262,8 @@ export class Yagna { ); debitNoteEvents.forEach((event: any) => { - console.log("debit note event", event); const debitNoteId = event.debitNoteId; const debitNote = this.paymentService.getDebitNote(debitNoteId); - console.log("debit note", debitNote); this.debitNoteEvents.next(debitNote); this.lastDebitNoteEventTimestamp = event.eventDate; }); @@ -271,7 +279,6 @@ export class Yagna { ); invoiceEvents.forEach((event: any) => { - console.log("invoice event", event); this.debitNoteEvents.next(event); this.lastInvoiceEventTimestamp = event.eventDate; }); diff --git a/backend/src/services/yagna/worker.ts b/backend/src/services/yagna/worker.ts index 3a60bd3..5ff5574 100644 --- a/backend/src/services/yagna/worker.ts +++ b/backend/src/services/yagna/worker.ts @@ -45,8 +45,6 @@ export class Worker { const subscription = this.state$.subscribe((state) => { const isFirstInQueue = this.queue[this.queue.length - 1] === fileId; if (state === "free" && isFirstInQueue) { - console.log("Worker is free now"); - // subscription.unsubscribe(); resolve(); } }); @@ -56,10 +54,7 @@ export class Worker { return new Promise((resolve) => { const subscription = this.state$.subscribe(async (state) => { if (state !== "connecting") { - console.log("Worker is connected now"); - // subscription.unsubscribe(); const state = await this.context?.getState(); - console.log("state", state); resolve(ActivityStateEnum.Ready === state); } }); diff --git a/golem-sdk-task-executor b/golem-sdk-task-executor index a211b28..6f94d3f 160000 --- a/golem-sdk-task-executor +++ b/golem-sdk-task-executor @@ -1 +1 @@ -Subproject commit a211b28765174f2f0f1a75d23caa3e5df03a167c +Subproject commit 6f94d3f6b82439ab00e0b4c2e245392efb4fd2d8