Skip to content

Commit 7b04023

Browse files
committed
merge master
2 parents 273e324 + afb9754 commit 7b04023

6 files changed

Lines changed: 62 additions & 31 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ Update - PATCH - /resources/:id *PATCH is a partial update, PUT is a full reso
4444
Delete - DELETE - /resources/:id
4545

4646
#### Middleware Patterns
47-
Request Data validation and Middleware Flow Control - [tjmehta/dat-middleware](https://github.com/tjmehta/dat-middleware)
47+
48+
Request Data validation and Middleware Flow Control - [tjmehta/dat-middleware](https://github.com/tjmehta/dat-middleware)
4849
Middleware Flow Control - [tjmehta/middleware-flow](https://github.com/tjmehta/middleware-flow)
4950
Middlewares of models are autogenerated for you
50-
* Mongoose Models - /lib/middlewares/mongo/index.js - [tjmehta/mongooseware](https://github.com/tjmehta/mongooseware)
51-
* Class Models - /lib/middlewares/apis/index.js [tjmehta/middlewarize](https://github.com/tjmehta/middlewarize) *documentation soon
51+
* Mongoose Models - /lib/middlewares/mongo/index.js - [tjmehta/mongooseware](https://github.com/tjmehta/mongooseware)
52+
* Class Models - /lib/middlewares/apis/index.js [tjmehta/middlewarize](https://github.com/tjmehta/middlewarize)
5253
Sharing the request object as a common context between middlewares allows us to make
5354
asynchronous code look synchronous and avoid "callback hell"
5455

56+
5557
#### Boom for Http Errors
5658
Nice Http Error library - [hapijs/boom](https://github.com/hapijs/boom)
5759

docker-files/api_base/Dockerfile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#
22
# api_base Dockerfile
3-
# Author anandkumarpatel
4-
##
3+
#
54

65
# Pull base image.
76
FROM registry.runnable.com/runnable/base:latest
87

9-
WORKDIR /
8+
# Node.js @ 10.28
9+
# npm @ 2.1.8
10+
11+
# install required packages
12+
# lsof: required for open file monitoring
1013

11-
# Installing Node.js
12-
RUN wget http://nodejs.org/dist/v0.10.29/node-v0.10.29.tar.gz
13-
RUN tar xvf node-v*.tar.gz
14-
WORKDIR node-v0.10.29/
15-
RUN ./configure
16-
RUN make -j16
17-
RUN make install
14+
RUN wget http://nodejs.org/dist/v0.10.28/node-v0.10.28.tar.gz \
15+
&& tar xvf node-v*.tar.gz \
16+
&& cd node-v0.10.28 \
17+
&& ./configure \
18+
&& make -j16 \
19+
&& make install \
20+
&& npm install -g npm@2.1.11 \
21+
&& apt-get install lsof

lib/express-app.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ var pkg = require('../package.json');
1010
var dogstatsd = require('models/datadog');
1111
var app = module.exports = express();
1212

13-
app.use(require('connect-datadog')({
14-
'dogstatsd': dogstatsd,
15-
'response_code':true,
16-
'method':true,
17-
'tags': ['name:api', 'logType:express', 'env:'+process.env.NODE_ENV]
18-
}));
13+
if (envIs('production')) {
14+
app.use(require('connect-datadog')({
15+
'dogstatsd': dogstatsd,
16+
'response_code':true,
17+
'method':true,
18+
'tags': ['name:api', 'logType:express', 'env:'+process.env.NODE_ENV]
19+
}));
1920

20-
if (envIs('development', 'local', 'io')) {
21-
app.use(morganFreeman());
22-
app.use(function (req, res, next) {
23-
console.log(req.method, '-', req.url);
24-
next();
25-
});
21+
// app.use(dogstatsd.captureSocketCount);
22+
}
23+
24+
if (envIs('development', 'local', 'stage')) {
25+
app.use(morganFreeman('short'));
2626
}
2727

2828
app.use(require('./routes/github'));

lib/models/datadog/index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var StatsD = require('node-dogstatsd').StatsD;
33
var client = module.exports = new StatsD(
44
process.env.DATADOG_HOST,
55
process.env.DATADOG_PORT);
6-
6+
var exec = require('child_process').exec;
77

88
function captureSteamData (streamName, stream) {
99
stream.on('data', function(){
@@ -21,5 +21,26 @@ function captureSteamData (streamName, stream) {
2121
}
2222

2323

24+
function captureSocketCount (req, res, next) {
25+
var sockets = require('http').globalAgent.sockets;
26+
var request = require('http').globalAgent.requests;
27+
var key;
28+
29+
for (key in sockets) {
30+
client.gauge('api.sockets_open', sockets[key].length, 1, ['target:'+key]);
31+
}
32+
33+
for (key in request) {
34+
client.gauge('api.sockets_pending', request[key].length, 1, ['target:'+key]);
35+
}
36+
37+
exec('lsof -p ' + process.pid + ' | wc -l', function (err, stdout) {
38+
if (err) { return; }
39+
client.gauge('api.openFiles', parseInt(stdout), 1, ['pid:'+process.pid]);
40+
});
41+
42+
next();
43+
}
2444

2545
module.exports.captureSteamData = captureSteamData;
46+
module.exports.captureSocketCount = captureSocketCount;

lib/routes/instances/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ var github = require('middlewares/apis').github;
2323
var docker = require('middlewares/apis').docker;
2424
var mavis = require('middlewares/apis').mavis;
2525
var sauron = require('middlewares/apis').sauron;
26-
var isInternal = require('middlewares/is-internal-request.js');
2726
var runnable = require('middlewares/apis').runnable;
2827
var hosts = require('middlewares/redis').hosts;
2928
var userStoppedContainer = require('middlewares/redis').userStoppedContainer;
@@ -562,11 +561,12 @@ app.post('/instances/:id/actions/copy',
562561
);
563562

564563
/** Creates a container (instance.container) from the current instance build (instance.build)
565-
* @event PUT rest/instances/:id/a
564+
- * @event PUT rest/instances/:id/a
565+
+ * THIS IS ALSO USED INTERNALLY
566+
+ * @event POST rest/instances/:id/actions/redeploy
566567
* @params id: instance id
567568
*/
568569
app.post('/instances/:id/actions/redeploy',
569-
isInternal,
570570
findInstance,
571571
flow.or(
572572
me.isOwnerOf('instance'),

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "api",
33
"description": "Runnable API Server",
4-
"version": "0.4.1",
4+
"version": "0.4.2",
55
"repository": {
66
"type": "git",
77
"url": "http://github.com/CodeNow/api.git"
@@ -97,7 +97,11 @@
9797
"sauron": "git+ssh://git@github.com:codenow/sauron#v0.0.8",
9898
"server-destroy": "^1.0.0"
9999
},
100-
"engine": "node >= 0.10.5",
100+
"engineStrict": true,
101+
"engine": {
102+
"node": "0.10.28",
103+
"npm": "2.1.8"
104+
},
101105
"scripts": {
102106
"test-watch": "echo use 'bdd-watch' or 'unit-watch'",
103107
"_bdd": "npm run clear; NODE_PATH=./lib NODE_ENV=test lab -v -l -m 200 -e test",

0 commit comments

Comments
 (0)