Skip to content

Commit

Permalink
misc prerelease fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-darkly committed Nov 15, 2018
1 parent 8a0588e commit 8b60ef6
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
package-lock.json
junit.xml

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change log

All notable changes to the LaunchDarkly Node.js SDK DynamoDB integration will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).

## [1.0.0] - 2018-11-15

Initial release.
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2018 Catamorphic, Co.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
LaunchDarkly SDK for Node.js - DynamoDB integration
===================================================
[![CircleCI](https://circleci.com/gh/launchdarkly/node-dynamodb-store.svg?style=svg)](https://circleci.com/gh/launchdarkly/node-dynamodb-store)

This library provides a DynamoDB-backed persistence mechanism (feature store) for the [LaunchDarkly Node.js SDK](https://github.com/launchdarkly/node-client), replacing the default in-memory feature store. It uses the AWS SDK for Node.js.

The minimum version of the LaunchDarkly Node.js SDK for use with this library is 5.6.0.

For more information, see also: [Using a persistent feature store](https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store)

Quick setup
-----------

This assumes that you have already installed the LaunchDarkly Node.js SDK.

0. Install this package with `npm`

npm install ldclient-node-dynamodb-store --save

1. Require the package:

var DynamoDBFeatureStore = require('ldclient-node-dynamodb-store');

2. When configuring your SDK client, add the DynamoDB feature store:

var store = DynamoDBFeatureStore('YOUR TABLE NAME');
var config = { featureStore: store };
var client = LaunchDarkly.init('YOUR SDK KEY', config);

The specified table must already exist in DynamoDB. It must have a partition key called "namespace" and a sort key called "key".

By default, the DynamoDB client will try to get your AWS credentials and region name from environment variables and/or local configuration files, as described in the AWS SDK documentation. You can also specify any valid [DynamoDB client options](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#constructor-property) like this:

var dynamoDBOptions = { accessKeyId: 'YOUR KEY', secretAccessKey: 'YOUR SECRET' };
var store = DynamoDBFeatureStore('YOUR TABLE NAME', { clientOptions: dynamoDBOptions });

Alternatively, if you already have a fully configured DynamoDB client object, you can tell LaunchDarkly to use that:

var store = DynamoDBFeatureStore('YOUR TABLE NAME', { dynamoDBClient: myDynamoDBClientInstance });

3. If you are running a [LaunchDarkly Relay Proxy](https://github.com/launchdarkly/ld-relay) instance, or any other process that will prepopulate the DynamoDB table with feature flags from LaunchDarkly, you can use [daemon mode](https://github.com/launchdarkly/ld-relay#daemon-mode), so that the SDK retrieves flag data only from DynamoDB and does not communicate directly with LaunchDarkly. This is controlled by the SDK's `useLdd` option:

var config = { featureStore: store, useLdd: true };
var client = LaunchDarkly.init('YOUR SDK KEY', config);

Caching behavior
----------------

To reduce traffic to DynamoDB, there is an optional in-memory cache that retains the last known data for a configurable amount of time. This is on by default; to turn it off (and guarantee that the latest feature flag data will always be retrieved from DynamoDB for every flag evaluation), configure the store as follows:

var store = DynamoDBFeatureStore('YOUR TABLE NAME', { cacheTTL: 0 });

About LaunchDarkly
-----------

* LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
* Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
* Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
* Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
* Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
* LaunchDarkly provides feature flag SDKs for
* [Java](http://docs.launchdarkly.com/docs/java-sdk-reference "Java SDK")
* [JavaScript](http://docs.launchdarkly.com/docs/js-sdk-reference "LaunchDarkly JavaScript SDK")
* [PHP](http://docs.launchdarkly.com/docs/php-sdk-reference "LaunchDarkly PHP SDK")
* [Python](http://docs.launchdarkly.com/docs/python-sdk-reference "LaunchDarkly Python SDK")
* [Go](http://docs.launchdarkly.com/docs/go-sdk-reference "LaunchDarkly Go SDK")
* [Node.JS](http://docs.launchdarkly.com/docs/node-sdk-reference "LaunchDarkly Node SDK")
* [.NET](http://docs.launchdarkly.com/docs/dotnet-sdk-reference "LaunchDarkly .Net SDK")
* [Ruby](http://docs.launchdarkly.com/docs/ruby-sdk-reference "LaunchDarkly Ruby SDK")
* [iOS](http://docs.launchdarkly.com/docs/ios-sdk-reference "LaunchDarkly iOS SDK")
* [Android](http://docs.launchdarkly.com/docs/android-sdk-reference "LaunchDarkly Android SDK")
* Explore LaunchDarkly
* [launchdarkly.com](http://www.launchdarkly.com/ "LaunchDarkly Main Website") for more information
* [docs.launchdarkly.com](http://docs.launchdarkly.com/ "LaunchDarkly Documentation") for our documentation and SDKs
* [apidocs.launchdarkly.com](http://apidocs.launchdarkly.com/ "LaunchDarkly API Documentation") for our API documentation
* [blog.launchdarkly.com](http://blog.launchdarkly.com/ "LaunchDarkly Blog Documentation") for the latest product updates
* [Feature Flagging Guide](https://github.com/launchdarkly/featureflags/ "Feature Flagging Guide") for best practices and strategies
7 changes: 6 additions & 1 deletion dynamodb_feature_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ var winston = require('winston');
var CachingStoreWrapper = require('ldclient-node/caching_store_wrapper');

var initializedToken = { namespace: '$inited', key: '$inited' };
var defaultCacheTTLSeconds = 15;

function DynamoDBFeatureStore(tableName, options) {
return new CachingStoreWrapper(new dynamoDBFeatureStoreInternal(tableName, options));
var ttl = options && options.cacheTTL;
if (ttl === null || ttl === undefined) {
ttl = defaultCacheTTLSeconds;
}
return new CachingStoreWrapper(new dynamoDBFeatureStoreInternal(tableName, options), ttl);
}

function dynamoDBFeatureStoreInternal(tableName, options) {
Expand Down
19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
{
"name": "ldclient-node-dynamo-store",
"name": "ldclient-node-dynamodb-store",
"version": "1.0.0",
"description": "DynamoDB-backed feature store for the LaunchDarkly node.js SDK",
"main": "dynamo_db_feature_store.js",
"description": "DynamoDB-backed feature store for the LaunchDarkly Node.js SDK",
"main": "dynamodb_feature_store.js",
"license": "Apache-2.0",
"scripts": {
"test": "jest --ci --forceExit"
},
"devDependencies": {
"eslint": "5.8.0",
"jest": "23.6.0",
"jest-junit": "5.2.0"
"jest-junit": "5.2.0",
"ldclient-node": ">= 5.6.0"
},
"jest": {
"rootDir": ".",
"testEnvironment": "node",
"testMatch": [
"**/*-test.js"
]
],
"testResultsProcessor": "jest-junit"
},
"dependencies": {
"aws-sdk": "2.349.0",
"ldclient-node": "file:../node-client-private/",
"node-cache": "4.2.0",
"winston": "2.4.1"
},
"peerDependencies": {
"ldclient-node": ">= 5.6.0"
},
"engines": {
"node": ">= 0.8.x"
},
Expand Down
58 changes: 33 additions & 25 deletions tests/dynamodb_feature_store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var AWS = require('aws-sdk');
describe('DynamoDBFeatureStore', function() {

AWS.config.update({
credentials: { accessKeyId: 'fake', secretAccessKey: 'fake' },
region: 'us-west-2',
endpoint: 'http://localhost:8000'
});
Expand All @@ -14,43 +15,44 @@ describe('DynamoDBFeatureStore', function() {
var table='test-store';

beforeAll(function(done) {
var params = {
TableName: table,
KeySchema: [
{ AttributeName: 'namespace', KeyType: 'HASH'}, //Partition key
{ AttributeName: 'key', KeyType: 'RANGE' } //Sort key
],
AttributeDefinitions: [
{ AttributeName: 'namespace', AttributeType: 'S' },
{ AttributeName: 'key', AttributeType: 'S' }
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
dynamodb.describeTable({ TableName: table }, function(err) {
if (!err) {
done();
return;
}
};

dynamodb.deleteTable({ TableName: table }, function(err) {
if (err) {
jasmine.error('Unable to delete table. Error JSON:', JSON.stringify(err, null, 2));
}
var params = {
TableName: table,
KeySchema: [
{ AttributeName: 'namespace', KeyType: 'HASH'}, //Partition key
{ AttributeName: 'key', KeyType: 'RANGE' } //Sort key
],
AttributeDefinitions: [
{ AttributeName: 'namespace', AttributeType: 'S' },
{ AttributeName: 'key', AttributeType: 'S' }
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
};

dynamodb.createTable(params, function(err) {
if (err) {
jasmine.error('Unable to create table. Error JSON:', JSON.stringify(err, null, 2));
done.fail('Unable to create table. Error JSON: ' + JSON.stringify(err, null, 2));
}
waitForTable(done);
});
});
});

function waitForTable(done) {
dynamodb.describeTable({ TableName: table }, function(err) {
dynamodb.describeTable({ TableName: table }, function(err, tableInfo) {
if (err) {
if (err.code == 'ResourceNotFoundException') {
if (err.code == 'ResourceNotFoundException' || (tableInfo && tableInfo.Table.TableStatus == 'TableStatusActive')) {
setTimeout(function () { waitForTable(done); }, 100);
} else {
jasmine.error('Unable to create table: ', JSON.stringify(err, null, 2));
done.fail('Unable to create table: ' + JSON.stringify(err, null, 2));
}
} else {
done();
Expand Down Expand Up @@ -94,7 +96,13 @@ describe('DynamoDBFeatureStore', function() {
return store;
}

testBase.baseFeatureStoreTests(makeStore, clearTable, false);
testBase.baseFeatureStoreTests(makeStoreWithoutCache, clearTable, false);
testBase.concurrentModificationTests(makeStoreWithoutCache, makeStoreWithHook);
describe('cached', function() {
testBase.baseFeatureStoreTests(makeStore, clearTable, true);
});

describe('uncached', function() {
testBase.baseFeatureStoreTests(makeStoreWithoutCache, clearTable, false);
});

testBase.concurrentModificationTests(makeStore, makeStoreWithHook);
});

0 comments on commit 8b60ef6

Please sign in to comment.