Skip to content

Commit

Permalink
remove deprecated duplicated metrics (#3833)
Browse files Browse the repository at this point in the history
* remove deprecated duplicated metrics

* remove backward compatibility
  • Loading branch information
mifi committed Jun 27, 2022
1 parent 4cbca6e commit d6441d8
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 37 deletions.
12 changes: 0 additions & 12 deletions packages/@uppy/companion/src/companion.js
Expand Up @@ -13,7 +13,6 @@ const s3 = require('./server/controllers/s3')
const url = require('./server/controllers/url')
const createEmitter = require('./server/emitter')
const redis = require('./server/redis')
const { getURLBuilder } = require('./server/helpers/utils')
const jobs = require('./server/jobs')
const logger = require('./server/logger')
const middlewares = require('./server/middlewares')
Expand Down Expand Up @@ -85,17 +84,6 @@ module.exports.app = (optionsArg = {}) => {

if (options.metrics) {
app.use(middlewares.metrics({ path: options.server.path }))

// backward compatibility
// TODO remove in next major semver
if (options.server.path) {
const buildUrl = getURLBuilder(options)
app.get('/metrics', (req, res) => {
process.emitWarning('/metrics is deprecated when specifying a path to companion')
const metricsUrl = buildUrl('/metrics', true)
res.redirect(metricsUrl)
})
}
}

app.use(cookieParser()) // server tokens are added to cookies
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/companion/src/config/companion.js
Expand Up @@ -21,6 +21,7 @@ const defaultOptions = {
periodicPingUrls: [],
streamingUpload: false,
clientSocketConnectTimeout: 60000,
metrics: true,
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/companion/src/standalone/helper.js
Expand Up @@ -112,6 +112,7 @@ const getConfigFromEnv = () => {
chunkSize: process.env.COMPANION_CHUNK_SIZE ? parseInt(process.env.COMPANION_CHUNK_SIZE, 10) : undefined,
clientSocketConnectTimeout: process.env.COMPANION_CLIENT_SOCKET_CONNECT_TIMEOUT
? parseInt(process.env.COMPANION_CLIENT_SOCKET_CONNECT_TIMEOUT, 10) : undefined,
metrics: process.env.COMPANION_HIDE_METRICS !== 'true',
}
}

Expand Down
22 changes: 0 additions & 22 deletions packages/@uppy/companion/src/standalone/index.js
Expand Up @@ -12,8 +12,6 @@ const logger = require('../server/logger')
const redis = require('../server/redis')
const companion = require('../companion')
const helper = require('./helper')
const middlewares = require('../server/middlewares')
const { getURLBuilder } = require('../server/helpers/utils')

/**
* Configures an Express app for running Companion standalone
Expand Down Expand Up @@ -102,26 +100,6 @@ module.exports = function server (inputCompanionOptions = {}) {
}
})

// for server metrics tracking.
// make app metrics available at '/metrics'.
// TODO for the next major version: use instead companion option "metrics": true and remove this code
// eslint-disable-next-line max-len
// See discussion: https://github.com/transloadit/uppy/pull/2854/files/64be97205e4012818abfcc8b0b8b7fe09de91729#diff-68f5e3eb307c1c9d1fd02224fd7888e2f74718744e1b6e35d929fcab1cc50ed1
if (process.env.COMPANION_HIDE_METRICS !== 'true') {
router.use(middlewares.metrics({ path: companionOptions.server.path }))

// backward compatibility
// TODO remove in next major semver
if (companionOptions.server.path) {
const buildUrl = getURLBuilder(companionOptions)
app.get('/metrics', (req, res) => {
process.emitWarning('/metrics is deprecated when specifying a path to companion')
const metricsUrl = buildUrl('/metrics', true)
res.redirect(metricsUrl)
})
}
}

router.use(bodyParser.json())
router.use(bodyParser.urlencoded({ extended: false }))

Expand Down
4 changes: 1 addition & 3 deletions packages/@uppy/companion/test/__tests__/subpath.js
Expand Up @@ -7,9 +7,7 @@ it('can be served under a subpath', async () => {
await request(server).get('/subpath').expect(200)
await request(server).get('/subpath/metrics').expect(200)
await request(server).get('/').expect(404)
// todo in next major:
await request(server).get('/metrics').expect(302)
// await request(server).get('/metrics').expect(404)
await request(server).get('/metrics').expect(404)
})

test('can be served without a subpath', async () => {
Expand Down

0 comments on commit d6441d8

Please sign in to comment.