Add limit and order to query log request

Add optional limit to the number of log records to return in the
log query request to avoid having the web interface instance console
download the entire log for only to show a few hundred lines from it.

To make it possible to query the end of the log instead of just the
start add an order option as well.
This commit is contained in:
Hornwitser committed 2021-09-11 19:11:30 +02:00
1 parent 9aebeeac02
commit e3d8aa1a9b
5 files changed
+53 -2

No files matched your search

+8
View File
@@ -819,6 +819,8 @@ logCommands.add(new libCommand.Command({
"slave": { describe: "Query log of given slave", nargs: 1, type: "string", default: null },
"instance": { describe: "Query log of given instance", nargs: 1, type: "string", default: null },
"max-level": { describe: "Maximum log level to return", nargs: 1, type: "string", default: null },
"limit": { describe: "Max number of entries to return", nargs: 1, type: "number", default: 1000 },
"start": { describe: "Limit from the start instead of the end", nargs: 0, type: "boolean", default: false },
});
}],
handler: async function(args, control) {
@@ -835,8 +837,14 @@ logCommands.add(new libCommand.Command({
slave_ids,
instance_ids,
max_level: args.maxLevel,
limit: args.limit,
order: args.start ? "asc" : "desc",
});
if (!args.start) {
result.log.reverse();
}
let stdoutLogger = winston.createLogger({
level: "verbose",
levels,
+2
View File
@@ -859,6 +859,8 @@ messages.queryLog = new Request({
items: { type: "integer" },
},
"max_level": { type: ["string", "null"] },
"limit": { type: "integer" },
"order": { enum: ["asc", "desc"] },
},
responseProperties: {
"log": {
+4 -1
View File
@@ -456,12 +456,15 @@ class ControlConnection extends BaseConnection {
// - The log file is read starting from the beginning
let setDuration = lastQueryLogTime.startTimer();
let log = await query({
order: "asc",
order: message.data.order,
limit: Infinity,
from: new Date(0),
});
log = log.filter(this.constructor.logFilter(message.data));
if (message.data.limit) {
log = log.slice(0, message.data.limit);
}
setDuration();
return { log };
}
@@ -65,8 +65,10 @@ export default function InstanceConsole(props) {
slave_ids: [],
instance_ids: [props.id],
max_level: null,
limit: 400,
order: "desc",
}).then(result => {
setPastLines(result.log.slice(-400).map((info, index) => formatLog(info, index)));
setPastLines(result.log.map((info, index) => formatLog(info, index)).reverse());
}).catch(err => {
setPastLines([<span key={0}>{`Error loading log: ${err.message}`}<br/></span>]);
});
+36
View File
@@ -62,6 +62,42 @@ describe("Integration of Clusterio", function() {
await connectorB.close(1000, "");
});
});
describe("queryLogRequestHandler", function() {
it("should honnor the limit", async function() {
let result = await libLink.messages.queryLog.send(getControl(), {
all: true,
master: false,
slave_ids: [],
instance_ids: [],
max_level: null,
limit: 10,
order: "asc",
});
assert.equal(result.log.length, 10);
});
it("should return entries by order", async function() {
let first = await libLink.messages.queryLog.send(getControl(), {
all: true,
master: false,
slave_ids: [],
instance_ids: [],
max_level: null,
limit: 1,
order: "asc",
});
let last = await libLink.messages.queryLog.send(getControl(), {
all: true,
master: false,
slave_ids: [],
instance_ids: [],
max_level: null,
limit: 1,
order: "desc",
});
assert(first.log[0].timestamp < last.log[0].timestamp, "first log entry happened after last");
});
});
});
describe("clusterioslave", function() {