Skip to content

Commit 24e6e28

Browse files
author
Aaron O'Hagan
authored
Merge pull request #43 from OHaganA/master
allow healthchecks to be aware of collector object
2 parents 843e112 + ec52b8c commit 24e6e28

File tree

4 files changed

+59
-77
lines changed

4 files changed

+59
-77
lines changed

al_aws_collector.js

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const deepEqual = require('deep-equal');
2121
const m_alCollector = require('@alertlogic/al-collector-js');
2222
const m_alAws = require('./al_aws');
2323
const m_healthChecks = require('./health_checks');
24-
const m_stats = require('./statistics');
24+
const m_alStatsTmpls = require('./statistics_templates');
2525

2626
var AIMS_DECRYPTED_CREDS = null;
2727

@@ -255,12 +255,12 @@ class AlAwsCollector {
255255
//it is assumed that all functions here always return err != null
256256
async.parallel([
257257
function(asyncCallback) {
258-
m_healthChecks.getHealthStatus(context, checks, function(err, healthStatus) {
258+
collector.getHealthStatus(context, checks, function(err, healthStatus) {
259259
return asyncCallback(null, healthStatus);
260260
});
261261
},
262262
function(asyncCallback) {
263-
m_stats.getStatistics(context, statsFuns, function(err, statistics) {
263+
collector.getStatistics(context, statsFuns, function(err, statistics) {
264264
return asyncCallback(null, statistics);
265265
});
266266
}
@@ -285,6 +285,58 @@ class AlAwsCollector {
285285
});
286286
}
287287

288+
getHealthStatus(context, customChecks, callback) {
289+
const appliedHealthChecks = customChecks.map(check => check.bind(this));
290+
async.parallel([
291+
function(asyncCallback) {
292+
m_healthChecks.checkCloudFormationStatus(process.env.stack_name, asyncCallback);
293+
}
294+
].concat(appliedHealthChecks),
295+
function(errMsg) {
296+
var status = {};
297+
if (errMsg) {
298+
console.warn('ALAWS00001 Health check failed with', errMsg);
299+
status = {
300+
status: errMsg.status,
301+
error_code: errMsg.code,
302+
details: [errMsg.details]
303+
};
304+
} else {
305+
status = {
306+
status: 'ok',
307+
details: []
308+
};
309+
}
310+
return callback(null, status);
311+
});
312+
}
313+
314+
getStatistics(context, statsFuns, callback) {
315+
const appliedStatsFuns = statsFuns.map(fun => fun.bind(this));
316+
var allFuns = [
317+
function(asyncCallback) {
318+
return m_alStatsTmpls.getLambdaMetrics(
319+
context.functionName, 'Invocations', asyncCallback
320+
);
321+
},
322+
function(asyncCallback) {
323+
return m_alStatsTmpls.getLambdaMetrics(
324+
context.functionName, 'Errors', asyncCallback
325+
);
326+
}
327+
].concat(appliedStatsFuns);
328+
async.parallel(allFuns,
329+
function(err, res) {
330+
if (err) {
331+
return callback(null, {statistics : []});
332+
} else {
333+
return callback(null, {statistics : res});
334+
}
335+
}
336+
);
337+
}
338+
339+
288340
deregister(event, custom){
289341
const context = this._invokeContext;
290342
let regValues = Object.assign(this.getProperties(), custom);

health_checks.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010

1111
const AWS = require('aws-sdk');
12-
const async = require('async');
1312

1413

1514
/**
@@ -50,31 +49,6 @@ function checkCloudFormationStatus(stackName, callback) {
5049
});
5150
}
5251

53-
function getHealthStatus(context, customChecks, callback) {
54-
async.parallel([
55-
function(asyncCallback) {
56-
checkCloudFormationStatus(process.env.stack_name, asyncCallback);
57-
}
58-
].concat(customChecks),
59-
function(errMsg) {
60-
var status = {};
61-
if (errMsg) {
62-
console.warn('ALAWS00001 Health check failed with', errMsg);
63-
status = {
64-
status: errMsg.status,
65-
error_code: errMsg.code,
66-
details: [errMsg.details]
67-
};
68-
} else {
69-
status = {
70-
status: 'ok',
71-
details: []
72-
};
73-
}
74-
return callback(null, status);
75-
});
76-
}
77-
7852

7953
function stringify(jsonObj) {
8054
return JSON.stringify(jsonObj, null, 0);
@@ -107,6 +81,6 @@ function errorMsg(code, message) {
10781
}
10882

10983
module.exports = {
110-
getHealthStatus : getHealthStatus,
111-
errorMsg : errorMsg
112-
};
84+
errorMsg : errorMsg,
85+
checkCloudFormationStatus : checkCloudFormationStatus
86+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alertlogic/al-aws-collector-js",
3-
"version": "2.0.6",
3+
"version": "2.0.7",
44
"license": "MIT",
55
"description": "Alert Logic AWS Collector Common Library",
66
"repository": {

statistics.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)