reduce logs

This commit is contained in:
Hongbo Wu
2024-08-29 18:18:17 +08:00
parent 32f4b684cc
commit 70d6e9dcae
17 changed files with 2 additions and 107 deletions

View File

@ -289,7 +289,6 @@ export const triggerRule = async (jobData: TriggerRuleJobData) => {
// get rules by calling api // get rules by calling api
const rules = await findEnabledRules(userId, ruleEventType) const rules = await findEnabledRules(userId, ruleEventType)
if (rules.length === 0) { if (rules.length === 0) {
console.log('No rules found')
return false return false
} }

View File

@ -362,26 +362,6 @@ const main = async () => {
await setupCronJobs() await setupCronJobs()
const queueEvents = new QueueEvents(BACKEND_QUEUE_NAME, {
connection: workerRedisClient,
})
queueEvents.on('added', async (job) => {
console.log('added job: ', job.jobId, job.name)
})
queueEvents.on('removed', async (job) => {
console.log('removed job: ', job.jobId)
})
queueEvents.on('completed', async (job) => {
console.log('completed job: ', job.jobId)
})
queueEvents.on('failed', async (job) => {
console.log('failed job: ', job.jobId)
})
workerRedisClient.on('error', (error) => { workerRedisClient.on('error', (error) => {
console.trace('[queue-processor]: redis worker error', { error }) console.trace('[queue-processor]: redis worker error', { error })
}) })

View File

@ -318,13 +318,6 @@ export const createArticleResolver = authorized<
savedAt, savedAt,
}) })
log.info('New article saving', {
parsedArticle: Object.assign({}, libraryItemToSave, {
readableContent: undefined,
originalContent: undefined,
}),
})
if (uploadFileId) { if (uploadFileId) {
const uploadFileData = await setFileUploadComplete(uploadFileId) const uploadFileData = await setFileUploadComplete(uploadFileId)
if (!uploadFileData || !uploadFileData.id || !uploadFileData.fileName) { if (!uploadFileData || !uploadFileData.id || !uploadFileData.fileName) {
@ -461,12 +454,6 @@ export const setBookmarkArticleResolver = authorized<
}, },
}) })
log.info('Article unbookmarked', {
item: Object.assign({}, deletedLibraryItem, {
readableContent: undefined,
originalContent: undefined,
}),
})
// Make sure article.id instead of userArticle.id has passed. We use it for cache updates // Make sure article.id instead of userArticle.id has passed. We use it for cache updates
return { return {
bookmarkedArticle: deletedLibraryItem, bookmarkedArticle: deletedLibraryItem,

View File

@ -206,8 +206,6 @@ export const userDigestEligible = async (uid: string): Promise<boolean> => {
const featuresCacheKey = (userId: string) => `cache:features:${userId}` const featuresCacheKey = (userId: string) => `cache:features:${userId}`
export const getFeaturesCache = async (userId: string) => { export const getFeaturesCache = async (userId: string) => {
logger.debug('getFeaturesCache', { userId })
const cachedFeatures = await redisDataSource.redisClient?.get( const cachedFeatures = await redisDataSource.redisClient?.get(
featuresCacheKey(userId) featuresCacheKey(userId)
) )
@ -221,8 +219,6 @@ export const getFeaturesCache = async (userId: string) => {
export const setFeaturesCache = async (userId: string, features: Feature[]) => { export const setFeaturesCache = async (userId: string, features: Feature[]) => {
const value = JSON.stringify(features) const value = JSON.stringify(features)
logger.debug('setFeaturesCache', { userId, value })
return redisDataSource.redisClient?.set( return redisDataSource.redisClient?.set(
featuresCacheKey(userId), featuresCacheKey(userId),
value, value,

View File

@ -1749,11 +1749,6 @@ const totalCountCacheKey = (userId: string, args: SearchArgs) => {
} }
export const getCachedTotalCount = async (userId: string, args: SearchArgs) => { export const getCachedTotalCount = async (userId: string, args: SearchArgs) => {
logger.debug('Getting cached total count:', {
userId,
args,
})
const cacheKey = totalCountCacheKey(userId, args) const cacheKey = totalCountCacheKey(userId, args)
const cachedCount = await redisDataSource.redisClient?.get(cacheKey) const cachedCount = await redisDataSource.redisClient?.get(cacheKey)
if (!cachedCount) { if (!cachedCount) {
@ -1770,11 +1765,6 @@ export const setCachedTotalCount = async (
) => { ) => {
const cacheKey = totalCountCacheKey(userId, args) const cacheKey = totalCountCacheKey(userId, args)
logger.debug('Setting cached total count:', {
cacheKey,
count,
})
await redisDataSource.redisClient?.set(cacheKey, count, 'EX', 600) await redisDataSource.redisClient?.set(cacheKey, count, 'EX', 600)
} }
@ -1785,10 +1775,5 @@ export const deleteCachedTotalCount = async (userId: string) => {
return return
} }
logger.debug('Deleting keys:', {
keys,
userId,
})
await redisDataSource.redisClient?.del(keys) await redisDataSource.redisClient?.del(keys)
} }

View File

@ -161,8 +161,6 @@ export const findUserAndPersonalization = async (id: string) => {
const userCacheKey = (id: string) => `cache:user:${id}` const userCacheKey = (id: string) => `cache:user:${id}`
export const getCachedUser = async (id: string) => { export const getCachedUser = async (id: string) => {
logger.debug(`Getting user from cache: ${id}`)
const user = await redisDataSource.redisClient?.get(userCacheKey(id)) const user = await redisDataSource.redisClient?.get(userCacheKey(id))
if (!user) { if (!user) {
return undefined return undefined
@ -172,8 +170,6 @@ export const getCachedUser = async (id: string) => {
} }
export const cacheUser = async (user: User) => { export const cacheUser = async (user: User) => {
logger.debug(`Caching user: ${user.id}`)
await redisDataSource.redisClient?.set( await redisDataSource.redisClient?.set(
userCacheKey(user.id), userCacheKey(user.id),
JSON.stringify(user), JSON.stringify(user),

View File

@ -177,8 +177,6 @@ const userDefaultShortcuts = async (userId: string): Promise<Shortcut[]> => {
const shortcutsCacheKey = (userId: string) => `cache:shortcuts:${userId}` const shortcutsCacheKey = (userId: string) => `cache:shortcuts:${userId}`
export const getShortcutsCache = async (userId: string) => { export const getShortcutsCache = async (userId: string) => {
logger.debug(`Getting shortcuts from cache: ${userId}`)
const cachedShortcuts = await redisDataSource.redisClient?.get( const cachedShortcuts = await redisDataSource.redisClient?.get(
shortcutsCacheKey(userId) shortcutsCacheKey(userId)
) )
@ -189,8 +187,6 @@ export const getShortcutsCache = async (userId: string) => {
} }
export const cacheShortcuts = async (userId: string, shortcuts: Shortcut[]) => { export const cacheShortcuts = async (userId: string, shortcuts: Shortcut[]) => {
logger.debug(`Caching shortcuts: ${userId}`)
await redisDataSource.redisClient?.set( await redisDataSource.redisClient?.set(
shortcutsCacheKey(userId), shortcutsCacheKey(userId),
JSON.stringify(shortcuts), JSON.stringify(shortcuts),

View File

@ -33,7 +33,6 @@ export const apiLimiter = rateLimit({
const claims = await getClaimsByToken(token) const claims = await getClaimsByToken(token)
return claims ? 60 : 15 return claims ? 60 : 15
} catch (e) { } catch (e) {
console.log('non-authenticated request')
return 15 return 15
} }
}, },
@ -53,7 +52,6 @@ export const apiHourLimiter = rateLimit({
const claims = await getClaimsByToken(token) const claims = await getClaimsByToken(token)
return claims ? 600 : 150 return claims ? 600 : 150
} catch (e) { } catch (e) {
console.log('non-authenticated request')
return 150 return 150
} }
}, },

View File

@ -31,8 +31,6 @@ class PostHogClient implements AnalyticClient {
return return
} }
console.log('analytics', { userIds, result, properties })
} }
} }

View File

@ -299,12 +299,7 @@ export const processFetchContentJob = async (
} }
if (fetchResult.content && !NO_CACHE_URLS.includes(url)) { if (fetchResult.content && !NO_CACHE_URLS.includes(url)) {
const cacheResult = await cacheFetchResult( await cacheFetchResult(redisDataSource, key, fetchResult)
redisDataSource,
key,
fetchResult
)
console.log('cache result', cacheResult)
} }
} }

View File

@ -1,5 +1,5 @@
import { RedisDataSource } from '@omnivore/utils' import { RedisDataSource } from '@omnivore/utils'
import { Job, Queue, QueueEvents, RedisClient, Worker } from 'bullmq' import { Job, Queue, RedisClient, Worker } from 'bullmq'
import { JobData, processFetchContentJob } from './request_handler' import { JobData, processFetchContentJob } from './request_handler'
export const QUEUE = 'omnivore-content-fetch-queue' export const QUEUE = 'omnivore-content-fetch-queue'
@ -53,25 +53,5 @@ export const createWorker = (
console.error('worker error:', err) console.error('worker error:', err)
}) })
const queueEvents = new QueueEvents(queueName, {
connection: redisDataSource.queueRedisClient,
})
queueEvents.on('added', (job) => {
console.log('added job:', job.jobId, job.name)
})
queueEvents.on('removed', (job) => {
console.log('removed job:', job.jobId)
})
queueEvents.on('completed', (job) => {
console.log('completed job:', job.jobId)
})
queueEvents.on('failed', (job) => {
console.log('failed job:', job.jobId)
})
return worker return worker
} }

View File

@ -159,8 +159,6 @@ export abstract class ContentHandler {
html, html,
headers, headers,
}: NewsletterInput): Promise<NewsletterResult> { }: NewsletterInput): Promise<NewsletterResult> {
console.log('handleNewsletter', from, to, subject, headers)
if (!from || !html || !subject || !to) { if (!from || !html || !subject || !to) {
console.log('invalid newsletter email') console.log('invalid newsletter email')
throw new Error('invalid newsletter email') throw new Error('invalid newsletter email')

View File

@ -13,8 +13,6 @@ const parseLabels = (labels: string): string[] => {
// labels follows format: "[""label1"",""label2""]" // labels follows format: "[""label1"",""label2""]"
return JSON.parse(labels) as string[] return JSON.parse(labels) as string[]
} catch (error) { } catch (error) {
console.debug('invalid labels format', labels)
// labels follows format: "[label1,label2]" // labels follows format: "[label1,label2]"
return labels return labels
.slice(1, -1) .slice(1, -1)

View File

@ -55,10 +55,8 @@ export const inboundEmailHandler = Sentry.GCPFunction.wrapHttpFunction(
console.log('no data or name for ', part) console.log('no data or name for ', part)
} }
} }
console.log('parsed', parsed)
const headers = parseHeaders(parsed.headers) const headers = parseHeaders(parsed.headers)
console.log('headers', headers)
// original sender email address // original sender email address
const from = parsed['from'] const from = parsed['from']

View File

@ -45,7 +45,6 @@ const getDocumentUrl = async (
const [url] = await file.getSignedUrl(options) const [url] = await file.getSignedUrl(options)
return new URL(url) return new URL(url)
} catch (e) { } catch (e) {
console.debug('error getting signed url', e)
return undefined return undefined
} }
} }
@ -101,8 +100,6 @@ export const pdfHandler = Sentry.GCPFunction.wrapHttpFunction(
return res.send('ok') return res.send('ok')
} }
console.log('handling pdf data', data)
let content, let content,
title, title,
author, author,

View File

@ -214,7 +214,6 @@ export const textToSpeechHandler = Sentry.GCPFunction.wrapHttpFunction(
export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction( export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
async (req, res) => { async (req, res) => {
console.log('Text to speech steaming request body:', req.body)
if (!process.env.JWT_SECRET) { if (!process.env.JWT_SECRET) {
console.error('JWT_SECRET not exists') console.error('JWT_SECRET not exists')
return res.status(500).send({ errorCodes: 'JWT_SECRET_NOT_EXISTS' }) return res.status(500).send({ errorCodes: 'JWT_SECRET_NOT_EXISTS' })
@ -314,7 +313,6 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
// check if audio file already exists // check if audio file already exists
const [exists] = await audioFile.exists() const [exists] = await audioFile.exists()
if (exists) { if (exists) {
console.debug('Audio file already exists')
;[audioData] = await audioFile.download() ;[audioData] = await audioFile.download()
const [speechMarksExists] = await speechMarksFile.exists() const [speechMarksExists] = await speechMarksFile.exists()
if (speechMarksExists) { if (speechMarksExists) {
@ -341,7 +339,6 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
}) })
} }
console.debug('saving audio file')
// upload audio data to GCS // upload audio data to GCS
await audioFile.save(audioData) await audioFile.save(audioData)
// upload speech marks to GCS // upload speech marks to GCS

View File

@ -290,7 +290,6 @@ export const thumbnailHandler = Sentry.GCPFunction.wrapHttpFunction(
const token = req.headers.cookie?.split('auth=')[1] const token = req.headers.cookie?.split('auth=')[1]
if (!token) { if (!token) {
console.debug('no token')
return res.status(401).send('UNAUTHORIZED') return res.status(401).send('UNAUTHORIZED')
} }
let uid = '' let uid = ''
@ -300,12 +299,10 @@ export const thumbnailHandler = Sentry.GCPFunction.wrapHttpFunction(
} }
uid = decoded.uid uid = decoded.uid
} catch (e) { } catch (e) {
console.debug(e)
return res.status(401).send('UNAUTHORIZED') return res.status(401).send('UNAUTHORIZED')
} }
if (!isThumbnailRequest(req.body)) { if (!isThumbnailRequest(req.body)) {
console.debug('bad request')
return res.status(400).send('BAD_REQUEST') return res.status(400).send('BAD_REQUEST')
} }