build(analytics): add basic build-analytics to the project

This is pretty experimental, but the goal is to track the performance
of our build over time so that we can more easily track perf regressions.

Currently it's integrated only with gulp tasks, but I'd like to expand it
to tracking travis jobs, protractor/benchpress test runs, npm installs, etc.

No PII is being collected. And the data is collected via a Google Analytics
property owned by the Angular team account.

Closes #4672
This commit is contained in:
Igor Minar 2015-10-11 02:23:05 -07:00
parent 0def28e594
commit da1272f368
6 changed files with 738 additions and 132 deletions

3
.gitignore vendored
View File

@ -41,3 +41,6 @@ modules/.vscode
npm-debug.log
/docs/bower_components/
# build-analytics
.build-analytics

View File

@ -17,6 +17,7 @@ var merge = require('merge');
var merge2 = require('merge2');
var path = require('path');
var licenseWrap = require('./tools/build/licensewrap');
var analytics = require('./tools/analytics/analytics');
var watch = require('./tools/build/watch');
@ -1297,3 +1298,7 @@ process.on('beforeExit', function() {
gulp.start('cleanup.builder');
}
});
gulp.on('task_stop', (e) => { analytics.build('gulp ' + e.task, e.duration*1000)});
gulp.on('task_err', (e) => { analytics.build('gulp ' + e.task + ' (errored)', e.duration*1000)});

View File

