Improve error logging with server details and descriptive messages

- Enhanced error messages in getHealthStatsFromSense() to include server name and host
- Enhanced error messages in getProxySessionStatsFromSense() and related functions to include server, host, and virtual proxy details
- Updated all proxy session error handlers to use globals.getErrorMessage() for consistent formatting
- Fixed related unit tests to expect the new error message formats
- Added missing getErrorMessage mock to proxysessionmetrics tests

Co-authored-by: mountaindude <1029262+mountaindude@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-09-25 07:27:27 +00:00
parent e56656410c
commit 7f0be80539
4 changed files with 13 additions and 6 deletions

View File

@@ -221,7 +221,7 @@ describe('healthmetrics', () => {
// Expectations
expect(axios.request).toHaveBeenCalled();
expect(globals.logger.error).toHaveBeenCalledWith(
expect.stringContaining('HEALTH: Error when calling health check API:')
expect.stringContaining('HEALTH: Error when calling health check API for server \'server1\' (server1.example.com):')
);
// Verify that no metrics were posted

View File

@@ -71,6 +71,7 @@ jest.unstable_mockModule('../../globals.js', () => ({
}),
has: jest.fn().mockReturnValue(true),
},
getErrorMessage: jest.fn().mockImplementation((err) => err.toString()),
serverList: [
{
serverName: 'server1',
@@ -202,7 +203,7 @@ describe('proxysessionmetrics', () => {
// Verify
expect(mockRequest).toHaveBeenCalled();
expect(globals.logger.error).toHaveBeenCalledWith(
expect.stringContaining('Error when calling proxy session API')
expect.stringContaining('PROXY SESSIONS: Error when calling proxy session API for server \'server1\' (host1.example.com), virtual proxy \'vproxy1\':')
);
expect(mockPostProxySessionsToInfluxdb).not.toHaveBeenCalled();
});

View File

@@ -105,7 +105,7 @@ export function getHealthStatsFromSense(serverName, host, tags, headers) {
})
.catch((err) => {
globals.logger.error(
`HEALTH: Error when calling health check API: ${globals.getErrorMessage(err)}`
`HEALTH: Error when calling health check API for server '${serverName}' (${host}): ${globals.getErrorMessage(err)}`
);
});
}

View File

@@ -192,7 +192,9 @@ function prepUserSessionMetrics(serverName, host, virtualProxy, body, tags) {
resolve(userProxySessionsData);
} catch (err) {
globals.logger.error(`PROXY SESSIONS: ${err}`);
globals.logger.error(
`PROXY SESSIONS: Error preparing user session metrics for server '${serverName}' (${host}), virtual proxy '${virtualProxy}': ${globals.getErrorMessage(err)}`
);
reject();
}
});
@@ -314,7 +316,9 @@ export async function getProxySessionStatsFromSense(serverName, host, virtualPro
}
}
} catch (err) {
globals.logger.error(`PROXY SESSIONS: Error when calling proxy session API: ${err}`);
globals.logger.error(
`PROXY SESSIONS: Error when calling proxy session API for server '${serverName}' (${host}), virtual proxy '${virtualProxy}': ${globals.getErrorMessage(err)}`
);
}
}
@@ -361,7 +365,9 @@ export function setupUserSessionsTimer() {
tags
);
} catch (err) {
globals.logger.error(`PROXY SESSIONS: Error getting session stats: ${err}`);
globals.logger.error(
`PROXY SESSIONS: Error getting session stats for server '${server.serverName}' (${server.userSessions.host}), virtual proxy '${virtualProxy.virtualProxy}': ${globals.getErrorMessage(err)}`
);
}
}
}