Address code review feedback: fix typo and prevent overlapping executions

- Fix spelling: 'retrived' -> 'retrieved' in proxysessionmetrics.js
- Add flag to prevent overlapping health check executions
- Change back to sequential server processing to avoid overwhelming Sense servers
- Add warning log when skipping intervals due to long-running health checks

Co-authored-by: mountaindude <1029262+mountaindude@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-18 06:14:27 +00:00
parent c444156871
commit 17f20985ca
2 changed files with 35 additions and 20 deletions

View File

@@ -156,35 +156,50 @@ export async function getHealthStatsFromSense(serverName, host, tags, headers, r
* *
* This function creates an interval that runs every pollingInterval milliseconds (as defined in config) * This function creates an interval that runs every pollingInterval milliseconds (as defined in config)
* and calls getHealthStatsFromSense for each server in the serverList global variable. * and calls getHealthStatsFromSense for each server in the serverList global variable.
* Uses a flag to prevent overlapping executions if health checks take longer than the polling interval.
* *
* @returns {void} * @returns {void}
*/ */
export function setupHealthMetricsTimer() { export function setupHealthMetricsTimer() {
let isCollecting = false;
// Configure timer for getting healthcheck data // Configure timer for getting healthcheck data
setInterval(async () => { setInterval(async () => {
globals.logger.verbose('HEALTH: Event started: Statistics collection'); // Prevent overlapping executions
if (isCollecting) {
globals.logger.warn(
'HEALTH: Previous health check collection still in progress, skipping this interval'
);
return;
}
// Process all servers concurrently with error handling isCollecting = true;
const healthCheckPromises = globals.serverList.map(async (server) => { try {
try { globals.logger.verbose('HEALTH: Event started: Statistics collection');
globals.logger.verbose(`HEALTH: Getting stats for server: ${server.serverName}`);
globals.logger.debug(`HEALTH: Server details: ${JSON.stringify(server)}`);
// Get per-server tags // Process servers sequentially to avoid overwhelming the Sense servers
const tags = getServerTags(globals.logger, server); for (const server of globals.serverList) {
try {
globals.logger.verbose(
`HEALTH: Getting stats for server: ${server.serverName}`
);
globals.logger.debug(`HEALTH: Server details: ${JSON.stringify(server)}`);
// Get per-server headers // Get per-server tags
const headers = getServerHeaders(server); const tags = getServerTags(globals.logger, server);
await getHealthStatsFromSense(server.serverName, server.host, tags, headers); // Get per-server headers
} catch (err) { const headers = getServerHeaders(server);
globals.logger.error(
`HEALTH: Unexpected error processing health stats for server '${server.serverName}': ${globals.getErrorMessage(err)}` await getHealthStatsFromSense(server.serverName, server.host, tags, headers);
); } catch (err) {
globals.logger.error(
`HEALTH: Unexpected error processing health stats for server '${server.serverName}': ${globals.getErrorMessage(err)}`
);
}
} }
}); } finally {
isCollecting = false;
// Wait for all health checks to complete }
await Promise.allSettled(healthCheckPromises);
}, globals.config.get('Butler-SOS.serversToMonitor.pollingInterval')); }, globals.config.get('Butler-SOS.serversToMonitor.pollingInterval'));
} }

View File

@@ -222,7 +222,7 @@ export async function getProxySessionStatsFromSense(
influxTags, influxTags,
retryCount = 0 retryCount = 0
) { ) {
// Current user sessions are retrived using this API: // Current user sessions are retrieved using this API:
// https://help.qlik.com/en-US/sense-developer/February2021/Subsystems/ProxyServiceAPI/Content/Sense_ProxyServiceAPI/ProxyServiceAPI-Proxy-API.htm // https://help.qlik.com/en-US/sense-developer/February2021/Subsystems/ProxyServiceAPI/Content/Sense_ProxyServiceAPI/ProxyServiceAPI-Proxy-API.htm
// Get certificate configuration options // Get certificate configuration options