@ -11344,17 +11344,6 @@
"type-detect": {
"version": "0.1.2"
},
"universal-analytics": {
"version": "0.3.9",
"dependencies": {
"underscore": {
"version": "1.8.3"
},
"async": {
"version": "0.2.10"
}
}
},
"update-notifier": {
"version": "0.2.2",
"dependencies": {
@ -11647,6 +11636,208 @@
"typescript": {
"version": "1.6.2"
},
"universal-analytics": {
"version": "0.3.9",
"dependencies": {
"request": {
"version": "2.65.0",
"dependencies": {
"bl": {
"version": "1.0.0",
"dependencies": {
"readable-stream": {
"version": "2.0.2",
"dependencies": {
"core-util-is": {
"version": "1.0.1"
},
"inherits": {
"version": "2.0.1"
},
"isarray": {
"version": "0.0.1"
},
"process-nextick-args": {
"version": "1.0.3"
},
"string_decoder": {
"version": "0.10.31"
},
"util-deprecate": {
"version": "1.0.2"
}
}
}
}
},
"caseless": {
"version": "0.11.0"
},
"extend": {
"version": "3.0.0"
},
"forever-agent": {
"version": "0.6.1"
},
"form-data": {
"version": "1.0.0-rc3",
"dependencies": {
"async": {
"version": "1.4.2"
}
}
},
"json-stringify-safe": {
"version": "5.0.1"
},
"mime-types": {
"version": "2.1.7",
"dependencies": {
"mime-db": {
"version": "1.19.0"
}
}
},
"qs": {
"version": "5.2.0"
},
"tunnel-agent": {
"version": "0.4.1"
},
"tough-cookie": {
"version": "2.2.0"
},
"http-signature": {
"version": "0.11.0",
"dependencies": {
"assert-plus": {
"version": "0.1.5"
},
"asn1": {
"version": "0.1.11"
},
"ctype": {
"version": "0.5.3"
}
}
},
"oauth-sign": {
"version": "0.8.0"
},
"hawk": {
"version": "3.1.0",
"dependencies": {
"hoek": {
"version": "2.16.3"
},
"boom": {
"version": "2.9.0"
},
"cryptiles": {
"version": "2.0.5"
},
"sntp": {
"version": "1.0.9"
}
}
},
"aws-sign2": {
"version": "0.6.0"
},
"stringstream": {
"version": "0.0.4"
},
"combined-stream": {
"version": "1.0.5",
"dependencies": {
"delayed-stream": {
"version": "1.0.0"
}
}
},
"isstream": {
"version": "0.1.2"
},
"har-validator": {
"version": "2.0.2",
"dependencies": {
"chalk": {
"version": "1.1.1",
"dependencies": {
"ansi-styles": {
"version": "2.1.0"
},
"escape-string-regexp": {
"version": "1.0.3"
},
"has-ansi": {
"version": "2.0.0",
"dependencies": {
"ansi-regex": {
"version": "2.0.0"
}
}
},
"strip-ansi": {
"version": "3.0.0",
"dependencies": {
"ansi-regex": {
"version": "2.0.0"
}
}
},
"supports-color": {
"version": "2.0.0"
}
}
},
"commander": {
"version": "2.8.1",
"dependencies": {
"graceful-readlink": {
"version": "1.0.1"
}
}
},
"is-my-json-valid": {
"version": "2.12.2",
"dependencies": {
"generate-function": {
"version": "2.0.0"
},
"generate-object-property": {
"version": "1.2.0",
"dependencies": {
"is-property": {
"version": "1.0.2"
}
}
},
"jsonpointer": {
"version": "2.0.0"
}
}
},
"pinkie-promise": {
"version": "1.0.0",
"dependencies": {
"pinkie": {
"version": "1.0.0"
}
}
}
}
}
}
},
"underscore": {
"version": "1.8.3"
},
"async": {
"version": "0.2.10"
}
}
},
"vinyl": {
"version": "0.4.6",
"dependencies": {
@ -11685,5 +11876,5 @@
}
},
"name": "angular",
"version": "2.0.0-alpha.39"
"version": "2.0.0-alpha.40"
}

539
npm-shrinkwrap.json generated

File diff suppressed because it is too large Load Diff

View File

@ -132,6 +132,7 @@
"tsd": "^0.6.5-beta",
"tslint": "^2.5.0",
"typescript": "^1.6.2",
"universal-analytics": "^0.3.9",
"vinyl": "^0.4.6",
"walk-sync": "^0.1.3",
"which": "~1",

View File

@ -0,0 +1,107 @@
'use strict';
let execSync = require('child_process').execSync;
let fs = require('fs');
let path = require('path');
let os = require('os');
let ua = require('universal-analytics');
const analyticsFile = path.resolve(path.join(__dirname, '..', '..', '.build-analytics'));
const analyticsId = "UA-8594346-17"; // Owned by the Angular account
const analyticsOptions = {
https: true,
debug: false
};
let cid = fs.existsSync(analyticsFile) ? fs.readFileSync(analyticsFile, 'utf-8') : null;
let visitor;
if (cid) {
visitor = ua(analyticsId, cid, analyticsOptions);
} else {
visitor = ua(analyticsId, analyticsOptions);
cid = visitor.cid;
fs.writeFileSync(analyticsFile, cid, 'utf-8');
}
// https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
let customParams = {
// OS Platform (darwin, win32, linux)
cd1: os.platform,
// Node.js Version (v4.1.2)
cd2: process.version,
// npm Version (2.14.7)
cd10: getNpmVersion(),
// TypeScript Version (1.6.2)
cd3: getTypeScriptVersion(),
// Dart Version
cd11: getDartVersion(),
// Dev Environment
cd4: process.env.TRAVIS ? 'Travis CI' : 'Local Dev',
// Travis - Pull Request?
cd5: process.env.TRAVIS && process.env.TRAVIS_PULL_REQUEST ? 'true' : 'false',
// Travis - Branch Name (master)
cd6: process.env.TRAVIS_BRANCH,
// Travis - Repo Slug (angular/angular)
cd7: process.env.TRAVIS_REPO_SLUG,
// HW - CPU Info
cd8: `${os.cpus().length} x ${os.cpus()[0].model}`,
// HW - Memory Info
cd9: `${Math.round(os.totalmem()/1024/1024/1024)}GB`,
};
function getTypeScriptVersion() {
try {
return require('typescript').version;
} catch (e) {
return 'unknown';
}
}
function getNpmVersion() {
try {
return execSync('npm -v').toString().replace(/\s/, '');
} catch (e) {
return 'unknown';
}
}
function getDartVersion() {
try {
return execSync('dart --version 2>&1').toString().replace(/.+: (\S+) [\s\S]+/, '$1')
} catch (e) {
return 'unknown';
}
}
module.exports = {
install: (actionName, duration) => {
duration = Math.round(duration);
visitor.
event('install', actionName, 'testLabel', duration, customParams).
timing('install', actionName, duration, customParams).
send();
},
build: (actionName, duration) => {
duration = Math.round(duration);
visitor.
event('build', actionName, 'testLabel', duration, customParams).
timing('build', actionName, duration, customParams).
send();
},
test: (actionName, duration) => {
duration = Math.round(duration);
visitor.
event('test', actionName, 'testLabel', duration, customParams).
timing('test', actionName, duration, customParams).
send();
}
};