From 143864b8d95314f82b55d0f6468b3f0fa209d271 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Sun, 4 Jun 2023 20:46:59 +0200 Subject: [PATCH] enhancement(metrics): allow disabling via config option Signed-off-by: Erik Michelson --- app.js | 6 ++++-- docs/content/configuration.md | 15 ++++++++------- lib/config/default.js | 3 ++- lib/config/environment.js | 3 ++- lib/web/statusRouter.js | 3 +++ public/docs/release-notes.md | 1 + 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index 050970b35..f40358981 100644 --- a/app.js +++ b/app.js @@ -75,8 +75,10 @@ app.use(morgan('combined', { })) // Register prometheus metrics endpoint -app.use(apiMetrics()) -metrics.setupCustomPrometheusMetrics() +if (config.enableStatsApi) { + app.use(apiMetrics()) + metrics.setupCustomPrometheusMetrics() +} // socket io const io = require('socket.io')(server, { cookie: false }) diff --git a/docs/content/configuration.md b/docs/content/configuration.md index 67b71e4e8..7a955fabe 100644 --- a/docs/content/configuration.md +++ b/docs/content/configuration.md @@ -21,15 +21,15 @@ to `config.json` before filling in your own details. ## HedgeDoc basics | config file | environment | **default** and example value | description | -| -------------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +|----------------------|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | | `CMD_CONFIG_FILE` | **no default**, `/path/to/config.json` | optional override for the path to HedgeDoc's config file | | `db` | | **`undefined`**, `{ "dialect": "sqlite", "storage": "./db.hedgedoc.sqlite" }` | set the db configs, [see more here](https://sequelize.org/v5/manual/dialects.html) | -| `db.username` | `CMD_DB_USERNAME` | **`undefined`**, `hedgedoc-db-user` | Username used to authenticate to the database (host). | -| `db.password` | `CMD_DB_PASSWORD` | **`undefined`** | Password used to authenticate to the database (host). | -| `db.database` | `CMD_DB_DATABASE` | **`undefined`**, `hedgedoc` | Name of the database used to store hedgedoc data. | -| `db.host` | `CMD_DB_HOST` | **`undefined`**, `db-host.example.com` | Hostname used to connect the database server. | -| `db.post` | `CMD_DB_PORT` | **`undefined`**, `5432` | Port used to connect the database server. | -| `db.dialect` | `CMD_DB_DIALECT` | **`undefined`**, `postgres`, `mariadb` | [Dialect](https://sequelize.org/v5/manual/dialects.html) / protocol used to connect to the database. | +| `db.username` | `CMD_DB_USERNAME` | **`undefined`**, `hedgedoc-db-user` | Username used to authenticate to the database (host). | +| `db.password` | `CMD_DB_PASSWORD` | **`undefined`** | Password used to authenticate to the database (host). | +| `db.database` | `CMD_DB_DATABASE` | **`undefined`**, `hedgedoc` | Name of the database used to store hedgedoc data. | +| `db.host` | `CMD_DB_HOST` | **`undefined`**, `db-host.example.com` | Hostname used to connect the database server. | +| `db.post` | `CMD_DB_PORT` | **`undefined`**, `5432` | Port used to connect the database server. | +| `db.dialect` | `CMD_DB_DIALECT` | **`undefined`**, `postgres`, `mariadb` | [Dialect](https://sequelize.org/v5/manual/dialects.html) / protocol used to connect to the database. | | `dbURL` | `CMD_DB_URL` | **`undefined`**, `postgres://username:password@localhost:5432/hedgedoc` or `mysql://username:password@localhost:3306/hedgedoc` | Set the db in URL style. If set, then the relevant `db` config entries will be overridden. | | `loglevel` | `CMD_LOGLEVEL` | **`info`**, `debug` ... | Defines what kind of logs are provided to stdout. Available options: `debug`, `verbose`, `info`, `warn`, `error` | | `forbiddenNoteIDs` | `CMD_FORBIDDEN_NOTE_IDS` | **`['robots.txt', 'favicon.ico', 'api', 'build', 'css', 'docs', 'fonts', 'js', 'uploads', 'vendor', 'views']`**, `['robots.txt']` or `'robots.txt'` | disallow creation of notes, even if `allowFreeUrl` or `CMD_ALLOW_FREEURL` is `true` | @@ -41,6 +41,7 @@ to `config.json` before filling in your own details. | `heartbeatTimeout` | | **`10000`** | socket.io heartbeat timeout | | `documentMaxLength` | `CMD_DOCUMENT_MAX_LENGTH` | **`100000`** | note max length | | `linkifyHeaderStyle` | | **`keep-case`**, `lower-case`, `gfm` | how is a header text converted into a link id | +| `enableStatsApi` | `CMD_ENABLE_STATS_API` | **`true`**, `false` | Enables or disables the /status and /metrics endpoint. | ## HedgeDoc paths stuff diff --git a/lib/config/default.js b/lib/config/default.js index 88cc63069..f7df8f99e 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -179,5 +179,6 @@ module.exports = { // Generated id: "31-good-morning-my-friend---do-you-have-5" // 2nd appearance: "31-good-morning-my-friend---do-you-have-5-1" // 3rd appearance: "31-good-morning-my-friend---do-you-have-5-2" - linkifyHeaderStyle: 'keep-case' + linkifyHeaderStyle: 'keep-case', + enableStatsApi: true } diff --git a/lib/config/environment.js b/lib/config/environment.js index 4a621dae5..31f3c6fc5 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -157,5 +157,6 @@ module.exports = { allowEmailRegister: toBooleanConfig(process.env.CMD_ALLOW_EMAIL_REGISTER), allowGravatar: toBooleanConfig(process.env.CMD_ALLOW_GRAVATAR), openID: toBooleanConfig(process.env.CMD_OPENID), - linkifyHeaderStyle: process.env.CMD_LINKIFY_HEADER_STYLE + linkifyHeaderStyle: process.env.CMD_LINKIFY_HEADER_STYLE, + enableStatsApi: toBooleanConfig(process.env.CMD_ENABLE_STATS_API) } diff --git a/lib/web/statusRouter.js b/lib/web/statusRouter.js index 3f49b211a..a807eee24 100644 --- a/lib/web/statusRouter.js +++ b/lib/web/statusRouter.js @@ -24,6 +24,9 @@ statusRouter.get('/_health', function (req, res) { // get status statusRouter.get('/status', function (req, res, next) { + if (!config.enableStatsApi) { + return errors.errorForbidden(res) + } realtime.getStatus(function (data) { res.set({ 'Cache-Control': 'private', // only cache by client diff --git a/public/docs/release-notes.md b/public/docs/release-notes.md index 7fe84ad59..0966f8827 100644 --- a/public/docs/release-notes.md +++ b/public/docs/release-notes.md @@ -15,6 +15,7 @@ special actions. - Add dedicated healthcheck endpoint at /_health that is less resource intensive than /status. - Compatibility with Node.js 18 and later - Add support for the arm64 architecture in the docker image +- Add a config option to disable the `/status` and `/metrics` endpoints ### Bugfixes - Fix that permission errors can break existing connections to a note, causing inconsistent note content and changes not being saved