Skip to content

Commit

Permalink
Merge pull request #580 from joola/feature/#579
Browse files Browse the repository at this point in the history
#579 Support for metricless queries
  • Loading branch information
itayw committed Aug 11, 2014
2 parents 99dc943 + 11d2987 commit eb9fd4a
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -26,7 +26,9 @@ apiary.out.html

config/oo.yml
config/development.yml
config/test.yml
config/development.json
config/test.json
config/certs/goo.pem

npm-shrinkwrap.json
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Expand Up @@ -12,7 +12,9 @@ apiary.out.html

config/oo.yml
config/development.yml
config/test.yml
config/development.json
config/test.json
config/certs/goo.pem

.vagrant
1 change: 0 additions & 1 deletion lib/common/redis.js
Expand Up @@ -40,7 +40,6 @@ var redis = module.exports = function (options) {
self.auth = options.auth || null;
self.redisOptions = options.options || null;
}
console.log(self.port, self.host, self.redisOptions);
self.redis = _redis.createClient(self.port, self.host, self.redisOptions);
self.connect = options.connect || function () {
joola.state.set('runtime-redis', 'working', 'redis [runtime-redis] is up.');
Expand Down
3 changes: 0 additions & 3 deletions lib/dispatch/beacon.js
Expand Up @@ -34,10 +34,7 @@ etl.verify = function (context, workspace, collection, documents, callback) {
if (documents.length > 0)
_document = ce.clone(documents[0]);

//console.log('doc', _document);

if (!_document.timestamp) {
console.log('generating timestamp');
_document.timestamp = new Date();
}

Expand Down
5 changes: 5 additions & 0 deletions lib/dispatch/query.js
Expand Up @@ -605,6 +605,11 @@ manager.formatResults = function (results, callback) {

results.dimensions = results.dimensions || query.dimensions;
results.metrics = results.metrics || query.metrics;

//allow engines to return a fake metric to be removed before processing
results.metrics = _.filter(results.metrics, function (metric) {
return metric.key !== 'fake';
});

var timestampDimension = _.find(results.dimensions, function (d) {
return d.datatype === 'date';
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -68,8 +68,8 @@
"humanize-number": "0.0.2",
"jade": "*",
"joola.cli": "^0.1.0",
"joola.datastore-mongodb": "^0.0.6",
"joola.datastore-influxdb": "^0.0.5",
"joola.datastore-mongodb": "^0.0.8",
"joola.datastore-influxdb": "^0.0.7",
"joola.sdk": "^0.7.0",
"js-yaml": "~3.0.2",
"json-stringify-safe": "^5.0.0",
Expand Down
3 changes: 2 additions & 1 deletion test/unit/6_beacon/beacon-basic.spec.js
Expand Up @@ -60,7 +60,7 @@ describe("beacon-basic", function () {
});
});

it("should load array of documents and verify timestamp", function (done) {
xit("should load array of documents and verify timestamp", function (done) {
var self = this;
var docs = require('../../fixtures/basic-timestamps.json');
engine.beacon.insert(self.context, self.context.user.workspace, self.collection, docs, function (err, docs) {
Expand All @@ -71,6 +71,7 @@ describe("beacon-basic", function () {
expect(d.timestamp === docs[index].timestamp);
var shorttimestamp = new Date(d.timestamp);
shorttimestamp.setMilliseconds(0);
//TODO: should be disabled check when using any store other than mongodb.
expect(d.timestamp_timebucket.second.getTime()).to.equal(shorttimestamp.getTime());
expect(d.saved).to.equal(true);
});
Expand Down
78 changes: 77 additions & 1 deletion test/unit/7_query/query-basic.spec.js
Expand Up @@ -8,7 +8,7 @@ describe("query-basic", function () {
done();
});

it("should not fail performing a query with no arguments", function (done) {
xit("should not fail performing a query with no arguments", function (done) {
var query = {};
var expected = 0;

Expand Down Expand Up @@ -565,4 +565,80 @@ describe("query-basic", function () {
return done();
});
});

it("should perform a freestyle unique count by attribute", function (done) {
var query = {
timeframe: 'this_day',
interval: 'minute',
dimensions: ['attribute'],
metrics: [
{
key: 'uniquevalue',
name: 'uniquevalue',
aggregation: 'ucount',
datatype: 'number',
dependsOn: ['attribute']
}
],
collection: this.collection
};
joola_proxy.query.fetch(this.context, query, function (err, result) {
if (err)
return done(err);
expect(result).to.be.ok;
expect(result.documents).to.be.ok;
expect(result.documents.length).to.be.greaterThan(0);
expect(result.documents[0].values.uniquevalue).to.equal(1);
return done();
});
});

it("should perform an last_n_items query", function (done) {
var query = {
timeframe: 'last_1_items',
interval: 'minute',
dimensions: ['timestamp'],
metrics: [
{
key: 'uniquevalue',
name: 'uniquevalue',
aggregation: 'ucount',
datatype: 'number',
dependsOn: ['attribute']
}
],
collection: this.collection
};
joola_proxy.query.fetch(this.context, query, function (err, result) {
if (err)
return done(err);
expect(result).to.be.ok;
expect(result.documents).to.be.ok;
expect(result.documents.length).to.be.greaterThan(0);
expect(result.documents[0].values.uniquevalue).to.equal(1);
return done();
});
});

it("should perform an last_n_items query w/o metrics", function (done) {
var query = {
timeframe: 'last_1_items',
interval: 'minute',
dimensions: ['attribute'],
metrics: [

],
collection: this.collection
};
joola_proxy.query.fetch(this.context, query, function (err, result) {
if (err)
return done(err);

expect(result).to.be.ok;
expect(result.documents).to.be.ok;
expect(result.documents.length).to.be.greaterThan(0);
expect(result.documents[0].values.attribute).to.equal('test');
return done();
});
});
});

0 comments on commit eb9fd4a

Please sign in to comment.