Metrics collection framework
This commit is contained in:
@@ -11,6 +11,7 @@ script:
|
||||
|
||||
after_success:
|
||||
- grunt publish
|
||||
- grunt metrics
|
||||
|
||||
email:
|
||||
on_failure: change
|
||||
|
||||
+1
-11
@@ -87,17 +87,7 @@ module.exports = function(grunt) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
grunt.registerTask('bench', function() {
|
||||
var done = this.async();
|
||||
|
||||
var runner = childProcess.fork('./bench/handlebars', [], {stdio: 'inherit'});
|
||||
runner.on('close', function(code) {
|
||||
if (code != 0) {
|
||||
grunt.fatal(code + ' tests failed');
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
grunt.registerTask('bench', ['metrics']);
|
||||
|
||||
grunt.registerTask('build', ['jshint', 'parser', 'dist-dir', 'concat', 'uglify', 'test']);
|
||||
grunt.registerTask('default', 'build');
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
var fs = require('fs');
|
||||
|
||||
var metrics = fs.readdirSync(__dirname);
|
||||
metrics.forEach(function(metric) {
|
||||
if (metric === 'index.js' || !/(.*)\.js$/.test(metric)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var name = RegExp.$1;
|
||||
metric = require('./' + name);
|
||||
if (metric instanceof Function) {
|
||||
module.exports[name] = metric;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
var _ = require('underscore'),
|
||||
async = require('async'),
|
||||
git = require('./util/git'),
|
||||
Keen = require('keen.io'),
|
||||
metrics = require('../bench');
|
||||
|
||||
module.exports = function(grunt) {
|
||||
grunt.registerTask('metrics', function() {
|
||||
var done = this.async(),
|
||||
execName = grunt.option('name'),
|
||||
events = {},
|
||||
|
||||
projectId = process.env.KEEN_PROJECTID,
|
||||
writeKey = process.env.KEEN_WRITEKEY,
|
||||
keen;
|
||||
|
||||
if (!execName && projectId && writeKey) {
|
||||
keen = Keen.configure({
|
||||
projectId: projectId,
|
||||
writeKey: writeKey
|
||||
});
|
||||
}
|
||||
|
||||
async.each(_.keys(metrics), function(name, complete) {
|
||||
if (/^_/.test(name) || (execName && name !== execName)) {
|
||||
return complete();
|
||||
}
|
||||
|
||||
metrics[name](grunt, function(data) {
|
||||
events[name] = data;
|
||||
complete();
|
||||
});
|
||||
},
|
||||
function() {
|
||||
if (!keen) {
|
||||
return done();
|
||||
}
|
||||
|
||||
emit(keen, events, function(err, res) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
grunt.log.writeln('Metrics recorded.');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
function emit(keen, collections, callback) {
|
||||
git.commitInfo(function(err, info) {
|
||||
_.each(collections, function(collection) {
|
||||
_.each(collection, function(event) {
|
||||
if (info.tagName) {
|
||||
event.tag = info.tagName;
|
||||
}
|
||||
event.sha = info.head;
|
||||
});
|
||||
});
|
||||
|
||||
keen.addEvents(collections, callback);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user