aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-11-16 10:49:03 +0100
committerChocobozzz <me@florianbigard.com>2021-11-16 10:49:03 +0100
commitac03618098e430acb21c075bdba57ce6d377b12d (patch)
treed3140bb58c12f6a8739dceb65d3f94785bbc9845 /server
parenta2f99b54dfdfe489e14714681189cb13c89f60a3 (diff)
downloadPeerTube-ac03618098e430acb21c075bdba57ce6d377b12d.tar.gz
PeerTube-ac03618098e430acb21c075bdba57ce6d377b12d.tar.zst
PeerTube-ac03618098e430acb21c075bdba57ce6d377b12d.zip
Don't display log tag filter for audit logs
Diffstat (limited to 'server')
-rw-r--r--server/helpers/requests.ts19
1 files changed, 15 insertions, 4 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index 57299eee1..6e80995ad 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -6,9 +6,11 @@ import { CONFIG } from '../initializers/config'
6import { ACTIVITY_PUB, BINARY_CONTENT_TYPES, PEERTUBE_VERSION, REQUEST_TIMEOUT, WEBSERVER } from '../initializers/constants' 6import { ACTIVITY_PUB, BINARY_CONTENT_TYPES, PEERTUBE_VERSION, REQUEST_TIMEOUT, WEBSERVER } from '../initializers/constants'
7import { pipelinePromise } from './core-utils' 7import { pipelinePromise } from './core-utils'
8import { processImage } from './image-utils' 8import { processImage } from './image-utils'
9import { logger } from './logger' 9import { logger, loggerTagsFactory } from './logger'
10import { getProxy, isProxyEnabled } from './proxy' 10import { getProxy, isProxyEnabled } from './proxy'
11 11
12const lTags = loggerTagsFactory('request')
13
12const httpSignature = require('@peertube/http-signature') 14const httpSignature = require('@peertube/http-signature')
13 15
14export interface PeerTubeRequestError extends Error { 16export interface PeerTubeRequestError extends Error {
@@ -48,7 +50,7 @@ const peertubeGot = got.extend({
48 promiseOrStream.on('downloadProgress', progress => { 50 promiseOrStream.on('downloadProgress', progress => {
49 if (progress.transferred > bodyLimit && progress.percent !== 1) { 51 if (progress.transferred > bodyLimit && progress.percent !== 1) {
50 const message = `Exceeded the download limit of ${bodyLimit} B` 52 const message = `Exceeded the download limit of ${bodyLimit} B`
51 logger.warn(message) 53 logger.warn(message, lTags())
52 54
53 // CancelableRequest 55 // CancelableRequest
54 if (promiseOrStream.cancel) { 56 if (promiseOrStream.cancel) {
@@ -105,6 +107,7 @@ function doRequest (url: string, options: PeerTubeRequestOptions = {}) {
105 const gotOptions = buildGotOptions(options) 107 const gotOptions = buildGotOptions(options)
106 108
107 return peertubeGot(url, gotOptions) 109 return peertubeGot(url, gotOptions)
110 .on('retry', logRetryFactory(url))
108 .catch(err => { throw buildRequestError(err) }) 111 .catch(err => { throw buildRequestError(err) })
109} 112}
110 113
@@ -112,6 +115,7 @@ function doJSONRequest <T> (url: string, options: PeerTubeRequestOptions = {}) {
112 const gotOptions = buildGotOptions(options) 115 const gotOptions = buildGotOptions(options)
113 116
114 return peertubeGot<T>(url, { ...gotOptions, responseType: 'json' }) 117 return peertubeGot<T>(url, { ...gotOptions, responseType: 'json' })
118 .on('retry', logRetryFactory(url))
115 .catch(err => { throw buildRequestError(err) }) 119 .catch(err => { throw buildRequestError(err) })
116} 120}
117 121
@@ -131,7 +135,7 @@ async function doRequestAndSaveToFile (
131 ) 135 )
132 } catch (err) { 136 } catch (err) {
133 remove(destPath) 137 remove(destPath)
134 .catch(err => logger.error('Cannot remove %s after request failure.', destPath, { err })) 138 .catch(err => logger.error('Cannot remove %s after request failure.', destPath, { err, ...lTags() }))
135 139
136 throw buildRequestError(err) 140 throw buildRequestError(err)
137 } 141 }
@@ -157,7 +161,7 @@ function getAgent () {
157 161
158 const proxy = getProxy() 162 const proxy = getProxy()
159 163
160 logger.info('Using proxy %s.', proxy) 164 logger.info('Using proxy %s.', proxy, lTags())
161 165
162 const proxyAgentOptions = { 166 const proxyAgentOptions = {
163 keepAlive: true, 167 keepAlive: true,
@@ -229,6 +233,7 @@ function buildGotOptions (options: PeerTubeRequestOptions) {
229 timeout: REQUEST_TIMEOUT, 233 timeout: REQUEST_TIMEOUT,
230 json: options.json, 234 json: options.json,
231 searchParams: options.searchParams, 235 searchParams: options.searchParams,
236 retry: 2,
232 headers, 237 headers,
233 context 238 context
234 } 239 }
@@ -246,3 +251,9 @@ function buildRequestError (error: RequestError) {
246 251
247 return newError 252 return newError
248} 253}
254
255function logRetryFactory (url: string) {
256 return (retryCount: number, error: RequestError) => {
257 logger.debug('Retrying request to %s.', url, { retryCount, error, ...lTags() })
258 }
259}