better logging

This commit is contained in:
Juergen Kunz
2025-07-03 02:32:17 +00:00
parent 67aff4bb30
commit 5d011ba84c
18 changed files with 1604 additions and 410 deletions

View File

@ -1,6 +1,7 @@
import * as plugins from '../../plugins.js';
import type { IConnectionRecord, ISmartProxyOptions } from './models/interfaces.js';
import { logger } from '../../core/utils/logger.js';
import { connectionLogDeduplicator } from '../../core/utils/log-deduplicator.js';
// Route checking functions have been removed
import type { IRouteConfig, IRouteAction } from './models/route-types.js';
import type { IRouteContext } from '../../core/models/route-context.js';
@ -563,12 +564,20 @@ export class RouteConnectionHandler {
);
if (!isIPAllowed) {
logger.log('warn', `IP ${remoteIP} blocked by route security for route ${route.name || 'unnamed'} (connection: ${connectionId})`, {
connectionId,
remoteIP,
routeName: route.name || 'unnamed',
component: 'route-handler'
});
// Deduplicated logging for route IP blocks
connectionLogDeduplicator.log(
'ip-rejected',
'warn',
`IP blocked by route security`,
{
connectionId,
remoteIP,
routeName: route.name || 'unnamed',
reason: 'route-ip-blocked',
component: 'route-handler'
},
remoteIP
);
socket.end();
this.smartProxy.connectionManager.cleanupConnection(record, 'route_ip_blocked');
return;
@ -577,14 +586,28 @@ export class RouteConnectionHandler {
// Check max connections per route
if (route.security.maxConnections !== undefined) {
// TODO: Implement per-route connection tracking
// For now, log that this feature is not yet implemented
if (this.smartProxy.settings.enableDetailedLogging) {
logger.log('warn', `Route ${route.name} has maxConnections=${route.security.maxConnections} configured but per-route connection limits are not yet implemented`, {
connectionId,
routeName: route.name,
component: 'route-handler'
});
const routeId = route.id || route.name || 'unnamed';
const currentConnections = this.smartProxy.connectionManager.getConnectionCountByRoute(routeId);
if (currentConnections >= route.security.maxConnections) {
// Deduplicated logging for route connection limits
connectionLogDeduplicator.log(
'connection-rejected',
'warn',
`Route connection limit reached`,
{
connectionId,
routeName: route.name,
currentConnections,
maxConnections: route.security.maxConnections,
reason: 'route-limit',
component: 'route-handler'
},
`route-limit-${route.name}`
);
socket.end();
this.smartProxy.connectionManager.cleanupConnection(record, 'route_connection_limit');
return;
}
}
@ -642,6 +665,10 @@ export class RouteConnectionHandler {
// Store the route config in the connection record for metrics and other uses
record.routeConfig = route;
record.routeId = route.id || route.name || 'unnamed';
// Track connection by route
this.smartProxy.connectionManager.trackConnectionByRoute(record.routeId, record.id);
// Check if this route uses NFTables for forwarding
if (action.forwardingEngine === 'nftables') {
@ -960,6 +987,10 @@ export class RouteConnectionHandler {
// Store the route config in the connection record for metrics and other uses
record.routeConfig = route;
record.routeId = route.id || route.name || 'unnamed';
// Track connection by route
this.smartProxy.connectionManager.trackConnectionByRoute(record.routeId, record.id);
if (!route.action.socketHandler) {
logger.log('error', 'socket-handler action missing socketHandler function', {