1.4.5 • Published 28 days ago

faros-feeds-sdk v1.4.5

Weekly downloads
207
License
Apache-2.0
Repository
github
Last release
28 days ago

feeds-sdk

An SDK that simplifies feed development by handling all Faros API interactions. A feed is a tool that extracts data from an external data source, typically an IaaS or PaaS API, and loads it into Faros.

Uploading data

The SDK includes two functions for uploading data to the Faros platform: withEntryUploader and entryUploader. They have slightly different signatures, but they both wrap all the necessary API calls to the Faros platform, so you can focus on what's unique to your feed. Choosing one comes down to whether your feed requires state to be persisted between runs.

Stateless feeds

Feeds which do not need to persist state between runs can use entryUploader. This will give you a stream.Writable whose entries are uploaded to the API.

Example of using entryUploader:

import {entryUploader} from 'faros-feeds-sdk';

const writer = await entryUploader({
  name: 'EC2',
  // Other required parameters...
});

// Written entries will be streamed to the API
writer.write({
  ec2_Instance: {
    instanceId: 'i-0ef827cbfe244614f',
    instanceType: 't2.micro',
    state: {
      code: 80,
      name: 'stopped',
    },
    launchedAt: new Date(1607473249000),
  },
});

// Write more entries and finally:
writer.end();

Stateful feeds

When possible, it's good practice to support incremental data ingestion. In order to do so, use withEntryUploader, which comes with a callback you can use to read the existing feed state, and return the new state.

Example of using withEntryUploader:

import {withEntryUploader} from 'faros-feeds-sdk';

export interface FeedState {
  readonly lastLaunchedAt: number;
}

const uploaderCfg = {
  name: 'EC2',
  // Other required parameters...
};
await withEntryUploader<FeedState>(uploaderCfg, (writer, state) => {
  // Write entries to writer using the old state...
  return /* new state */;
});

Lambda runner

The feeds SDK also includes a convenience function called createLambdaHandler for generating a lambda handler if you would like to run your feed in Faros's Lambda environment.

:clipboard: Note: The resulting lambda handler is only compatible with feeds that have been set up and scheduled via Faros's /accounts API, because of the very specific way in which it handles feed params.

The lambda handler decrypts secrets, params, and environment variables provided by the Faros scheduler, and passes them on to a user defined runFeed method that in turn uses them to run the feed. Example usage:

import {createLambdaHandler, FarosEnv} from 'faros-feeds-sdk';

async function runFeed(env: FarosEnv): Promise<void> {
  // validate input params
  // run the feed
}

export const lambdaHandler = createLambdaHandler(runFeed);

An example FarosEnv for the GitHub feed might look something like this:

{
  "token": "myGitHubToken",
  "orgLogin": "acme",
  "repoList": ["repo1", "repo2"],
  "farosApiUrl": "https://prod.api.faros.ai",
  "farosApiKey": "myFarosApikey",
  "runMode": "Root",
  "logger": Logger
}

Worker Feeds

The createLambdaHandler also takes in an optional parameter partition, which is a function will takes the FarosEnv and returns a list of FarosEnv to enable parallel execution of the feed. The root feed should adapt each sub FarosEnv with the appropriate param the feed needs to run.

:clipboard: Note: Create unique values of the param the feed uses as the origin to ensure correct handling of the worker's feed state.

import {createLambdaHandler, FarosEnv} from 'faros-feeds-sdk';

async function runFeed(env: FarosEnv): Promise<void> {
  // validate input params
  // run the feed
}

async function partition(env: FarosEnv): Promise<Map<string, FarosEnv>> {
  // return map of farosEnv with split params
  // e.g. return new Map([['partition1', farosEnv]])
}

export const lambdaHandler = createLambdaHandler(runFeed, partition);

Logging

The FarosEnv passes a logger to the feed. This logger should be used by the feed for all logging to ensure logs are correctly stored.

Links

  1. Canonical models. This library can be used for the sdl property of EntryUploaderConfig. See the docs for details.
1.4.5

28 days ago

1.4.4

1 month ago

1.4.3

1 month ago

1.4.2

1 month ago

1.4.1

1 month ago

1.4.0

5 months ago

1.3.5

5 months ago

1.3.4

5 months ago

1.3.3

6 months ago

1.2.0

9 months ago

1.3.2

8 months ago

1.3.1

8 months ago

1.3.0

9 months ago

1.1.7

10 months ago

1.1.6

10 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.3

1 year ago

0.13.9

2 years ago

0.14.0

1 year ago

0.14.1

1 year ago

0.14.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.13.12

1 year ago

0.13.11

2 years ago

0.13.10

2 years ago

0.13.14

1 year ago

0.13.13

1 year ago

0.13.6

2 years ago

0.13.7

2 years ago

0.13.8

2 years ago

0.13.3

2 years ago

0.13.4

2 years ago

0.13.5

2 years ago

0.13.1

2 years ago

0.11.0

2 years ago

0.11.1

2 years ago

0.13.0

2 years ago

0.11.2

2 years ago

0.11.3

2 years ago

0.11.4

2 years ago

0.11.5

2 years ago

0.11.6

2 years ago

0.12.7

2 years ago

0.12.8

2 years ago

0.12.0

2 years ago

0.12.1

2 years ago

0.12.2

2 years ago

0.12.3

2 years ago

0.12.4

2 years ago

0.12.5

2 years ago

0.12.6

2 years ago

0.10.0-rc.2

2 years ago

0.10.0-rc.1

2 years ago

0.10.0-rc.0

2 years ago

0.10.0-rc.3

2 years ago

0.10.0

2 years ago

0.9.11

2 years ago

0.9.10

2 years ago

0.9.8

2 years ago

0.9.7

2 years ago

0.9.9

2 years ago

0.9.4

2 years ago

0.9.3

2 years ago

0.9.6

2 years ago

0.9.5

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.0

3 years ago

0.8.34

3 years ago

0.8.35

3 years ago

0.8.33

3 years ago

0.8.32

3 years ago

0.8.31

3 years ago

0.8.30

3 years ago

0.8.29

3 years ago

0.8.28

3 years ago

0.8.27

3 years ago

0.8.26

3 years ago

0.8.25

3 years ago

0.8.23

3 years ago

0.8.24

3 years ago

0.8.22

3 years ago

0.8.21

3 years ago

0.8.20

3 years ago

0.8.19

3 years ago

0.8.18

3 years ago

0.8.17

3 years ago

0.8.16

3 years ago

0.8.14

3 years ago

0.8.15

3 years ago

0.8.9

3 years ago

0.8.8

3 years ago

0.8.5

3 years ago

0.8.7

3 years ago

0.8.6

3 years ago

0.8.12

3 years ago

0.8.11

3 years ago

0.8.13

3 years ago

0.8.10

3 years ago

0.8.4

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.7.0

3 years ago

0.6.3

3 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.3.0

3 years ago

0.4.0

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.1-rc.2

3 years ago

0.0.1-rc.1

3 years ago