Skip to content

Commit

Permalink
fix: add data fetcher debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
vasyl-ivanchuk committed Feb 7, 2024
1 parent 0c6232a commit c0070cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/data-fetcher/src/block/block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class BlockService {
public async getData(blockNumber: number): Promise<BlockData | null> {
const stopDurationMeasuring = this.processingDurationMetric.startTimer();

this.logger.debug({ message: "Getting block from the blockchain", blockNumber });
this.logger.debug({ message: "Getting block data from the blockchain", blockNumber });
const stopGetBlockInfoDurationMetric = this.getBlockInfoDurationMetric.startTimer();
const [block, blockDetails] = await Promise.all([
this.blockchainService.getBlock(blockNumber),
Expand Down Expand Up @@ -90,6 +90,7 @@ export class BlockService {
stopDurationMeasuring({ status: blockProcessingStatus, action: "get" });
}

this.logger.debug({ message: "Successfully generated block data", blockNumber });
return {
block,
blockDetails,
Expand Down
7 changes: 7 additions & 0 deletions packages/data-fetcher/src/health/health.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ describe("HealthController", () => {
});
});
});

describe("onApplicationShutdown", () => {
it("defined and returns void", async () => {
const result = healthController.onApplicationShutdown();
expect(result).toBeUndefined();
});
});
});
14 changes: 11 additions & 3 deletions packages/data-fetcher/src/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Logger, Controller, Get } from "@nestjs/common";
import { Logger, Controller, Get, OnApplicationShutdown } from "@nestjs/common";
import { HealthCheckService, HealthCheck, HealthCheckResult } from "@nestjs/terminus";
import { JsonRpcHealthIndicator } from "./jsonRpcProvider.health";

@Controller(["health", "ready"])
export class HealthController {
export class HealthController implements OnApplicationShutdown {
private readonly logger: Logger;

constructor(
Expand All @@ -17,10 +17,18 @@ export class HealthController {
@HealthCheck()
public async check(): Promise<HealthCheckResult> {
try {
return await this.healthCheckService.check([() => this.jsonRpcHealthIndicator.isHealthy("jsonRpcProvider")]);
const healthCheckResult = await this.healthCheckService.check([
() => this.jsonRpcHealthIndicator.isHealthy("jsonRpcProvider"),
]);
this.logger.debug({ message: "Health check result", ...healthCheckResult });
return healthCheckResult;
} catch (error) {
this.logger.error({ message: error.message, response: error.getResponse() }, error.stack);
throw error;
}
}

onApplicationShutdown(signal?: string): void {
this.logger.debug({ message: "Received a signal", signal });
}
}

0 comments on commit c0070cc

Please sign in to comment.