mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-22 00:10:37 +00:00
Mongo timeouts and long request logging (#2891)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
293d56f4a2
commit
442fcace43
@ -1 +1 @@
|
|||||||
{ "major": 0, "minor": 6, "patch": 73 }
|
{ "major": 0, "minor": 6, "patch": 78 }
|
||||||
|
@ -14,22 +14,26 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
import { ArrOf, Builder, Collection, Mixin, Model, Prop, TypeRef, TypeString } from '@hcengineering/model'
|
import { ArrOf, Builder, Collection, Mixin, Model, Prop, ReadOnly, TypeRef, TypeString, UX } from '@hcengineering/model'
|
||||||
import core, { TAttachedDoc, TDoc } from '@hcengineering/model-core'
|
import core, { TAttachedDoc, TDoc } from '@hcengineering/model-core'
|
||||||
import bitrix from './plugin'
|
import bitrix from './plugin'
|
||||||
|
|
||||||
import { BitrixEntityMapping, BitrixFieldMapping, BitrixSyncDoc, Fields } from '@hcengineering/bitrix'
|
import { BitrixEntityMapping, BitrixFieldMapping, BitrixSyncDoc, Fields } from '@hcengineering/bitrix'
|
||||||
import { AnyAttribute, Class, Doc, Domain, Mixin as CoreMixin, Ref } from '@hcengineering/core'
|
import { AnyAttribute, Class, Mixin as CoreMixin, Doc, Domain, Ref } from '@hcengineering/core'
|
||||||
|
|
||||||
import view, { createAction } from '@hcengineering/model-view'
|
import view, { createAction } from '@hcengineering/model-view'
|
||||||
|
|
||||||
|
import { getEmbeddedLabel } from '@hcengineering/platform'
|
||||||
import setting from '@hcengineering/setting'
|
import setting from '@hcengineering/setting'
|
||||||
|
|
||||||
const DOMAIN_BITRIX = 'bitrix' as Domain
|
const DOMAIN_BITRIX = 'bitrix' as Domain
|
||||||
|
|
||||||
@Mixin(bitrix.mixin.BitrixSyncDoc, core.class.Doc)
|
@Mixin(bitrix.mixin.BitrixSyncDoc, core.class.Doc)
|
||||||
|
@UX(getEmbeddedLabel('Bitrix'))
|
||||||
export class TBitrixSyncDoc extends TDoc implements BitrixSyncDoc {
|
export class TBitrixSyncDoc extends TDoc implements BitrixSyncDoc {
|
||||||
type!: string
|
type!: string
|
||||||
|
@Prop(TypeString(), getEmbeddedLabel('BitrixId'))
|
||||||
|
@ReadOnly()
|
||||||
bitrixId!: string
|
bitrixId!: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,12 +90,15 @@ export class TDoc extends TObj implements Doc {
|
|||||||
space!: Ref<Space>
|
space!: Ref<Space>
|
||||||
|
|
||||||
@Prop(TypeTimestamp(), core.string.Modified)
|
@Prop(TypeTimestamp(), core.string.Modified)
|
||||||
|
@Index(IndexKind.Indexed)
|
||||||
modifiedOn!: Timestamp
|
modifiedOn!: Timestamp
|
||||||
|
|
||||||
@Prop(TypeRef(core.class.Account), core.string.ModifiedBy)
|
@Prop(TypeRef(core.class.Account), core.string.ModifiedBy)
|
||||||
|
@Index(IndexKind.Indexed)
|
||||||
modifiedBy!: Ref<Account>
|
modifiedBy!: Ref<Account>
|
||||||
|
|
||||||
@Prop(TypeRef(core.class.Account), core.string.CreatedBy)
|
@Prop(TypeRef(core.class.Account), core.string.CreatedBy)
|
||||||
|
@Index(IndexKind.Indexed)
|
||||||
createdBy!: Ref<Account>
|
createdBy!: Ref<Account>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +207,7 @@ export class TIssue extends TAttachedDoc implements Issue {
|
|||||||
blockedBy!: RelatedDocument[]
|
blockedBy!: RelatedDocument[]
|
||||||
|
|
||||||
@Prop(ArrOf(TypeRef(core.class.TypeRelatedDocument)), tracker.string.RelatedTo)
|
@Prop(ArrOf(TypeRef(core.class.TypeRelatedDocument)), tracker.string.RelatedTo)
|
||||||
|
@Index(IndexKind.Indexed)
|
||||||
relations!: RelatedDocument[]
|
relations!: RelatedDocument[]
|
||||||
|
|
||||||
parents!: IssueParentInfo[]
|
parents!: IssueParentInfo[]
|
||||||
|
@ -5,4 +5,4 @@ WORKDIR /usr/src/app
|
|||||||
COPY bundle.js ./
|
COPY bundle.js ./
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
CMD [ "node", "--enable-source-maps", "bundle.js" ]
|
CMD [ "node", "--enable-source-maps", "--inspect", "bundle.js" ]
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
"docker:push": "../../common/scripts/docker_tag.sh hardcoreeng/transactor",
|
"docker:push": "../../common/scripts/docker_tag.sh hardcoreeng/transactor",
|
||||||
"build:watch": "tsc",
|
"build:watch": "tsc",
|
||||||
"lint": "eslint src",
|
"lint": "eslint src",
|
||||||
"format": "prettier --write src && eslint --fix src"
|
"format": "prettier --write src && eslint --fix src",
|
||||||
|
"docker:tbuild": "docker build -t hardcoreeng/transactor . --platform=linux/amd64 && ../../common/scripts/docker_tag_push.sh hardcoreeng/transactor"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"cross-env": "~7.0.3",
|
"cross-env": "~7.0.3",
|
||||||
|
@ -408,6 +408,7 @@ abstract class MongoAdapterBase implements DbAdapter {
|
|||||||
})
|
})
|
||||||
const domain = this.hierarchy.getDomain(clazz)
|
const domain = this.hierarchy.getDomain(clazz)
|
||||||
const cursor = this.db.collection(domain).aggregate(pipeline)
|
const cursor = this.db.collection(domain).aggregate(pipeline)
|
||||||
|
cursor.maxTimeMS(30000)
|
||||||
const res = (await cursor.toArray())[0]
|
const res = (await cursor.toArray())[0]
|
||||||
const result = res.results as WithLookup<T>[]
|
const result = res.results as WithLookup<T>[]
|
||||||
const total = res.totalCount?.shift()?.count
|
const total = res.totalCount?.shift()?.count
|
||||||
@ -529,6 +530,11 @@ abstract class MongoAdapterBase implements DbAdapter {
|
|||||||
cursor = cursor.limit(options.limit)
|
cursor = cursor.limit(options.limit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error in case of timeout
|
||||||
|
cursor.maxTimeMS(30000)
|
||||||
|
cursor.maxAwaitTimeMS(30000)
|
||||||
|
|
||||||
const res = await cursor.toArray()
|
const res = await cursor.toArray()
|
||||||
return toFindResult(res, total)
|
return toFindResult(res, total)
|
||||||
}
|
}
|
||||||
|
@ -319,7 +319,8 @@ async function handleRequest<S extends Session> (
|
|||||||
ctx: MeasureContext,
|
ctx: MeasureContext,
|
||||||
service: S,
|
service: S,
|
||||||
ws: WebSocket,
|
ws: WebSocket,
|
||||||
msg: string
|
msg: string,
|
||||||
|
workspace: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const request = readRequest(msg)
|
const request = readRequest(msg)
|
||||||
if (request.id === -1 && request.method === 'hello') {
|
if (request.id === -1 && request.method === 'hello') {
|
||||||
@ -336,10 +337,36 @@ async function handleRequest<S extends Session> (
|
|||||||
const f = (service as any)[request.method]
|
const f = (service as any)[request.method]
|
||||||
try {
|
try {
|
||||||
const params = [userCtx, ...request.params]
|
const params = [userCtx, ...request.params]
|
||||||
|
|
||||||
|
const st = Date.now()
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
console.log('long request found', workspace, service.getUser(), request, params)
|
||||||
|
}, 4000)
|
||||||
|
|
||||||
|
const hangTimeout = setTimeout(() => {
|
||||||
|
console.log('request hang found, 30sec', workspace, service.getUser(), request, params)
|
||||||
|
}, 30000)
|
||||||
|
|
||||||
const result = await f.apply(service, params)
|
const result = await f.apply(service, params)
|
||||||
|
clearTimeout(timeout)
|
||||||
|
clearTimeout(hangTimeout)
|
||||||
const resp: Response<any> = { id: request.id, result }
|
const resp: Response<any> = { id: request.id, result }
|
||||||
|
|
||||||
|
const diff = Date.now() - st
|
||||||
|
if (diff > 5000) {
|
||||||
|
console.log(
|
||||||
|
'very long request found',
|
||||||
|
workspace,
|
||||||
|
service.getUser(),
|
||||||
|
request,
|
||||||
|
params,
|
||||||
|
Array.isArray(result) ? result.length : '0',
|
||||||
|
diff
|
||||||
|
)
|
||||||
|
}
|
||||||
ws.send(serialize(resp))
|
ws.send(serialize(resp))
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
console.error(err)
|
||||||
const resp: Response<any> = {
|
const resp: Response<any> = {
|
||||||
id: request.id,
|
id: request.id,
|
||||||
error: unknownError(err)
|
error: unknownError(err)
|
||||||
@ -398,7 +425,7 @@ export function start (
|
|||||||
} else if (Array.isArray(msg)) {
|
} else if (Array.isArray(msg)) {
|
||||||
msgStr = Buffer.concat(msg).toString()
|
msgStr = Buffer.concat(msg).toString()
|
||||||
}
|
}
|
||||||
await handleRequest(ctx, session, ws, msgStr)
|
await handleRequest(ctx, session, ws, msgStr, token.workspace.name)
|
||||||
})
|
})
|
||||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
ws.on('close', (code: number, reason: Buffer) => {
|
ws.on('close', (code: number, reason: Buffer) => {
|
||||||
@ -420,7 +447,7 @@ export function start (
|
|||||||
const b = buffer
|
const b = buffer
|
||||||
buffer = undefined
|
buffer = undefined
|
||||||
for (const msg of b) {
|
for (const msg of b) {
|
||||||
await handleRequest(ctx, session, ws, msg)
|
await handleRequest(ctx, session, ws, msg, token.workspace.name)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user