Giter Site home page Giter Site logo

deej-split / impressions-query-by-key Goto Github PK

View Code? Open in Web Editor NEW

This project forked from splitio/impressions-query-by-key

0.0 0.0 0.0 243 KB

Query for impressions by split key, drawing on a DynamoDB-backed store of impressions seen.

JavaScript 65.92% HTML 34.08%

impressions-query-by-key's Introduction

Impressions Query By Key

Ever needed to know immediately what impressions a customer had recently received? Even if you capture impressions, is it slow and awkward to search them? No more!

In short, a service that allows HTTP GET query to retrieve all impressions for a specific Split key.

https://<lambda function url>/<split_key>

... returns a JSON list of abridged impressions for that split key.

[
    {
        "treatment": "on",
        "split": "next_step",
        "time": 1659231532349,
        "key": "dmartin-dogs"
    },
    {
        "treatment": "red",
        "split": "multivariant_demo",
        "time": 1659233452345,
        "key": "dmartin-dogs"
    },
    {
        "treatment": "on",
        "split": "next_step",
        "time": 1659231531796,
        "key": "dmartin-dogs"
    },
    ...
]

UPDATE

I have provided an index.html as sample "front end". The page presents a search box for key to query. You can sort by column and search results.

You must substitute the URL of your lambda function in order to use it:

async function getSearchResults(query) {
   const url = 'https://<lambda function url>/' + query;

How does it work?

digest is a lambda impressions webhook POST. It writes impressions in batches of twenty-five to a backing DynamoDB table. You register it with the Split Impressions Webhook.

search uses a global secondary index to pull all the impressions for a specific split key, then return them in JSON form as a response. It is a GET function URL, its only paramter the Split key you want to query.

Impressions are automatically deleted from the DynamoDB table using its Time to Live (TTL) feature on the ttl column of the table, which is in seconds since the epoch (not the usual Split milliseconds since epoch). You can control the TTL by editing the digest lambda script; the script stamps impressions with a TTL when they are loaded to DynamoDB. Impressions older than the ttl are automatically deleted from the impressions table.

Installation

The lambdas must be set up with permission to DynamoDB, and a suitable DynamoDB table must be created for the backing store, with Global Secondary Index on key. Screenshots are included with this repository. TTL must be set up on the ttl attribute of the DynamoDB table.

Known Issues

When first creating the database and installing its Global Secondary Index, the search lambda may get errors:

ValidationException: Cannot read from backfilling global secondary index: key-index

These errors should resolve within a few minutes.

DynamoDB returns up to 1MB of data with a single query. This should be hundreds, or nearly a thousand impressions. I have not tested the response when more impressions are returned, but I expect it to be a truncated result (maybe with no indication it was truncated).

[email protected]

ROUGH DRAFT OF INSTRUCTIONS

git clone https://github.com/splitio/impressions-query-by-key.git

ADVANCED

If you want to change the 7 day default time to live on impressions, you can edit the digest/index.js to change the default as suits you.

const ttl = nowInSeconds + (60 * 60 * 24 * 7);

Change 7 to 14 for a fourteen day rentention, etc.

Creating the Lambda ZIPs

In each sub-directory (digest and search):

npm install
zip -r digest.zip *

Or search.zip in the search subdirectory. This should create a zip file with index.js and a richly defined node_modules/ subdirectory. Most of the dependency code is on the aws-sdk, necessary to use DynamoDB.

AWS

From AWS, create new lambdas, one for digest and one for search.

Upload the zip you created above from the Code section of the lambda config.

  • Give the Lambdas DynamoDB permission
  • Give the Lambdas function URLs

Digest gets a POST function. Search gets a GET function. You probably also want to enable CORS support, and maybe accept all headers, with a *

Digest lambdas POST function URL is the webhook URL to install in Split. Split impressions webhook.

DynamoDB table...

  • DIGEST_IMPRESSIONS is the expected name
  • ID as partition key, key as sort key
  • From Indexes tab, create a new Global Secondary Index. key as partition key, key-index as index name.
  • From Additional settings, turn on TTL with ttl as attribute name

Generate some impressions by exercising a split. Use Live Tail to check the impressions are received by Split. Use Cloud Watch to see your digest lambda is writing the impressions to DynamoDB table. Call your search lambda with one of the keys you saw received to verify you are a success.

Questions?

[email protected]

impressions-query-by-key's People

Contributors

dbmartin00 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.