From 03b07dd4decb9a1051c48b3c08cc6ab0b2e973a0 Mon Sep 17 00:00:00 2001 From: thinkholic Date: Mon, 30 Nov 2015 17:49:10 +0530 Subject: [PATCH 1/6] add MeteorToys methods as in ignoringMethods --- lib/client/providers/blaze.js | 52 +++++++++++++++++++++++++++-------- lib/client/providers/ddp.js | 31 +++++++++++++++++++-- lib/client/utils.js | 7 +++++ 3 files changed, 76 insertions(+), 14 deletions(-) diff --git a/lib/client/providers/blaze.js b/lib/client/providers/blaze.js index 5a3bdf0..7fd5274 100644 --- a/lib/client/providers/blaze.js +++ b/lib/client/providers/blaze.js @@ -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); @@ -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); }); @@ -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); }); @@ -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); }); @@ -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); }); @@ -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); }); diff --git a/lib/client/providers/ddp.js b/lib/client/providers/ddp.js index e3de839..356a6ff 100644 --- a/lib/client/providers/ddp.js +++ b/lib/client/providers/ddp.js @@ -1,6 +1,15 @@ 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: {} }; @@ -158,6 +167,12 @@ DDPProvider._send = function(original) { DDPProvider.ignoringMethodIds["" + msg.id] = 2; break; } + + if(Utils.hasNoTrackingKeywords(msg.method)) { + DDPProvider.ignoringMethodIds["" + msg.id] = 2; + break; + } + info.name = msg.method; info.id = msg.id; eventName = "ddp-method"; @@ -184,4 +199,16 @@ DDPProvider._send = function(original) { return original.call(conn, msg); }; }; -Utils.override(conn, '_send', DDPProvider._send); \ No newline at end of file +Utils.override(conn, '_send', DDPProvider._send); + +function isTrackingDisallowed(msg, type) { + if(type === "method") { + if(DDPProvider.ignoringMethods[msg.method]) { + return true; + } + + if(Utils.hasNoTrackingKeywords(msg.method)) { + return true; + } + } +} \ No newline at end of file diff --git a/lib/client/utils.js b/lib/client/utils.js index 085bbb0..215f078 100644 --- a/lib/client/utils.js +++ b/lib/client/utils.js @@ -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; + } }; \ No newline at end of file From d1375582b2670611e6f48fec49faef551c444598 Mon Sep 17 00:00:00 2001 From: thinkholic Date: Tue, 1 Dec 2015 11:52:04 +0530 Subject: [PATCH 2/6] prevent tracking unwanted pub/methods with regex --- lib/client/providers/ddp.js | 42 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/client/providers/ddp.js b/lib/client/providers/ddp.js index 356a6ff..7e74149 100644 --- a/lib/client/providers/ddp.js +++ b/lib/client/providers/ddp.js @@ -11,7 +11,12 @@ DDPProvider = { "Mongol_update": true, "Mongol_duplicate": true }, - ignoringMethodIds: {} + ignoringMethodIds: {}, + + ignoringPubSubs: { + "MeteorToys": true + }, + ignoringPubSubIds: {} }; var conn = Meteor.connection; @@ -40,6 +45,7 @@ DDPProvider._livedata_data = function(original) { break; case "updated": var methods = []; + // removing ignoring methods _.each(msg.methods, function(id) { if(DDPProvider.ignoringMethodIds[id]) { @@ -163,14 +169,11 @@ DDPProvider._send = function(original) { var eventName = null; switch(msg.msg) { case "method": - if(DDPProvider.ignoringMethods[msg.method]) { - DDPProvider.ignoringMethodIds["" + msg.id] = 2; - break; - } - - if(Utils.hasNoTrackingKeywords(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; @@ -180,6 +183,13 @@ DDPProvider._send = function(original) { 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"; @@ -199,16 +209,4 @@ DDPProvider._send = function(original) { return original.call(conn, msg); }; }; -Utils.override(conn, '_send', DDPProvider._send); - -function isTrackingDisallowed(msg, type) { - if(type === "method") { - if(DDPProvider.ignoringMethods[msg.method]) { - return true; - } - - if(Utils.hasNoTrackingKeywords(msg.method)) { - return true; - } - } -} \ No newline at end of file +Utils.override(conn, '_send', DDPProvider._send); \ No newline at end of file From 648aa769908cf5c4ecc412403c7008c89af8a0f1 Mon Sep 17 00:00:00 2001 From: thinkholic Date: Tue, 1 Dec 2015 12:50:09 +0530 Subject: [PATCH 3/6] add server side availability for utils.js --- lib/{client => }/utils.js | 0 package.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/{client => }/utils.js (100%) diff --git a/lib/client/utils.js b/lib/utils.js similarity index 100% rename from lib/client/utils.js rename to lib/utils.js diff --git a/package.js b/package.js index d2ef230..a284113 100644 --- a/package.js +++ b/package.js @@ -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'); From bb5faf393c61de20682fdf298429d9f4939d3886 Mon Sep 17 00:00:00 2001 From: thinkholic Date: Tue, 1 Dec 2015 12:55:28 +0530 Subject: [PATCH 4/6] prevent tracking unwanted traces --- lib/server/trace_store.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/server/trace_store.js b/lib/server/trace_store.js index 0eaf2b6..19dd28a 100644 --- a/lib/server/trace_store.js +++ b/lib/server/trace_store.js @@ -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); @@ -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); From 8fe7def03d3c0c6f65602ecc24073bcf9564e578 Mon Sep 17 00:00:00 2001 From: thinkholic Date: Tue, 1 Dec 2015 13:34:59 +0530 Subject: [PATCH 5/6] update test cases --- tests/client/providers/blaze.js | 96 +++++++++++++++++++++++++++++++++ tests/client/providers/ddp.js | 52 ++++++++++++++++++ 2 files changed, 148 insertions(+) diff --git a/tests/client/providers/blaze.js b/tests/client/providers/blaze.js index a0d6c3a..a475d73 100644 --- a/tests/client/providers/blaze.js +++ b/tests/client/providers/blaze.js @@ -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(); + }); }); \ No newline at end of file diff --git a/tests/client/providers/ddp.js b/tests/client/providers/ddp.js index aa6d111..63a66a4 100644 --- a/tests/client/providers/ddp.js +++ b/tests/client/providers/ddp.js @@ -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) { @@ -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) { From 3bc6b38da0c5420b21bdd43d14887d00b6b37aff Mon Sep 17 00:00:00 2001 From: thinkholic Date: Fri, 4 Dec 2015 16:50:27 +0530 Subject: [PATCH 6/6] add kadira:debug subscription to NoTracking list --- lib/client/providers/ddp.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/client/providers/ddp.js b/lib/client/providers/ddp.js index 7e74149..81088ee 100644 --- a/lib/client/providers/ddp.js +++ b/lib/client/providers/ddp.js @@ -14,7 +14,10 @@ DDPProvider = { ignoringMethodIds: {}, ignoringPubSubs: { - "MeteorToys": true + "MeteorToys": true, + "kadira.debug.client.auth": true, + "kadira.debug.client.init": true, + "kadira.debug.client.listeners": true, }, ignoringPubSubIds: {} };