Skip to content

Commit 55d929d

Browse files
authored
Merge pull request #6258 from Countly/feature/ingestion
Aggregator file for browser plugin
2 parents c5675ed + 89f6f3c commit 55d929d

File tree

12 files changed

+116
-42
lines changed

12 files changed

+116
-42
lines changed

api/parts/jobs/handle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class Handle {
3333
* @returns {Job} job
3434
**/
3535
job(name, data) {
36-
let Constructor = this.classes[name];
36+
37+
let Constructor = this.classes && this.classes[name];
3738
if (Constructor) {
3839
return new Constructor(name, data);
3940
}

api/utils/calculatedDataManager.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const log = require('./log.js')('core:calculatedDataManager');
2323
* @param {object} options - options object
2424
* @param {object} options.query_data - query data
2525
* @param {object} options.db - db connection
26+
* @param {string} options.id - id of the query, if not given it will be calculated based on query_data
27+
* @param {boolean} [options.no_cache=false] - if true, will not use cache
28+
* @param {boolean} [options.returned=false] - if true, will not output data
2629
* @param {function} options.outputData - function to output data
2730
* @param {number} options.threshold - threshold in seconds
2831
*/
@@ -32,6 +35,9 @@ calculatedDataManager.longtask = async function(options) {
3235
var timeout;
3336
var keep = parseInt(plugins.getConfig("drill").drill_snapshots_cache_time, 10) || 60 * 60 * 24;
3437
keep = keep * 1000;
38+
if (options.no_cache) {
39+
keep = 0;
40+
}
3541

3642
/**
3743
* Return message in case it takes too long

api/utils/requestProcessor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2772,11 +2772,12 @@ const processRequest = (params) => {
27722772
params.qstring.query.period = params.qstring.query.period || params.qstring.period || "30days";
27732773
}
27742774
if (params.qstring.periodOffset) {
2775-
params.qstring.query.periodOffset = params.qstrig.query.periodOffset || params.qstring.periodOffset || 0;
2775+
params.qstring.query.periodOffset = params.qstring.query.periodOffset || params.qstring.periodOffset || 0;
27762776
}
27772777

27782778
calculatedDataManager.longtask({
27792779
db: common.db,
2780+
no_cache: params.qstring.no_cache,
27802781
threshold: plugins.getConfig("api").request_threshold,
27812782
app_id: params.qstring.query.app_id,
27822783
query_data: params.qstring.query,

plugins/browser/api/aggregator.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
var plugins = require('../../pluginManager.js');
3+
4+
(function() {
5+
plugins.register("/session/metrics", function(ob) {
6+
ob.predefinedMetrics.push({
7+
db: "browser",
8+
metrics: [
9+
{ name: "_browser", set: "browser", short_code: "brw" },
10+
{ name: "_browser_version", set: "browser_version", short_code: "brwv" }
11+
]
12+
});
13+
});
14+
}());

plugins/star-rating/tests.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,20 @@ describe('Testing Rating plugin', function() {
424424
}
425425
var ob = JSON.parse(res.text);
426426
ob.should.have.property('result', 'Success');
427-
setTimeout(done, 10 * testUtils.testScalingFactor);
427+
//giving morre time to remove widget
428+
setTimeout(done, 10 * testUtils.testScalingFactor + 2000);
429+
});
430+
});
431+
it('should not find widget in database', function(done) {
432+
request.get('/o/feedback/widget?app_id=' + APP_ID + '&api_key=' + API_KEY_ADMIN + '&widget_id=' + WIDGET_ID)
433+
.expect(404)
434+
.end(function(err, res) {
435+
if (err) {
436+
return done(err);
437+
}
438+
var ob = JSON.parse(res.text);
439+
ob.should.have.property('result', 'Widget not found.');
440+
done();
428441
});
429442
});
430443
});

plugins/views/tests.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function verifySegments(values) {
175175
function verifyTotals(period, order, orderString) {
176176
it("Checking against calculating same table from granural data", function(done) {
177177
request
178-
.get('/o/aggregate?api_key=' + API_KEY_ADMIN + '&app_id=' + APP_ID + '&query={"queryName":"viewsTableData"}&period=' + period)
178+
.get('/o/aggregate?api_key=' + API_KEY_ADMIN + '&no_cache=true&app_id=' + APP_ID + '&query={"queryName":"viewsTableData"}&period=' + period)
179179
.expect(200)
180180
.end(function(err, res) {
181181
console.log(res.text);
@@ -341,12 +341,12 @@ describe('Testing views plugin', function() {
341341
.get('/i?app_key=' + APP_KEY + '&device_id=' + "user1" + '&timestamp=' + (myTime - (25 * 24 * 60 * 60 * 1000)) + '&events=' + data)
342342
.expect(200)
343343
.end(function(err, res) {
344-
setTimeout(done, 1000 * testUtils.testScalingFactor);
344+
setTimeout(done, 1000 * testUtils.testScalingFactor + 2000);
345345
});
346346
});
347347
});
348348

349-
describe('verifying totals after last update', function() {
349+
describe('verifying totals after last update(last year+ 25 days ago)', function() {
350350
verifyTotals("30days");
351351
verifyTotals("month");
352352
});
@@ -383,7 +383,7 @@ describe('Testing views plugin', function() {
383383
});
384384
});
385385
});
386-
describe('verifying totals after last update', function() {
386+
describe('verifying totals after last update(yesterday)', function() {
387387
verifyTotals("yesterday");
388388
verifyTotals("30days");
389389
verifyTotals("month");
@@ -407,11 +407,11 @@ describe('Testing views plugin', function() {
407407
.get('/i?app_key=' + APP_KEY + '&device_id=' + "user1" + '&timestamp=' + (myTime - 10) + '&events=' + data)
408408
.expect(200)
409409
.end(function(err, res) {
410-
setTimeout(done, 1000 * testUtils.testScalingFactor);
410+
setTimeout(done, 1000 * testUtils.testScalingFactor + 2000);
411411
});
412412
});
413413
});
414-
describe('verifying totals after last update', function() {
414+
describe('verifying totals after last update(right now)', function() {
415415
verifyTotals("hour");
416416
verifyTotals("yesterday");
417417
verifyTotals("30days");
@@ -437,11 +437,11 @@ describe('Testing views plugin', function() {
437437
.get('/i?app_key=' + APP_KEY + '&device_id=' + "user1" + '&timestamp=' + (myTime) + '&events=' + data)
438438
.expect(200)
439439
.end(function(err, res) {
440-
setTimeout(done, 1000 * testUtils.testScalingFactor);
440+
setTimeout(done, 1000 * testUtils.testScalingFactor + 2000);
441441
});
442442
});
443443
});
444-
describe('verifying totals after last update', function() {
444+
describe('verifying totals after last update(Same user different view)', function() {
445445
verifyTotals("hour");
446446
verifyTotals("yesterday");
447447
verifyTotals("30days");

test/3.api.write/2.write.app.sessions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var DEVICE_ID = "1234567890";
1010

1111
var compareAgainstGranuralData = function(options, data, done) {
1212
request
13-
.get('/o/aggregate?api_key=' + API_KEY_ADMIN + '&app_id=' + APP_ID + '&query=' + JSON.stringify(options.query) + '&period=' + (options.period || "30ddays"))
13+
.get('/o/aggregate?api_key=' + API_KEY_ADMIN + '&no_cache=true&app_id=' + APP_ID + '&query=' + JSON.stringify(options.query) + '&period=' + (options.period || "30ddays"))
1414
.expect(200)
1515
.end(function(err, res) {
1616
if (err) {

test/3.api.write/4.write.app.metrics.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var DEVICE_ID = "1234567890";
1212

1313
var compareAgainstGranuralData = function(options, data, done) {
1414
request
15-
.get('/o/aggregate?api_key=' + API_KEY_ADMIN + '&app_id=' + APP_ID + '&query=' + JSON.stringify(options.query) + '&period=' + (options.period || "30ddays"))
15+
.get('/o/aggregate?api_key=' + API_KEY_ADMIN + '&no_cache=true&app_id=' + APP_ID + '&query=' + JSON.stringify(options.query) + '&period=' + (options.period || "30ddays"))
1616
.expect(200)
1717
.end(function(err, res) {
1818
if (err) {
@@ -185,7 +185,7 @@ describe('Writing app metrics', function() {
185185
}
186186
var ob = JSON.parse(res.text);
187187
ob.should.have.property('result', 'Success');
188-
setTimeout(done, 1000 * testUtils.testScalingFactor);
188+
setTimeout(done, 1000 * testUtils.testScalingFactor + 2000);
189189
});
190190
});
191191
});
@@ -196,6 +196,7 @@ describe('Writing app metrics', function() {
196196
.get('/o?api_key=' + API_KEY_ADMIN + '&app_id=' + APP_ID + '&method=device_details')
197197
.expect(200)
198198
.end(function(err, res) {
199+
console.log(JSON.stringify(res));
199200
testUtils.validateMetrics(err, res, done, {meta: {"os": ["Android"], "os_versions": ["a4:4"]}, Android: {"n": 2, "t": 2, "u": 2}, "a4:4": {"n": 1, "t": 1, "u": 1}});
200201
});
201202
});
@@ -221,7 +222,7 @@ describe('Writing app metrics', function() {
221222
}
222223
var ob = JSON.parse(res.text);
223224
ob.should.have.property('result', 'Success');
224-
setTimeout(done, 1000 * testUtils.testScalingFactor);
225+
setTimeout(done, 1000 * testUtils.testScalingFactor + 2000);
225226
});
226227
});
227228
});
@@ -270,7 +271,7 @@ describe('Writing app metrics', function() {
270271
}
271272
var ob = JSON.parse(res.text);
272273
ob.should.have.property('result', 'Success');
273-
setTimeout(done, 1000 * testUtils.testScalingFactor);
274+
setTimeout(done, 1000 * testUtils.testScalingFactor + 2000);
274275
});
275276
});
276277
});
@@ -359,7 +360,7 @@ describe('Writing app metrics', function() {
359360
}
360361
var ob = JSON.parse(res.text);
361362
ob.should.have.property('result', 'Success');
362-
setTimeout(done, 1000 * testUtils.testScalingFactor);
363+
setTimeout(done, 1000 * testUtils.testScalingFactor + 2000);
363364
});
364365
});
365366
});
@@ -391,7 +392,7 @@ describe('Writing app metrics', function() {
391392
}
392393
var ob = JSON.parse(res.text);
393394
ob.should.have.property('result', 'Success');
394-
setTimeout(done, 1000 * testUtils.testScalingFactor);
395+
setTimeout(done, 1000 * testUtils.testScalingFactor + 2000);
395396
});
396397
});
397398
});
@@ -478,7 +479,7 @@ describe('Writing app metrics', function() {
478479
}
479480
var ob = JSON.parse(res.text);
480481
ob.should.have.property('result', 'Success');
481-
setTimeout(done, 1000 * testUtils.testScalingFactor);
482+
setTimeout(done, 1000 * testUtils.testScalingFactor + 2000);
482483
});
483484
});
484485
});

test/3.api.write/5.write.app.events.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var APP_KEY = "";
77
var API_KEY_ADMIN = "";
88
var APP_ID = "";
99
var DEVICE_ID = "1234567890";
10+
var drill_db = "";
1011

1112
var totalEventCounts = {};
1213

@@ -52,6 +53,7 @@ describe('Writing app events', function() {
5253
API_KEY_ADMIN = testUtils.get("API_KEY_ADMIN");
5354
APP_ID = testUtils.get("APP_ID");
5455
APP_KEY = testUtils.get("APP_KEY");
56+
drill_db = testUtils.client.db("countly_drill");
5557
var params = [];
5658
request
5759
.get('/i?device_id=' + DEVICE_ID + '&app_key=' + APP_KEY + "&events=" + JSON.stringify(params))
@@ -167,8 +169,15 @@ describe('Writing app events', function() {
167169
});
168170
});
169171
/*{"2015":{"1":{"6":{"17":{"c":1},"c":1},"c":1},"c":1}}
170-
*/
172+
*/
171173
describe('verify events without params', function() {
174+
it("Verify granural data", function(done) {
175+
testUtils.validateTotalsInDrillData(
176+
drill_db,
177+
{app_id: APP_ID, event: "test", query: {}, values: {u: 1, t: 2}},
178+
done
179+
);
180+
});
172181
it('should have 2 event', function(done) {
173182
request
174183
.get('/o?api_key=' + API_KEY_ADMIN + '&app_id=' + APP_ID + '&method=events')
@@ -256,6 +265,13 @@ describe('Writing app events', function() {
256265
});
257266
});
258267
describe('verify events without params', function() {
268+
it("Verify granural data", function(done) {
269+
testUtils.validateTotalsInDrillData(
270+
drill_db,
271+
{app_id: APP_ID, event: "test", query: {}, values: {u: 1, t: 4}},
272+
done
273+
);
274+
});
259275
it('should have 4 test events', function(done) {
260276
request
261277
.get('/o?api_key=' + API_KEY_ADMIN + '&app_id=' + APP_ID + '&method=events')
@@ -340,12 +356,26 @@ describe('Writing app events', function() {
340356
});
341357
});
342358
describe('verify events without params', function() {
359+
it("Verify granural data(test)", function(done) {
360+
testUtils.validateTotalsInDrillData(
361+
drill_db,
362+
{app_id: APP_ID, event: "test", query: {}, values: {u: 1, t: 4}},
363+
done
364+
);
365+
});
366+
it("Verify granural data(test1)", function(done) {
367+
testUtils.validateTotalsInDrillData(
368+
drill_db,
369+
{app_id: APP_ID, event: "test1", query: {}, values: {u: 1, t: 1}},
370+
done
371+
);
372+
});
343373
it('should 1 test1 and 4 test events', function(done) {
344374
request
345375
.get('/o?api_key=' + API_KEY_ADMIN + '&app_id=' + APP_ID + '&method=events')
346376
.expect(200)
347377
.end(function(err, res) {
348-
testUtils.validateEvents(err, res, done, {c: 4});
378+
testUtils.validateEvents(err, res, done, {c: 5});
349379
});
350380
});
351381
});

test/3.api.write/8.checksums.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("Testing checksum validations", function() {
3636

3737
const responseObject = JSON.parse(response.text);
3838
responseObject.should.have.property("salt", TEST_SALT);
39-
setTimeout(done, 1000 * testUtils.testScalingFactor);
39+
setTimeout(done, 1000 * testUtils.testScalingFactor + 1000);
4040
});
4141
});
4242
});

0 commit comments

Comments
 (0)