falcon-metrics / falcon-metrics-api

MIT License
5 stars 1 forks source link

Introduction

The main reasons for having an api-based architecture are:

Use these reasons when deciding what functionality should reside behind the api-wall, and what can be dealt with by the clients of the apis. For example, statistical calculations and data extractions from the data sources should be placed behind the api-wall

Api scheme notes

API architecture is based on the Serverless Framework with Node.js running in AWS.

Thanks to the Offline plugin for Serverless (and other related plugins) we can deploy the API services locally so we should rarely have the need to spin off sandboxes in AWS to test.

Database functions

Many metrics are directly calculated at the DB level to enable faster processing. The DB functions required for the same are present in the database folder. Please make sure to run those commands to create the db functions if not present.

Dev env setup

:bulb: NOTE: This will pickup local lambda function changes without needing a restart. Occasionally you should restart npm run offline for memory reasons.

:warning: BUG: There is a bug in Serverless Offline when the JWT token contains multiple aud values (https://github.com/dherault/serverless-offline/pull/1070) until this is fixed you can either checkout the patched version and follow the instructions in CONTRIBUTING.md or start the API without authentication by running env DISABLE_AUTH=1 npm run offline

Create AWS Lambda sandbox

STAGE=<NAME> npm run deploy

When naming your AWS Lambda env, please include your name For example

STAGE=jsoap-dev npm run deploy

:bulb: NOTE: if you dont specify stage it will default to 'dev' :bulb: NOTE: Please keep AWS clean and remove your dev sandbox once you're done. You can always spin up a new sandbox quickly next time you need it.

AWS Console - Application List

AWS Lambda Logs

AWS Lambda function logs are available in CloudWatch. https://ap-southeast-2.console.aws.amazon.com/cloudwatch/home?region=ap-southeast-2#logs:

STAGE=<STAGE_NAME> serverless logs -f <FUNCTION_NAME>

Remove AWS Lambda environment

:warning: WARNING: If you create a new environment, please remove it when you no longer need it.

STAGE=<NAME> sls remove

Build Pipeline

GitLab CI

Versioning

Api versioning should be indicated in the path: <baseurl>/V1/<rest of api call>

If no version is included in the path, then latest version is to be assumed.

Available Scripts

npm deploy

:warning: WARNING: This will deploy to PROD!

This will deploy to AWS based on serverless.yml config. Usually we would manage deployment to Prod environment via GitLab CI. GitLab will then setup API Version env vars

npm test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

npm run format

This will execute eslint and re-format code according to the lint rules.

References

Points to note

Auth0

Contact us

Datadog

Slack

Logo

Demo organisation

Hubspot

Serverless

Mailchimp