airlock
Advanced tools
Comparing version 2.1.2 to 2.2.0
11
index.js
@@ -10,2 +10,6 @@ var assert = require('assert'); | ||
maxWaitPeriod: 60 * 1000, | ||
isUnhealthyFunc: function isUnhealthy(err, resp) { | ||
// default is for HTTP, tchannel/other protocal needs to pass in different function | ||
return err || resp && !isNaN(resp.statusCode) && resp.statusCode >= 500; | ||
} | ||
}; | ||
@@ -42,2 +46,5 @@ | ||
this.isUnhealthyFunc = typeof options.isUnhealthyFunc === 'function' || | ||
defaults.isUnhealthyFunc; | ||
if (this.detectFailuresByEvent) { | ||
@@ -115,5 +122,3 @@ if (!options.backend) { | ||
wrappedCallback = function(err, resp) { | ||
var errResponse = resp && !isNaN(resp.statusCode) && | ||
resp.statusCode >= 500; | ||
if (err || errResponse) { | ||
if (self.isUnhealthyFunc(err, resp)) { | ||
self.notok(); | ||
@@ -120,0 +125,0 @@ } else { |
{ | ||
"name": "airlock", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "A prober to probe HTTP based backends for health", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
# airlock | ||
A prober to probe HTTP based backends for health | ||
A prober to probe HTTP, [tchannel](https://github.com/uber/tchannel), or potentially other protocols based backends for health | ||
@@ -5,0 +5,0 @@ ## Example |
@@ -8,2 +8,23 @@ var assert = require('assert'); | ||
var exampleTchannelIsUnhealthyFunc = function isUnhealthy(err, resp) { | ||
if (err) { | ||
// not an exhaustive list, just an example | ||
var serverErrTypes = [ | ||
'tchannel.request.timeout', | ||
'tchannel.connection.close', | ||
'tchannel.connection.reset', | ||
'tchannel.connection.unknown-reset' | ||
]; | ||
return serverErrTypes.indexOf(err.type) !== -1; | ||
} | ||
if (resp) { | ||
// not an exhaustive list, just an example | ||
var respServerErrTypes = [ | ||
'tchannel.busy' | ||
]; | ||
return resp.ok === false && respServerErrTypes.indexOf(resp.type) !== -1; | ||
} | ||
return false; | ||
}; | ||
test('Prober is a function', function (end) { | ||
@@ -215,3 +236,3 @@ assert.equal(typeof Prober, 'function'); | ||
test('should be unhealthy after request server err', function(end) { | ||
test('should be unhealthy after HTTP request server err', function(end) { | ||
var prober = new Prober(); | ||
@@ -231,3 +252,3 @@ prober.threshold = 1; | ||
test('should be healthy after request client err', function(end) { | ||
test('should be healthy after HTTP request client err', function(end) { | ||
var prober = new Prober(); | ||
@@ -247,3 +268,50 @@ prober.threshold = 1; | ||
test('should be healthy after tchannel request server success', function(end) { | ||
var prober = new Prober(); | ||
prober.threshold = 1; | ||
prober.window = 1; | ||
prober.isUnhealthyFunc = exampleTchannelIsUnhealthyFunc; | ||
prober.probe(function(fn) { | ||
fn(null, { | ||
ok: true, | ||
body: {} | ||
}); | ||
}); | ||
assert.ok(prober.isHealthy()); | ||
end(); | ||
}); | ||
test('should be unhealthy after tchannel request server err', function(end) { | ||
var prober = new Prober(); | ||
prober.threshold = 1; | ||
prober.window = 1; | ||
prober.isUnhealthyFunc = exampleTchannelIsUnhealthyFunc; | ||
prober.probe(function(fn) { | ||
fn({ type: 'tchannel.request.timeout' }); | ||
}); | ||
assert.ok(prober.isSick()); | ||
end(); | ||
}); | ||
test('should be unhealthy after tchannel request server err from resp', function(end) { | ||
var prober = new Prober(); | ||
prober.threshold = 1; | ||
prober.window = 1; | ||
prober.isUnhealthyFunc = exampleTchannelIsUnhealthyFunc; | ||
prober.probe(function(fn) { | ||
fn(null, { | ||
ok: false, | ||
type: 'tchannel.busy' | ||
}); | ||
}); | ||
assert.ok(prober.isSick()); | ||
end(); | ||
}); | ||
test('should be healthy after custom handling expected error', function(end) { | ||
@@ -250,0 +318,0 @@ var prober = new Prober(); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
24358
579
1