express-service-readiness-middleware
Advanced tools
Comparing version 1.0.20 to 1.0.21
@@ -15,4 +15,4 @@ import { NextFunction, Request, Response } from "express"; | ||
whitelistedPaths?: string[]; | ||
/** indicates whether critical dependency information should be logged out if critical dependencies fail to become ready */ | ||
logOutCriticalDependenciesOnFailure?: boolean; | ||
/** indicates whether dependency information should be logged out if dependencies fail to become ready */ | ||
logOutDependenciesDataOnFailure?: boolean; | ||
} | ||
@@ -19,0 +19,0 @@ /** Dependency interface */ |
@@ -8,3 +8,3 @@ "use strict"; | ||
whitelistedPaths: [], | ||
logOutCriticalDependenciesOnFailure: true | ||
logOutDependenciesDataOnFailure: false | ||
}; | ||
@@ -15,2 +15,3 @@ const dependencyStateItems = []; | ||
let maximumWaitTimeTimeout; | ||
let serviceConfiguration = undefined; | ||
/** | ||
@@ -28,2 +29,3 @@ * Creates the service readiness middleware | ||
}); | ||
serviceConfiguration = configuration; | ||
checkServiceReadiness(dependencies, configuration); | ||
@@ -113,7 +115,7 @@ let pathsToWhitelist = []; | ||
healthy = await healthyFunc(); | ||
informationLogger?.log(`critical dependency '${dependency.name}' is ${healthy ? 'healthy' : 'not healthy'}`); | ||
informationLogger?.log(`dependency '${dependency.name}' is ${healthy ? 'healthy' : 'not healthy'}${!healthy && serviceConfiguration?.logOutDependenciesDataOnFailure ? ', data: ' + JSON.stringify(dependency.data) : ''}`); | ||
} | ||
catch (err) { | ||
// @ts-ignore | ||
informationLogger?.log(`An error occurred while checking health for dependency '${dependency.name}', error: ${err.message || err}`); | ||
informationLogger?.log(`An error occurred while checking health for dependency '${dependency.name}'${serviceConfiguration?.logOutDependenciesDataOnFailure ? ', data: ' + JSON.stringify(dependency.data) : ''}, error: ${err.message || err}`); | ||
} | ||
@@ -134,3 +136,3 @@ return healthy; | ||
if (informationLogger) { | ||
const suffix = config.logOutCriticalDependenciesOnFailure === true ? ` Critical dependencies: ${JSON.stringify(items)}` : ''; | ||
const suffix = config.logOutDependenciesDataOnFailure === true ? ` Critical dependencies: ${JSON.stringify(items)}` : ''; | ||
informationLogger?.log(`All critical dependencies did not become healthy.${suffix}`); | ||
@@ -184,7 +186,7 @@ } | ||
} | ||
informationLogger?.log(`critical dependency '${dependencyStateItem.name}' is not ready yet`); | ||
informationLogger?.log(`critical dependency '${dependencyStateItem.name}' is not ready yet${serviceConfiguration.logOutDependenciesDataOnFailure ? ', data: ' + JSON.stringify(dependencyStateItem.data) : ''}`); | ||
} | ||
catch (err) { | ||
// @ts-ignore | ||
informationLogger?.log(`An error occurred while checking health for critical dependency '${dependencyStateItem.name}', error: ${err.message || err}`); | ||
informationLogger?.log(`An error occurred while checking health for critical dependency '${dependencyStateItem.name}'${serviceConfiguration.logOutDependenciesDataOnFailure ? ', data: ' + JSON.stringify(dependencyStateItem.data) : ''}, error: ${err.message || err}`); | ||
} | ||
@@ -191,0 +193,0 @@ const checkHealthAgain = () => checkDependencyReadiness(dependencyStateItem); |
{ | ||
"name": "express-service-readiness-middleware", | ||
"version": "1.0.20", | ||
"version": "1.0.21", | ||
"description": "This module provides express middleware for determining whether routes are exposed based on service critical dependency health.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -100,3 +100,3 @@ | ||
- `whitelistedPaths`: (default: `[]`) Paths to still route traffic to even if dependencies are not yet ready. | ||
- `logOutCriticalDependenciesOnFailure`: (default: `true`) Indicates whether critical dependency information should be logged out if critical dependencies fail to become ready | ||
- `logOutDependenciesDataOnFailure`: (default: `false`) Indicates whether dependency information should be logged out if dependencies fail to become ready. | ||
@@ -103,0 +103,0 @@ ## checkDependenciesHealth |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25152
281