UBERF-6643: A bit more logging (#5413)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2024-04-21 00:34:41 +07:00 committed by GitHub
parent fc285330bc
commit 8dfd0fcf6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 58 additions and 15 deletions

View File

@ -887,6 +887,9 @@ dependencies:
'@types/koa-bodyparser':
specifier: ^4.3.3
version: 4.3.12
'@types/koa-morgan':
specifier: ^1.0.8
version: 1.0.8
'@types/koa-passport':
specifier: ^6.0.0
version: 6.0.3
@ -1118,6 +1121,9 @@ dependencies:
koa-bodyparser:
specifier: ^4.3.0
version: 4.4.1
koa-morgan:
specifier: ^1.0.1
version: 1.0.1
koa-passport:
specifier: ~6.0.0
version: 6.0.0
@ -6279,6 +6285,13 @@ packages:
'@types/koa': 2.14.0
dev: false
/@types/koa-morgan@1.0.8:
resolution: {integrity: sha512-2GredUi+iA3V0XrbzdsOAYgwj4F6+FnN+f5YjoKjessIE2lrMkqnc06YQQnzbMG75hRsXjyD+p6d5vlI70s1vg==}
dependencies:
'@types/koa': 2.14.0
'@types/morgan': 1.9.9
dev: false
/@types/koa-passport@6.0.3:
resolution: {integrity: sha512-9iV8aiSICfBZpqkkzUshqxN2wTuoj4HGRRH0Idv3lHhXV9rZRCOyDdJSg+vZ6RHSQg0ZeBeAdIL4r/l8bR4SPA==}
dependencies:
@ -12119,6 +12132,12 @@ packages:
koa-compose: 4.1.0
dev: false
/koa-morgan@1.0.1:
resolution: {integrity: sha512-JOUdCNlc21G50afBXfErUrr1RKymbgzlrO5KURY+wmDG1Uvd2jmxUJcHgylb/mYXy2SjiNZyYim/ptUBGsIi3A==}
dependencies:
morgan: 1.10.0
dev: false
/koa-passport@6.0.0:
resolution: {integrity: sha512-bgcrQN7Ylfgi1PVr5l6hHYkr38RHUzx+ty3m7e/xoTte8MR0zbDt6+pvP3/nuF/yXL6Ba7IzX1rSqmCy6OrrIw==}
engines: {node: '>= 4'}
@ -17044,7 +17063,7 @@ packages:
dev: false
file:projects/account-service.tgz:
resolution: {integrity: sha512-nobaJJXk2cwnaGafGa8skzZZ4Y3tn6AfYwO3SMo0hMyh5VSL6qzpqPo0Qyaf8PEgk/0IhyEt9fY9hqPzGnozAg==, tarball: file:projects/account-service.tgz}
resolution: {integrity: sha512-41LxbvGXCGm44FSbEJRQju/3/rEYOoqGcOTtxFlhFha68GQApiBjYnesZZh5DUrkFsXt8/RUVNz5OUutPoENpg==, tarball: file:projects/account-service.tgz}
name: '@rush-temp/account-service'
version: 0.0.0
dependencies:
@ -17052,6 +17071,7 @@ packages:
'@types/jest': 29.5.12
'@types/koa': 2.14.0
'@types/koa-bodyparser': 4.3.12
'@types/koa-morgan': 1.0.8
'@types/koa-router': 7.4.8
'@types/koa__cors': 3.3.1
'@types/node': 20.11.19
@ -17067,6 +17087,7 @@ packages:
jest: 29.7.0(@types/node@20.11.19)(ts-node@10.9.2)
koa: 2.15.0
koa-bodyparser: 4.4.1
koa-morgan: 1.0.1
koa-router: 12.0.1
mongodb: 6.3.0
prettier: 3.2.5

View File

@ -39,7 +39,8 @@
"typescript": "^5.3.3",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"@types/jest": "^29.5.5"
"@types/jest": "^29.5.5",
"@types/koa-morgan": "^1.0.8"
},
"dependencies": {
"@hcengineering/account": "^0.6.0",
@ -54,6 +55,7 @@
"@koa/cors": "^3.1.0",
"@hcengineering/server-tool": "^0.6.0",
"@hcengineering/server-token": "^0.6.7",
"@hcengineering/analytics": "^0.6.0"
"@hcengineering/analytics": "^0.6.0",
"koa-morgan": "^1.0.1"
}
}

