96bed71022
* Improves error logging
- use pino error logger correctly by passing in error as first argument
* monitor deployment: Filter logging at INFO level and above
* Use structured logging to create parameters for monitoring results
* Add structured logging to obj fileimport service
* Fileimport service, fix and improve logging
- use child logger with additional context where possible
- select appropriate logging level
- fix duplicated context in log statement
* REST endpoints, add context to structured logging and remove same context from message
* Webhook service provides context to bound logger to properly use structured logging
- Pass bound logger containing context to `makeNetworkRequest`
- do not log url, as it may contain a secret (like Discord's webhook urls), instead log the webhook Id
- log error message when network call fails
* upload: make better use of structured logging when recording data
* pino-pretty when in dev or test mode
- pino-pretty configured to send to stderr
* LOG_PRETTY env var
* Silence structured logging during testing
- can not rely on determining the port number by reading from stdout/stderr
- instead we determine which port is free, then create our server on that port
- we then poll that port until the server is ready before commencing tests
* Allow puppeteer to install chromium
* Do not need to install chromium separately
84 lines
2.2 KiB
JavaScript
84 lines
2.2 KiB
JavaScript
'use strict'
|
|
|
|
const zlib = require('zlib')
|
|
const express = require('express')
|
|
const { getObject, getObjectChildrenStream } = require('./services/objects_utils')
|
|
const { SpeckleObjectsStream } = require('./speckleObjectsStream')
|
|
const { pipeline, PassThrough } = require('stream')
|
|
const { logger } = require('../observability/logging')
|
|
|
|
const router = express.Router()
|
|
|
|
// This method was copy-pasted from the server method, without authentication/authorization (this web service is an internal one)
|
|
router.get('/:streamId/:objectId', async function (req, res) {
|
|
const boundLogger = logger.child({
|
|
streamId: req.params.streamId,
|
|
objectId: req.params.objectId
|
|
})
|
|
// Populate first object (the "commit")
|
|
const obj = await getObject({
|
|
streamId: req.params.streamId,
|
|
objectId: req.params.objectId
|
|
})
|
|
|
|
if (!obj) {
|
|
return res.status(404).send('Failed to find object.')
|
|
}
|
|
|
|
const simpleText = req.headers.accept === 'text/plain'
|
|
|
|
res.writeHead(200, {
|
|
'Content-Encoding': 'gzip',
|
|
'Content-Type': simpleText ? 'text/plain' : 'application/json'
|
|
})
|
|
|
|
const dbStream = await getObjectChildrenStream({
|
|
streamId: req.params.streamId,
|
|
objectId: req.params.objectId
|
|
})
|
|
const speckleObjStream = new SpeckleObjectsStream(simpleText)
|
|
const gzipStream = zlib.createGzip()
|
|
|
|
speckleObjStream.write(obj)
|
|
|
|
pipeline(
|
|
dbStream,
|
|
speckleObjStream,
|
|
gzipStream,
|
|
new PassThrough({ highWaterMark: 16384 * 31 }),
|
|
res,
|
|
(err) => {
|
|
if (err) {
|
|
boundLogger.error(err, 'Error downloading object from stream')
|
|
} else {
|
|
boundLogger.info(
|
|
`Downloaded object from stream (size: ${
|
|
gzipStream.bytesWritten / 1000000
|
|
} MB)`
|
|
)
|
|
}
|
|
}
|
|
)
|
|
})
|
|
|
|
router.get('/:streamId/:objectId/single', async (req, res) => {
|
|
const boundLogger = logger.child({
|
|
streamId: req.params.streamId,
|
|
objectId: req.params.objectId
|
|
})
|
|
const obj = await getObject({
|
|
streamId: req.params.streamId,
|
|
objectId: req.params.objectId
|
|
})
|
|
|
|
if (!obj) {
|
|
return res.status(404).send('Failed to find object.')
|
|
}
|
|
|
|
boundLogger.info('Downloaded single object.')
|
|
|
|
res.send(obj.data)
|
|
})
|
|
|
|
module.exports = router
|