Socket
Socket
Sign inDemoInstall

airlock

Package Overview
Dependencies
0
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc