Skip to content

Commit

Permalink
Merge pull request #43 from OHaganA/master
Browse files Browse the repository at this point in the history
allow healthchecks to be aware of collector object
  • Loading branch information
Aaron O'Hagan authored Mar 12, 2020
2 parents 843e112 + ec52b8c commit 24e6e28
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 77 deletions.
58 changes: 55 additions & 3 deletions al_aws_collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const deepEqual = require('deep-equal');
const m_alCollector = require('@alertlogic/al-collector-js');
const m_alAws = require('./al_aws');
const m_healthChecks = require('./health_checks');
const m_stats = require('./statistics');
const m_alStatsTmpls = require('./statistics_templates');

var AIMS_DECRYPTED_CREDS = null;

Expand Down Expand Up @@ -255,12 +255,12 @@ class AlAwsCollector {
//it is assumed that all functions here always return err != null
async.parallel([
function(asyncCallback) {
m_healthChecks.getHealthStatus(context, checks, function(err, healthStatus) {
collector.getHealthStatus(context, checks, function(err, healthStatus) {
return asyncCallback(null, healthStatus);
});
},
function(asyncCallback) {
m_stats.getStatistics(context, statsFuns, function(err, statistics) {
collector.getStatistics(context, statsFuns, function(err, statistics) {
return asyncCallback(null, statistics);
});
}
Expand All @@ -285,6 +285,58 @@ class AlAwsCollector {
});
}

getHealthStatus(context, customChecks, callback) {
const appliedHealthChecks = customChecks.map(check => check.bind(this));
async.parallel([
function(asyncCallback) {
m_healthChecks.checkCloudFormationStatus(process.env.stack_name, asyncCallback);
}
].concat(appliedHealthChecks),
function(errMsg) {
var status = {};
if (errMsg) {
console.warn('ALAWS00001 Health check failed with', errMsg);
status = {
status: errMsg.status,
error_code: errMsg.code,
details: [errMsg.details]
};
} else {
status = {
status: 'ok',
details: []
};
}
return callback(null, status);
});
}

getStatistics(context, statsFuns, callback) {
const appliedStatsFuns = statsFuns.map(fun => fun.bind(this));
var allFuns = [
function(asyncCallback) {
return m_alStatsTmpls.getLambdaMetrics(
context.functionName, 'Invocations', asyncCallback
);
},
function(asyncCallback) {
return m_alStatsTmpls.getLambdaMetrics(
context.functionName, 'Errors', asyncCallback
);
}
].concat(appliedStatsFuns);
async.parallel(allFuns,
function(err, res) {
if (err) {
return callback(null, {statistics : []});
} else {
return callback(null, {statistics : res});
}
}
);
}


deregister(event, custom){
const context = this._invokeContext;
let regValues = Object.assign(this.getProperties(), custom);
Expand Down
32 changes: 3 additions & 29 deletions health_checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

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


/**
Expand Down Expand Up @@ -50,31 +49,6 @@ function checkCloudFormationStatus(stackName, callback) {
});
}

function getHealthStatus(context, customChecks, callback) {
async.parallel([
function(asyncCallback) {
checkCloudFormationStatus(process.env.stack_name, asyncCallback);
}
].concat(customChecks),
function(errMsg) {
var status = {};
if (errMsg) {
console.warn('ALAWS00001 Health check failed with', errMsg);
status = {
status: errMsg.status,
error_code: errMsg.code,
details: [errMsg.details]
};
} else {
status = {
status: 'ok',
details: []
};
}
return callback(null, status);
});
}


function stringify(jsonObj) {
return JSON.stringify(jsonObj, null, 0);
Expand Down Expand Up @@ -107,6 +81,6 @@ function errorMsg(code, message) {
}

module.exports = {
getHealthStatus : getHealthStatus,
errorMsg : errorMsg
};
errorMsg : errorMsg,
checkCloudFormationStatus : checkCloudFormationStatus
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alertlogic/al-aws-collector-js",
"version": "2.0.6",
"version": "2.0.7",
"license": "MIT",
"description": "Alert Logic AWS Collector Common Library",
"repository": {
Expand Down
44 changes: 0 additions & 44 deletions statistics.js

This file was deleted.

0 comments on commit 24e6e28

Please sign in to comment.