diff --git a/.env.example b/.env.example index 856d0a00..485185bc 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,7 @@ VALIDATOR_URL=http://your-VC-ip:5062 API_TOKEN=get-it-from-'.lighthouse/validators/api-token.txt' SESSION_PASSWORD=default-siren-password SSL_ENABLED=true +DEBUG=false # don't change these when building the docker image, only change when running outside of docker PORT=3000 BACKEND_URL=http://127.0.0.1:3001 diff --git a/app/api/authenticate/route.ts b/app/api/authenticate/route.ts index 449c68cb..b8e13496 100644 --- a/app/api/authenticate/route.ts +++ b/app/api/authenticate/route.ts @@ -8,8 +8,6 @@ export async function POST(req: Request) { const {password} = await req.json(); const res = await axios.post(`${backendUrl}/authenticate`, {password}); - console.log(res) - if(!res?.data) { return NextResponse.json({ error: 'authPrompt.unableToReach' }, { status: 500 }) } diff --git a/backend/src/beacon/beacon.service.ts b/backend/src/beacon/beacon.service.ts index 8b54eaf5..bc625aa0 100644 --- a/backend/src/beacon/beacon.service.ts +++ b/backend/src/beacon/beacon.service.ts @@ -17,6 +17,7 @@ export class BeaconService { private utilsService: UtilsService ) {} private beaconUrl = process.env.BEACON_URL; + private isDebug = process.env.DEBUG === 'true'; async fetchBeaconNodeVersion(): Promise { try { @@ -113,7 +114,9 @@ export class BeaconService { url: `${this.beaconUrl}/eth/v1/node/syncing`, }); - console.log(`fetching 2nd syncData from node for ${api}.....`) + if(this.isDebug) { + console.log(`fetching 2nd syncData from node for ${api}.....`) + } syncData = { beaconSync: { @@ -121,7 +124,9 @@ export class BeaconService { } } } else { - console.log(`fetching cached syncData for ${api}.....`) + if(this.isDebug) { + console.log(`fetching cached syncData for ${api}.....`) + } } return syncData.beaconSync.headSlot; diff --git a/backend/src/database/database.config.ts b/backend/src/database/database.config.ts index ac6414ca..0b56c84e 100644 --- a/backend/src/database/database.config.ts +++ b/backend/src/database/database.config.ts @@ -5,4 +5,5 @@ export const dataBaseConfig: SequelizeModuleOptions = { storage: '.db/data.sqlite3', autoLoadModels: true, synchronize: true, + logging: false, }; \ No newline at end of file diff --git a/backend/src/logs/logs.service.ts b/backend/src/logs/logs.service.ts index 8595fe84..9460b8f4 100644 --- a/backend/src/logs/logs.service.ts +++ b/backend/src/logs/logs.service.ts @@ -14,6 +14,8 @@ export class LogsService { private logRepository: typeof Log ) {} + private isDebug = process.env.DEBUG === 'true'; + private logTypes = [LogType.BEACON, LogType.VALIDATOR]; private sseStreams: Map> = new Map(); @@ -39,7 +41,9 @@ export class LogsService { if(level !== LogLevels.INFO) { this.logRepository.create({type, level, data: JSON.stringify(newData), isHidden: false}, {ignoreDuplicates: true}) - console.log(newData, type,'------------------------------------------ log --------------------------------------') + if(this.isDebug) { + console.log(newData, type,'------------------------------------------ log --------------------------------------') + } } sseStream.next(event.data); diff --git a/backend/src/tasks/tasks.service.ts b/backend/src/tasks/tasks.service.ts index 5f0c5824..6bf3403e 100644 --- a/backend/src/tasks/tasks.service.ts +++ b/backend/src/tasks/tasks.service.ts @@ -41,6 +41,7 @@ export class TasksService implements OnApplicationBootstrap { private validatorUrl = process.env.VALIDATOR_URL; private apiToken = process.env.API_TOKEN; private sessionPassword = process.env.SESSION_PASSWORD; + private isDebug = process.env.DEBUG === 'true'; async onApplicationBootstrap(): Promise { try { @@ -73,7 +74,9 @@ export class TasksService implements OnApplicationBootstrap { private initLogCleaningScheduler() { this.setDynamicInterval('clean-logs', 60000, async () => { - console.log('cleaning logs database....') + if(this.isDebug) { + console.log('cleaning logs database....') + } const thresholdDate = moment().subtract(24, 'hours').toDate(); await this.logRepository.destroy({ @@ -89,7 +92,9 @@ export class TasksService implements OnApplicationBootstrap { private async initMetricsCleaningScheduler() { const interval = await this.utilsService.getEpochInterval(1) this.setDynamicInterval('clean-metrics', interval / 2, async () => { - console.log('cleaning metric database....') + if(this.isDebug) { + console.log('cleaning metric database....') + } const { SLOTS_PER_EPOCH, SECONDS_PER_SLOT} = await this.cacheManager.get('specs') as BeaconNodeSpecResults const secondsPerEpoch = (Number(SLOTS_PER_EPOCH) * Number(SECONDS_PER_SLOT)) @@ -145,7 +150,9 @@ export class TasksService implements OnApplicationBootstrap { } private async syncValidatorData() { - console.log('Syncing validator data...') + if(this.isDebug) { + console.log('Syncing validator data...') + } const { data } = await this.utilsService.sendHttpRequest({ url: `${this.validatorUrl}/lighthouse/validators`, diff --git a/backend/src/utils/utils.service.ts b/backend/src/utils/utils.service.ts index 40eac2c9..d38406d9 100644 --- a/backend/src/utils/utils.service.ts +++ b/backend/src/utils/utils.service.ts @@ -18,8 +18,9 @@ export class UtilsService { private httpService: HttpService ) {} + private isDebug = process.env.DEBUG === 'true'; + getErrorMessage(code: string | number): string { - console.log(code) if(code === 'ECONNREFUSED') { return 'Unable to connect to Beacon and Validator endpoints...' } @@ -89,7 +90,9 @@ export class UtilsService { const cachedData = await this.cacheManager.get(key) if(cachedData) { - console.log(`fetching from CACHE, key: ${key}....`) + if(this.isDebug) { + console.log(`fetching from CACHE, key: ${key}....`) + } return cachedData } @@ -97,7 +100,9 @@ export class UtilsService { await this.cacheManager.set(key, data, ttl) - console.log(`fetching from NODE, key: ${key} ......`) + if(this.isDebug) { + console.log(`fetching from NODE, key: ${key} ......`) + } return data } diff --git a/backend/src/validator/validator.service.ts b/backend/src/validator/validator.service.ts index 266f1622..f412f78d 100644 --- a/backend/src/validator/validator.service.ts +++ b/backend/src/validator/validator.service.ts @@ -132,7 +132,6 @@ export class ValidatorService { try { const options = index ? {where: {index}} : undefined const metrics = await this.utilsService.fetchAll(Metric, options) - console.log(metrics) const metricsData = metrics.map(metric => JSON.parse(metric.data)) const targetEffectiveness = getAverageKeyValue(metricsData, 'attestation_target_hit_percentage') diff --git a/docker-assets/docker-entrypoint.sh b/docker-assets/docker-entrypoint.sh index 52de1c8f..e9550017 100755 --- a/docker-assets/docker-entrypoint.sh +++ b/docker-assets/docker-entrypoint.sh @@ -9,6 +9,7 @@ VALIDATOR_URL=${VALIDATOR_URL:-http://your-VC-ip:5062} API_TOKEN=${API_TOKEN:-"get-it-from-'.lighthouse/validators/api-token.txt'"} SESSION_PASSWORD=${SESSION_PASSWORD:-default-siren-password} SSL_ENABLED=${SSL_ENABLED:-true} +DEBUG=${DEBUG:-false} set +a # if bn/vc api unreachable, print message and exit diff --git a/siren.js b/siren.js index 2458d8c4..974ddd11 100644 --- a/siren.js +++ b/siren.js @@ -52,7 +52,6 @@ const handleSSe = (res, req, url) => { } req.on('close', () => { - console.error('Request closed...') clearInterval(heartbeatInterval) eventSource.close() res.end()