Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

companion: add option to hide welcome and metrics #2521

Merged
merged 3 commits into from Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/@uppy/companion/env.test.sh
Expand Up @@ -2,6 +2,8 @@ export NODE_ENV="test"
export COMPANION_PORT=3020
export COMPANION_DOMAIN="localhost:3020"
export COMPANION_SELF_ENDPOINT="localhost:3020"
export COMPANION_HIDE_METRICS="false"
export COMPANION_HIDE_WELCOME="false"

export COMPANION_PROTOCOL="http"
export COMPANION_DATADIR="./test/output"
Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/companion/env_example
Expand Up @@ -2,6 +2,8 @@ NODE_ENV=dev
COMPANION_PORT=3020
COMPANION_DOMAIN=uppy.xxxx.com
COMPANION_SELF_ENDPOINT=uppy.xxxx.com
COMPANION_HIDE_METRICS=false
COMPANION_HIDE_WELCOME=false

COMPANION_PROTOCOL=https
COMPANION_DATADIR=/mnt/uppy-server-data
Expand Down
43 changes: 25 additions & 18 deletions packages/@uppy/companion/src/standalone/index.js
Expand Up @@ -25,19 +25,22 @@ function server (moreCompanionOptions = {}) {
const app = express()

// for server metrics tracking.
const metricsMiddleware = promBundle({ includeMethod: true })
const promClient = metricsMiddleware.promClient
const collectDefaultMetrics = promClient.collectDefaultMetrics
const promInterval = collectDefaultMetrics({ register: promClient.register, timeout: 5000 })

// Add version as a prometheus gauge
const versionGauge = new promClient.Gauge({ name: 'companion_version', help: 'npm version as an integer' })
// @ts-ignore
const numberVersion = version.replace(/\D/g, '') * 1
versionGauge.set(numberVersion)

if (app.get('env') !== 'test') {
clearInterval(promInterval)
let metricsMiddleware
if (process.env.COMPANION_HIDE_METRICS !== 'true') {
metricsMiddleware = promBundle({ includeMethod: true })
const promClient = metricsMiddleware.promClient
const collectDefaultMetrics = promClient.collectDefaultMetrics
const promInterval = collectDefaultMetrics({ register: promClient.register, timeout: 5000 })

// Add version as a prometheus gauge
const versionGauge = new promClient.Gauge({ name: 'companion_version', help: 'npm version as an integer' })
// @ts-ignore
const numberVersion = version.replace(/\D/g, '') * 1
versionGauge.set(numberVersion)

if (app.get('env') !== 'test') {
clearInterval(promInterval)
}
}

// Query string keys whose values should not end up in logging output.
Expand Down Expand Up @@ -94,7 +97,9 @@ function server (moreCompanionOptions = {}) {
})

// make app metrics available at '/metrics'.
app.use(metricsMiddleware)
if (process.env.COMPANION_HIDE_METRICS !== 'true') {
app.use(metricsMiddleware)
}

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
Expand Down Expand Up @@ -163,10 +168,12 @@ function server (moreCompanionOptions = {}) {
})

// Routes
app.get('/', (req, res) => {
res.setHeader('Content-Type', 'text/plain')
res.send(helper.buildHelpfulStartupMessage(companionOptions))
})
if (process.env.COMPANION_HIDE_WELCOME !== 'true') {
app.get('/', (req, res) => {
res.setHeader('Content-Type', 'text/plain')
res.send(helper.buildHelpfulStartupMessage(companionOptions))
})
}

let companionApp
try {
Expand Down
4 changes: 4 additions & 0 deletions website/src/docs/companion.md
Expand Up @@ -150,6 +150,10 @@ export COMPANION_PROTOCOL="YOUR SERVER PROTOCOL"
export COMPANION_PORT="YOUR SERVER PORT"
# corresponds to the server.port option, defaults to ''
export COMPANION_PATH="/SERVER/PATH/TO/WHERE/COMPANION/LIVES"
# disables the welcome page, defaults to false
export COMPANION_HIDE_WELCOME="true"
# disables the metrics page, defaults to false
export COMPANION_HIDE_METRICS="true"

# use this in place of COMPANION_PATH if the server path should not be
# handled by the express.js app, but maybe by an external server configuration
Expand Down