Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: debug logs #245

Merged
merged 7 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions app/api/authenticate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
9 changes: 7 additions & 2 deletions backend/src/beacon/beacon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
try {
Expand Down Expand Up @@ -113,15 +114,19 @@ 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: {
headSlot: beaconResponse.data.data.head_slot
}
}
} else {
console.log(`fetching cached syncData for ${api}.....`)
if(this.isDebug) {
console.log(`fetching cached syncData for ${api}.....`)
}
}

return syncData.beaconSync.headSlot;
Expand Down
1 change: 1 addition & 0 deletions backend/src/database/database.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const dataBaseConfig: SequelizeModuleOptions = {
storage: '.db/data.sqlite3',
autoLoadModels: true,
synchronize: true,
logging: false,
};
6 changes: 5 additions & 1 deletion backend/src/logs/logs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Subject<any>> = new Map();
Expand All @@ -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);
Expand Down
13 changes: 10 additions & 3 deletions backend/src/tasks/tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
try {
Expand Down Expand Up @@ -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({
Expand All @@ -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))
Expand Down Expand Up @@ -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`,
Expand Down
11 changes: 8 additions & 3 deletions backend/src/utils/utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...'
}
Expand Down Expand Up @@ -89,15 +90,19 @@ 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
}

const data = await callback()

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
}
Expand Down
1 change: 0 additions & 1 deletion backend/src/validator/validator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions docker-assets/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion siren.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const handleSSe = (res, req, url) => {
}

req.on('close', () => {
console.error('Request closed...')
clearInterval(heartbeatInterval)
eventSource.close()
res.end()
Expand Down