View File

@ -24,6 +24,7 @@ import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import Router from 'koa-router'
import { MongoClient } from 'mongodb'
import morgan from 'koa-morgan'
/**
* @public
@ -94,6 +95,16 @@ export function serveAccount (
const app = new Koa()
const router = new Router()
class MyStream {
write (text: string): void {
void measureCtx.info(text)
}
}
const myStream = new MyStream()
app.use(morgan('short', { stream: myStream }))
let worker: UpgradeWorker | undefined
void client.then(async (p: MongoClient) => {

View File

@ -862,12 +862,7 @@ export async function createWorkspace (
await updateInfo({ createProgress: 10 })
let client: Client | undefined
const childLogger = ctx.newChild(
'createWorkspace',
{ workspace: workspaceInfo.workspace },
{},
ctx.logger.childLogger?.(workspaceInfo.workspace, {}) ?? ctx.logger
)
const childLogger = ctx.newChild('createWorkspace', { workspace: workspaceInfo.workspace })
const ctxModellogger: ModelLogger = {
log: (msg, data) => {
void childLogger.info(msg, data)
@ -934,6 +929,7 @@ export async function createWorkspace (
Analytics.handleError(err)
return { workspaceInfo, err, client: null as any }
}
childLogger.end()
// Workspace is created, we need to clear disabled flag.
await updateInfo({ createProgress: 100, disabled: false, creating: false })
return { workspaceInfo, client }
@ -971,7 +967,8 @@ export async function upgradeWorkspace (
await ctx.info('upgrading', {
force: forceUpdate,
currentVersion: ws?.version !== undefined ? versionToString(ws.version) : '',
toVersion: versionStr
toVersion: versionStr,
workspace: ws.workspace
})
await (
await upgradeModel(

View File

@ -86,7 +86,7 @@ export class UpgradeWorker {
})
this.toProcess--
try {
await upgradeWorkspace(
const version = await upgradeWorkspace(
ctx,
this.version,
this.txes,
@ -100,7 +100,8 @@ export class UpgradeWorker {
await ctx.info('---done---------', {
pending: this.toProcess,
time: Date.now() - t,
workspace: ws.workspace
workspace: ws.workspace,
version
})
} catch (err: any) {
await opt.errorHandler(ws, err)

View File

@ -573,6 +573,10 @@ export async function backup (
async (ctx) => await loadChangesFromServer(ctx, domain, digest, changes)
)
if (needRetrieveChunks.length > 0) {
await ctx.info('dumping domain...', { workspace: workspaceId.name, domain })
}
while (needRetrieveChunks.length > 0) {
if (canceled) {
return
@ -701,8 +705,6 @@ export async function backup (
if (canceled) {
break
}
await ctx.info('dumping domain...', { workspace: workspaceId.name, domain })
await ctx.with('process-domain', { domain }, async (ctx) => {
await processDomain(ctx, domain)
})

View File

@ -306,6 +306,12 @@ class TSessionManager implements SessionManager {
}
} else {
if (workspace.upgrade) {
await ctx.info('connect during upgrade', {
email: token.email,
workspace: workspace.workspaceId.name,
sessionUsers: Array.from(workspace.sessions.values()).map((it) => it.session.getUser()),
sessionData: Array.from(workspace.sessions.values()).map((it) => it.socket.data())
})
return { upgrade: true }
}
pipeline = await ctx.with('💤 wait', { workspaceName }, async () => await (workspace as Workspace).pipeline)

View File

@ -176,7 +176,10 @@ export function startHttpServer (
const data = {
remoteAddress: request.socket.remoteAddress ?? '',
userAgent: request.headers['user-agent'] ?? '',
language: request.headers['accept-language'] ?? ''
language: request.headers['accept-language'] ?? '',
email: token.email,
mode: token.extra?.mode,
model: token.extra?.model
}
const cs: ConnectionSocket = {
id: generateId(),