Skip to content

Commit

Permalink
Added loggin and several fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundocabrera committed Jan 16, 2016
1 parent eec95fb commit ea2df54
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 18 deletions.
5 changes: 3 additions & 2 deletions packages/splitio-cache/es6/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

var segmentChangesDataSource = require('./ds/segmentChanges');
var splitChangesDataSource = require('./ds/splitChanges');

var storage = require('./storage');
var log = require('debug')('splitio-cache');

function writer(authorizationKey) {
log(`Running updater using key: ${authorizationKey}`);

return splitChangesDataSource({authorizationKey})
.then(splitsMutator => {
Expand All @@ -21,4 +22,4 @@ function writer(authorizationKey) {

}

exports.writer = writer;
module.exports = writer;
4 changes: 2 additions & 2 deletions packages/splitio-cache/es6/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = {
segments = segments.set(name, segmentSet);
},

updateSplit(featureName, splitDTO) {
splits = splits.set(featureName, splitDTO);
updateSplit(featureName, split) {
splits = splits.set(featureName, split);
},

getSplit(featureName) {
Expand Down
8 changes: 7 additions & 1 deletion packages/splitio-engine/es6/engine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var partitionTypes = require('../partitions/types');
var murmur = require('murmurhash-js');
var log = require('debug')('splitio-engine');

var engine = {
/**
Expand All @@ -19,7 +20,12 @@ var engine = {
* @return {boolean}
*/
isOn(key /*: string */, seed /*: number */, partitions /*: Map */) {
return partitions.get(partitionTypes.enum.ON) >= (murmur(key, seed) % 100);
let percentageOn = partitions.get(partitionTypes.enum.ON);
let keyPercentageValue = (murmur(key, seed) % 100);

log(`[engine] percentage on ${percentageOn} and key ${keyPercentageValue}`);

return percentageOn >= keyPercentageValue;
}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/splitio-engine/es6/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ class Split {
}

isOn(key) {
this.evalutor(key, this.baseInfo.seed);
return this.evaluator(key, this.baseInfo.seed);
}

static parse(splitFlatStructure) {
let {conditions, ...baseInfo} = splitFlatStructure;
let {evaluator, segments} = parser(conditions);

return new SplitDTO(baseInfo, evaluator, segments);
return new Split(baseInfo, evaluator, segments);
}

}
Expand Down
6 changes: 5 additions & 1 deletion packages/splitio-engine/es6/matchers/identity.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';

module.exports = function () {
var log = require('debug')('splitio-engine:matcher');

module.exports = function identityMatcher() {
log('[identityMatcher] always true');

return true;
};
7 changes: 6 additions & 1 deletion packages/splitio-engine/es6/matchers/segment.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
'use strict';

var storage = require('splitio-cache/src/storage');
var log = require('debug')('splitio-engine:matcher');

function matcherSegmentContext(segmentName /*: string */) {
return function segmentMatcher(key /*: string */) {
return storage.getSegment(segmentName).has(key);
let isInSegment = storage.getSegment(segmentName).has(key);

log(`[segmentMatcher] evaluated ${segmentName} / ${key} => ${isInSegment}`);

return isInSegment;
};
}

Expand Down
9 changes: 7 additions & 2 deletions packages/splitio-engine/es6/matchers/whitelist.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

'use strict';

var log = require('debug')('splitio-engine:matcher');

/**
* Check if a key is inside a whitelist.
*
Expand All @@ -10,7 +11,11 @@
*/
function whitelistMatcherContext(whitelist /*: Set */) {
return function whitelistMatcher(key /*: string */) {
return whitelist.has(key);
let isInWhitelist = whitelist.has(key);

log(`[whitelistMatcher] evaluated ${whitelist} / ${key} => ${isInWhitelist}`);

return isInWhitelist;
};
}

Expand Down
7 changes: 5 additions & 2 deletions packages/splitio/es6/core/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ var updater = require('splitio-cache');

var core = {
schedule(fn /*: function */, delay /*: number */, ...params /*:? Array<any> */) {
setTimeout(fn, delay, ...params);
setTimeout(() => {
fn(...params);
this.schedule(fn, delay, ...params);
}, delay);
},

start(authorizationKey /*: string */) {
Expand All @@ -14,7 +17,7 @@ var core = {
}

// fire cache updater each 5 seconds
this.schedule(writer, 5000, authorizationKey);
this.schedule(updater, 5000, authorizationKey);

return storage;
});
Expand Down
14 changes: 13 additions & 1 deletion packages/splitio/es6/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var core = require('./core');
var log = require('debug')('splitio');

function splitter(authorizationKey /*: string */) {
return core.start(authorizationKey).then(storage => {
Expand All @@ -9,7 +10,18 @@ function splitter(authorizationKey /*: string */) {
* Evaluates is a given userId is enabled for a given feature.
*/
isOn(userId /*: string */, featureName /*: string */) {
return storage.getSplit(featureName).evaluate(userId);
let split = storage.getSplit(featureName);

if (split) {
let splitEvaluation = split.isOn(userId);

log(`[splitio] feature ${featureName} key ${userId} evaluated as ${splitEvaluation}`);

return splitEvaluation;
} else {
console.log('Feature is not present yet');
return false;
}
}
};
});
Expand Down
7 changes: 3 additions & 4 deletions scripts/development.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/usr/bin/env bash

npm link packages/splitio-engine
npm link packages/splitio-cache
npm link packages/splitio

cd packages/splitio-cache
rm -rf src/
rm -rf node_modules/
npm install
npm link
npm run watch &
npm run watch-test &
cd -
Expand All @@ -16,6 +13,7 @@ cd packages/splitio-engine
rm -rf src/
rm -rf node_modules/
npm install
npm link
npm run watch &
npm run watch-test &
cd -
Expand All @@ -24,6 +22,7 @@ cd packages/splitio
rm -rf src/
rm -rf node_modules/
npm install
npm link
npm run watch &
npm run watch-test &
cd -

0 comments on commit ea2df54

Please sign in to comment.