Skip to content

Commit 59af678

Browse files
chore: preemptivly reduce the cost to store the responses by lowering the limit and changing the on disk compression format (#6691)
1 parent 751fe1b commit 59af678

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

db/knex_migrations/2025-10-15-0001-add-monitor-response-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ exports.up = function (knex) {
22
return knex.schema.alterTable("monitor", function (table) {
33
table.boolean("save_response").notNullable().defaultTo(false);
44
table.boolean("save_error_response").notNullable().defaultTo(true);
5-
table.integer("response_max_length").notNullable().defaultTo(10240); // Default 10KB
5+
table.integer("response_max_length").notNullable().defaultTo(1024); // Default 1KB
66
});
77
};
88

server/model/heartbeat.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { BeanModel } = require("redbean-node/dist/bean-model");
22
const zlib = require("node:zlib");
33
const { promisify } = require("node:util");
4-
const gunzip = promisify(zlib.gunzip);
4+
const brotliDecompress = promisify(zlib.brotliDecompress);
55

66
/**
77
* status:
@@ -73,8 +73,8 @@ class Heartbeat extends BeanModel {
7373
}
7474

7575
try {
76-
// Offload gzip decode from main event loop to libuv thread pool
77-
return (await gunzip(Buffer.from(response, "base64"))).toString("utf8");
76+
// Offload brotli decode from main event loop to libuv thread pool
77+
return (await brotliDecompress(Buffer.from(response, "base64"))).toString("utf8");
7878
} catch (error) {
7979
return response;
8080
}

server/model/monitor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const https = require("https");
6060
const http = require("http");
6161
const zlib = require("node:zlib");
6262
const { promisify } = require("node:util");
63-
const gzip = promisify(zlib.gzip);
63+
const brotliCompress = promisify(zlib.brotliCompress);
6464
const DomainExpiry = require("./domain_expiry");
6565

6666
const rootCertificates = rootCertificatesFingerprints();
@@ -1174,8 +1174,8 @@ class Monitor extends BeanModel {
11741174
responseData = responseData.substring(0, maxSize) + "... (truncated)";
11751175
}
11761176

1177-
// Offload gzip compression from main event loop to libuv thread pool
1178-
bean.response = (await gzip(Buffer.from(responseData, "utf8"))).toString("base64");
1177+
// Offload brotli compression from main event loop to libuv thread pool
1178+
bean.response = (await brotliCompress(Buffer.from(responseData, "utf8"))).toString("base64");
11791179
}
11801180

11811181
/**

src/lang/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"saveErrorResponseForNotifications": "Save HTTP Error Response for Notifications",
105105
"saveResponseDescription": "Stores the HTTP response and makes it available to notification templates as {templateVariable}",
106106
"responseMaxLength": "Response Max Length (bytes)",
107-
"responseMaxLengthDescription": "Maximum size of response data to store. Set to 0 for unlimited. Larger responses will be truncated. Default: 10240 (10KB)",
107+
"responseMaxLengthDescription": "Maximum size of response data to store. Set to 0 for unlimited. Larger responses will be truncated. Default: 1024 (1KB)",
108108
"Accepted Status Codes": "Accepted Status Codes",
109109
"Push URL": "Push URL",
110110
"needPushEvery": "You should call this URL every {0} seconds.",

src/pages/EditMonitor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,7 @@ const monitorDefaults = {
22692269
accepted_statuscodes: ["200-299"],
22702270
saveResponse: false,
22712271
saveErrorResponse: true,
2272-
responseMaxLength: 10240,
2272+
responseMaxLength: 1024,
22732273
dns_resolve_type: "A",
22742274
dns_resolve_server: "1.1.1.1",
22752275
docker_container: "",

src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ exports.PING_COUNT_DEFAULT = 1;
4343
exports.PING_PER_REQUEST_TIMEOUT_MIN = 1;
4444
exports.PING_PER_REQUEST_TIMEOUT_MAX = 60;
4545
exports.PING_PER_REQUEST_TIMEOUT_DEFAULT = 2;
46-
exports.RESPONSE_BODY_LENGTH_DEFAULT = 1024 * 10;
46+
exports.RESPONSE_BODY_LENGTH_DEFAULT = 1024;
4747
exports.RESPONSE_BODY_LENGTH_MAX = 1024 * 1024;
4848
exports.CONSOLE_STYLE_Reset = "\x1b[0m";
4949
exports.CONSOLE_STYLE_Bright = "\x1b[1m";

src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const PING_PER_REQUEST_TIMEOUT_DEFAULT = 2;
7070
* Response body length cutoff used by default (10kb)
7171
* (measured in bytes)
7272
*/
73-
export const RESPONSE_BODY_LENGTH_DEFAULT = 1024 * 10;
73+
export const RESPONSE_BODY_LENGTH_DEFAULT = 1024;
7474
/**
7575
* Maximum allowed response body length to store (1mb)
7676
* (measured in bytes)

0 commit comments

Comments
 (0)