Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meteor toys tracking removal #23

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions lib/client/providers/blaze.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ BlazeProvider._fireCallbacks = function(original) {
return function(view, which) {
var self = this;
var name = Utils.findBlazeViewName(view);

var done = StoreManager.trackActivity('view.' + which, name);
var response = StoreManager.onTracking(function() {
return original.call(self, view, which);
Expand All @@ -26,7 +27,12 @@ BlazeProvider.autorun = function(original) {
if(c.firstRun) {
cb.call(this, c);
} else {
var done = StoreManager.trackActivity('autorun', self.view.name);

var done = function() {};
if(!Utils.hasNoTrackingKeywords(self.view.name)) {
var done = StoreManager.trackActivity('autorun', self.view.name);
}

StoreManager.onTracking(function() {
cb.call(that, c);
});
Expand All @@ -51,7 +57,12 @@ BlazeProvider.helpers = function(original) {
var that = this;
var args = arguments;
var trackingName = self.viewName + '::' + name;
var done = StoreManager.trackActivity('helper', trackingName);

var done = function() {};
if(!Utils.hasNoTrackingKeywords(trackingName)) {
var done = StoreManager.trackActivity('helper', trackingName);
}

var response = StoreManager.onTracking(function() {
return fn.apply(that, args);
});
Expand All @@ -76,14 +87,22 @@ BlazeProvider.events = function(original) {
dict[name] = function() {
var that = this;
var args = arguments;
var info = {
name: name,
view: self.viewName
};
StoreManager.trackEvent('event', info);

var trackingName = self.viewName + '::' + name;
var done = StoreManager.trackActivity('event', trackingName);

var eventStr = name;
eventStr = eventStr.concat(self.viewName);
var done = function() {};

if(!Utils.hasNoTrackingKeywords(eventStr)) {
var info = {
name: name,
view: self.viewName
};
StoreManager.trackEvent('event', info);

var trackingName = self.viewName + '::' + name;
var done = StoreManager.trackActivity('event', trackingName);
}

var response = StoreManager.onTracking(function() {
return fn.apply(that, args);
});
Expand All @@ -102,7 +121,12 @@ BlazeProvider._materializeDOM = function(original) {
return function(htmljs, intoArray, view) {
var self = this;
var name = Utils.findBlazeViewName(view);
var done = StoreManager.trackActivity('dom.create', name)

var done = function() {};
if(!Utils.hasNoTrackingKeywords(name)) {
var done = StoreManager.trackActivity('dom.create', name);
}

var response = StoreManager.onTracking(function() {
return original.call(self, htmljs, intoArray, view);
});
Expand All @@ -121,7 +145,11 @@ BlazeProvider._destroyNode = function(original) {
viewName = Utils.findBlazeViewName(Blaze.currentView);
}

var done = StoreManager.trackActivity('dom.destroy', viewName);
var done = function() {};
if(!Utils.hasNoTrackingKeywords(viewName)) {
var done = StoreManager.trackActivity('dom.destroy', viewName);
}

var response = StoreManager.onTracking(function() {
return original.call(self, node);
});
Expand Down
38 changes: 33 additions & 5 deletions lib/client/providers/ddp.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
DDPProvider = {
ignoringMethods: {
"kadira.debug.updateTimeline": true
"kadira.debug.updateTimeline": true,
"MeteorToys": true,
"MeteorToysRegistry": true,
"MeteorToys_x": true,
"MeteorToys_d": true,
"MeteorToys_ia": true,
"MeteorToys_method_handlers": true,
"Mongol_verifyDoc": true,
"Mongol_update": true,
"Mongol_duplicate": true
},
ignoringMethodIds: {}
ignoringMethodIds: {},

ignoringPubSubs: {
"MeteorToys": true,
"kadira.debug.client.auth": true,
"kadira.debug.client.init": true,
"kadira.debug.client.listeners": true,
},
ignoringPubSubIds: {}
};

var conn = Meteor.connection;
Expand Down Expand Up @@ -31,6 +48,7 @@ DDPProvider._livedata_data = function(original) {
break;
case "updated":
var methods = [];

// removing ignoring methods
_.each(msg.methods, function(id) {
if(DDPProvider.ignoringMethodIds[id]) {
Expand Down Expand Up @@ -154,17 +172,27 @@ DDPProvider._send = function(original) {
var eventName = null;
switch(msg.msg) {
case "method":
if(DDPProvider.ignoringMethods[msg.method]) {
DDPProvider.ignoringMethodIds["" + msg.id] = 2;
break;
// prevent tracking unwanted methods
if((DDPProvider.ignoringMethods[msg.method]) ||
(Utils.hasNoTrackingKeywords(msg.method))) {
DDPProvider.ignoringMethodIds["" + msg.id] = 2;
break;
}

info.name = msg.method;
info.id = msg.id;
eventName = "ddp-method";
var timeInfo = {name: msg.method};
StoreManager.trackTime('method', msg.id, 'start', timeInfo);
break;
case "sub":
// prevent tracking unwanted publications
if((DDPProvider.ignoringPubSubs[msg.name]) ||
(Utils.hasNoTrackingKeywords(msg.name))) {
DDPProvider.ignoringPubSubIds["" + msg.id] = 2;
break;
}

info.name = msg.name;
info.id = msg.id;
eventName = "ddp-sub";
Expand Down
11 changes: 11 additions & 0 deletions lib/server/trace_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ TraceStore.prototype._onMethodTrace = function(trace, session) {
if(trace && trace.name === "kadira.debug.updateTimeline") {
return;
}

// prevent tracking unwanted traces
if(trace && Utils.hasNoTrackingKeywords(trace.name)) {
return;
}

this._buildTrace(trace);

var key = this._getTraceKey(session.id, trace.id);
Expand All @@ -119,6 +125,11 @@ TraceStore.prototype._onMethodTrace = function(trace, session) {
};

TraceStore.prototype._onSubTrace = function(trace, session) {
// prevent tracking unwanted traces
if(trace && Utils.hasNoTrackingKeywords(trace.name)) {
return;
}

// here, trace can be empty
if(trace) {
this._buildTrace(trace);
Expand Down
7 changes: 7 additions & 0 deletions lib/client/utils.js → lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ Utils.findBlazeViewName = function(view) {
Utils.override = function(namespace, funcName, generator) {
var original = namespace[funcName];
namespace[funcName] = generator(original);
};

Utils.hasNoTrackingKeywords = function(str) {
var patt = new RegExp(/(MeteorToys|Mongol|JetSetter)/ig);
if(patt.test(str)) {
return true;
}
};
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function configure(api) {

api.addFiles('lib/server/old_version_removal.js', 'server');

api.addFiles('lib/client/utils.js', 'client');
api.addFiles('lib/utils.js', ['server', 'client']);
api.addFiles('lib/client/store.js', 'client');

api.addFiles('lib/client/providers/blaze.js', 'client');
Expand Down
96 changes: 96 additions & 0 deletions tests/client/providers/blaze.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,101 @@ function(test, done) {
stub.stop();
done();
});
});

Tinytest.addAsync(
'Client - BlazeProvider - withIgnoredKeywords - autorun',
function(test, done) {
var stub = StartStubbing(StoreManager, 'trackActivity');
stub.returns(function() {});
var that = {view: {name: 'MeteorToys'}};

var caller = BlazeProvider.autorun(function(cb) {
var computation = {firstRun: false};
cb(computation);
});

caller.call(that, function() {
test.equal(stub.callCount, 0);
stub.stop();
done();
});
});

Tinytest.addAsync(
'Client - BlazeProvider - withIgnoredKeywords - events / activity',
function(test, done) {
var eventRef = {};
var stub = StartStubbing(StoreManager, 'trackActivity');
stub.returns(function() {});
var stub2 = StartStubbing(StoreManager, 'trackEvent');

var caller = BlazeProvider.events(function(eventMap) {
eventMap.click(eventRef);
});

var that = {viewName: "MeteorToys"};
var eventMap = {
"click": function(e) {
test.equal(e, eventRef);
test.equal(stub.callCount, 0);
test.equal(stub2.callCount, 0);
stub.stop();
stub2.stop();
done();
}
};
caller.call(that, eventMap);
});

Tinytest.addAsync(
'Client - BlazeProvider - withIgnoredKeywords - _materializeDOM',
function(test, done) {
var htmljs = {};
var intoArray = {};
var view = {name: "JetSetter"};
var that = {};
var dom = {};

var stub = StartStubbing(StoreManager, 'trackActivity');
stub.returns(function() {});

var caller = BlazeProvider._materializeDOM(function(h, i, v) {
test.equal(this, that);
test.equal(h, htmljs);
test.equal(i, intoArray);
test.equal(v, view);
return dom;
});

var res = caller.call(that, htmljs, intoArray, view);
test.equal(res, dom);
test.equal(stub.callCount, 0);
stub.stop();
done();
});

Tinytest.addAsync(
'Client - BlazeProvider - withIgnoredKeywords - _destroyNode with a view',
function(test, done) {
var node = {};
var that = {};
var view = {name: 'Mongol'};

var stub = StartStubbing(StoreManager, 'trackActivity');
stub.returns(function() {});

var caller = BlazeProvider._destroyNode(function(n) {
test.equal(this, that);
test.equal(n, node);
});

WithNew(Blaze, {
currentView: view
}, function() {
var res = caller.call(that, node);
test.equal(stub.callCount, 0);
stub.stop();
done();
});
});
52 changes: 52 additions & 0 deletions tests/client/providers/ddp.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,42 @@ function(test, done) {
caller(message);
});

Tinytest.addAsync(
'Client - DDPProvider - outgoing - ignoring sub message',
function(test, done) {
var stub = StartStubbing(StoreManager, 'trackEvent');
var stub2 = StartStubbing(StoreManager, 'trackTime');

var message = {msg: 'sub', id: '1', name: 'MeteorToys'};
var caller = DDPProvider._send(function(msg) {
test.equal(msg, message);
test.equal(DDPProvider.ignoringPubSubIds[message.id], 2);
test.equal(stub.callCount, 0);
stub.stop();
done();
});

caller(message);
});

Tinytest.addAsync(
'Client - DDPProvider - outgoing - ignoring sub message with specific keywords',
function(test, done) {
var stub = StartStubbing(StoreManager, 'trackEvent');
var stub2 = StartStubbing(StoreManager, 'trackTime');

var message = {msg: 'sub', id: '1', name: 'JetSetter'};
var caller = DDPProvider._send(function(msg) {
test.equal(msg, message);
test.equal(DDPProvider.ignoringPubSubIds[message.id], 2);
test.equal(stub.callCount, 0);
stub.stop();
done();
});

caller(message);
});

Tinytest.addAsync(
'Client - DDPProvider - outgoing - unsub message',
function(test, done) {
Expand Down Expand Up @@ -357,6 +393,22 @@ function(test, done) {
caller(message);
});

Tinytest.addAsync(
'Client - DDPProvider - outgoing - ignoring method message with specific keywords',
function(test, done) {
var stub = StartStubbing(StoreManager, 'trackEvent');
var message = {msg: 'method', id: Random.id(), method: 'MeteorToys_JetSetter'};
var caller = DDPProvider._send(function(msg) {
test.equal(msg, message);
test.equal(DDPProvider.ignoringMethodIds[message.id], 2);
test.equal(stub.callCount, 0);
stub.stop();
done();
});

caller(message);
});

Tinytest.addAsync(
'Client - DDPProvider - outgoing - some other message',
function(test, done) {
Expand Down