openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From berst...@apache.org
Subject [incubator-openwhisk-package-cloudant] branch master updated: Add system stats and basic auth to the health endpoint (#105)
Date Mon, 19 Jun 2017 17:25:23 GMT
This is an automated email from the ASF dual-hosted git repository.

berstler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-cloudant.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ad79b1  Add system stats and basic auth to the health endpoint (#105)
6ad79b1 is described below

commit 6ad79b1a4e2723b85b98abeb6d40638f6cba3d7e
Author: Jason Peterson <jasonpet@us.ibm.com>
AuthorDate: Mon Jun 19 13:25:21 2017 -0400

    Add system stats and basic auth to the health endpoint (#105)
    
    * Add system stats and basic auth to the health endpoint
    * get all system stats in parallel
---
 package.json                                       |  4 +--
 provider/app.js                                    |  4 +--
 provider/lib/constants.js                          |  7 +++-
 provider/lib/health.js                             | 37 ++++++++++++++++++----
 provider/lib/utils.js                              |  9 +++---
 .../redundancy/CloudantRedundancyTests.scala       |  2 +-
 6 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/package.json b/package.json
index 7eaeff6..e70f4a6 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,6 @@
   },
   "dependencies": {
     "body-parser": "^1.12.0",
-    "agentkeepalive": "^2.2.0",
     "express": "^4.12.2",
     "winston": "^2.1.1",
     "moment": "^2.11.1",
@@ -18,6 +17,7 @@
     "http-status-codes": "^1.0.5",
     "request-promise": "^1.0.2",
     "redis":"^2.7.1",
-    "bluebird": "^3.5.0"
+    "bluebird": "^3.5.0",
+    "systeminformation": "^3.19.0"
   }
 }
\ No newline at end of file
diff --git a/provider/app.js b/provider/app.js
index 75a8883..8195183 100644
--- a/provider/app.js
+++ b/provider/app.js
@@ -34,7 +34,7 @@ var dbProtocol = process.env.DB_PROTOCOL;
 var dbPrefix = process.env.DB_PREFIX;
 var databaseName = dbPrefix + constants.TRIGGER_DB_SUFFIX;
 var redisUrl = process.env.REDIS_URL;
-var ddname = '_design/triggers';
+var ddname = '_design/' + constants.DESIGN_DOC_NAME;
 
 // Create the Provider Server
 var server = http.createServer(app);
@@ -148,7 +148,7 @@ function init(server) {
             app.get(providerRAS.endPoint, providerRAS.ras);
 
             // Health Endpoint
-            app.get(providerHealth.endPoint, providerHealth.health);
+            app.get(providerHealth.endPoint, providerUtils.authorize, providerHealth.health);
 
             // Activation Endpoint
             app.get(providerActivation.endPoint, providerUtils.authorize, providerActivation.active);
diff --git a/provider/lib/constants.js b/provider/lib/constants.js
index 810ea62..2f2eca1 100644
--- a/provider/lib/constants.js
+++ b/provider/lib/constants.js
@@ -3,11 +3,16 @@ const DEFAULT_MAX_TRIGGERS = -1;
 const RETRY_ATTEMPTS = 12;
 const RETRY_DELAY = 1000; //in milliseconds
 const REDIS_KEY = 'active';
+const DESIGN_DOC_NAME = 'triggers';
+const FILTER_FUNCTION = 'only_triggers_by_worker';
+
 
 module.exports = {
     TRIGGER_DB_SUFFIX: TRIGGER_DB_SUFFIX,
     DEFAULT_MAX_TRIGGERS: DEFAULT_MAX_TRIGGERS,
     RETRY_ATTEMPTS: RETRY_ATTEMPTS,
     RETRY_DELAY: RETRY_DELAY,
-    REDIS_KEY: REDIS_KEY
+    REDIS_KEY: REDIS_KEY,
+    DESIGN_DOC_NAME: DESIGN_DOC_NAME,
+    FILTER_FUNCTION: FILTER_FUNCTION
 };
diff --git a/provider/lib/health.js b/provider/lib/health.js
index 808295d..2c56e2b 100644
--- a/provider/lib/health.js
+++ b/provider/lib/health.js
@@ -1,11 +1,34 @@
-module.exports = function(providerUtils) {
+var si = require('systeminformation');
 
-  // Health Endpoint
-  this.endPoint = '/health';
+module.exports = function(utils) {
 
-  // Health Logic
-  this.health = function (req, res) {
-      res.send({triggerCount: Object.keys(providerUtils.triggers).length});
-  };
+    // Health Endpoint
+    this.endPoint = '/health';
+    var stats = {triggerCount: Object.keys(utils.triggers).length};
+
+    // Health Logic
+    this.health = function (req, res) {
+
+        // get all system stats in parallel
+        Promise.all([
+            si.mem(),
+            si.currentLoad(),
+            si.fsSize(),
+            si.networkStats(),
+            si.inetLatency(utils.routerHost)
+        ])
+        .then(results => {
+            stats.memory = results[0];
+            stats.cpu = results[1];
+            stats.disk = results[2];
+            stats.network = results[3];
+            stats.apiHostLatency = results[4];
+            res.send(stats);
+        })
+        .catch(error => {
+            stats.error = error;
+            res.send(stats);
+        });
+    };
 
 };
diff --git a/provider/lib/utils.js b/provider/lib/utils.js
index 68b9d9c..e184f4d 100644
--- a/provider/lib/utils.js
+++ b/provider/lib/utils.js
@@ -19,10 +19,9 @@ module.exports = function(
     this.redisHash = triggerDB.config.db + '_' + this.worker;
     this.redisKey = constants.REDIS_KEY;
 
-    this.retryAttempts = constants.RETRY_ATTEMPTS;
-
-    var ddname = 'triggers';
-    var filter = 'only_triggers_by_worker';
+    var retryAttempts = constants.RETRY_ATTEMPTS;
+    var ddname = constants.DESIGN_DOC_NAME;
+    var filter = constants.FILTER_FUNCTION;
 
     var utils = this;
 
@@ -220,7 +219,7 @@ module.exports = function(
                             reject('Disabled trigger ' + dataTrigger.id + ' due to status
code: ' + response.statusCode);
                         }
                         else {
-                            if (retryCount < utils.retryAttempts ) {
+                            if (retryCount < retryAttempts ) {
                                 var timeout = response && response.statusCode ===
429 && retryCount === 0 ? 60000 : 1000 * Math.pow(retryCount + 1, 2);
                                 logger.info(method, 'attempting to fire trigger again', dataTrigger.id,
'Retry Count:', (retryCount + 1));
                                 setTimeout(function () {
diff --git a/tests/src/test/scala/system/redundancy/CloudantRedundancyTests.scala b/tests/src/test/scala/system/redundancy/CloudantRedundancyTests.scala
index 6cc69f8..5279d8d 100644
--- a/tests/src/test/scala/system/redundancy/CloudantRedundancyTests.scala
+++ b/tests/src/test/scala/system/redundancy/CloudantRedundancyTests.scala
@@ -28,7 +28,7 @@ import system.CloudantUtil
 /**
  * These tests verify that a cloudant redundancy (master/slave) configuration
  * works as expected.  They will only run properly in an environment with two
- * alarms containers running concurrently and env var ACTIVE set to true in
+ * cloudant containers running concurrently and env var ACTIVE set to true in
  * one container and false in the other.  This test also assumes that redis and
  * the active endpoint authorization are configured.  For the auth set the
  * ENDPOINT_AUTH env var in your containers to match the testing.auth property

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].

Mime
View raw message