Skip to content

Events Batch Processing flow#20

Merged
emilianofant-split merged 19 commits intomainfrom
efant_eventsImpressions_retries_batchProcess
Jul 19, 2021
Merged

Events Batch Processing flow#20
emilianofant-split merged 19 commits intomainfrom
efant_eventsImpressions_retries_batchProcess

Conversation

@emilianofant-split
Copy link
Contributor

@emilianofant-split emilianofant-split commented Jul 7, 2021

Javascript Slim Synchronizer

What did you accomplish?

In this PR I'm adding:

  • The config to determine the batch size of elements to POP from Storage (Events)
  • Wrap the pop function into a function that can call itself recursively until there are no more elements in the Storage.
  • Added CLI config and manager capability to create an Event Synchroniser with a custom batch size value.

How do we test the changes introduced in this PR?

1 - Checkout this branch:
git checkout efant_eventsImpressions_retries_batchProcess
2 - Run unit tests
npm run test:unit

If you want to test it manually:
This file is a Custom Storage to connect with Redis, and can be used for manual tests.
For example:

npm run build && clear && ./dist/cli.js -k <A_VALID_APIKEY> -s ../path/to/inRedisStorage.cjs -r https://sdk.split-stage.io/api -e https://events.split-stage.io/api -p storagePrefix -n 100

Note the path to the Storage file

Related JIRA tickets and PRs

[Synchroniser] - Set retries strategy for Impressions/Events sync

Extra Notes

Next steps:

  • Add option to configure how many batches should be processed, or until 0 elements are in storage (by default)

Base automatically changed from efant_eventsImpressions_retries to main July 19, 2021 16:05
Copy link
Contributor

@EmilianoSanchez EmilianoSanchez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment about parsing and validating the new eventsPerPost config param. If you prefer, you can update it in another PR, but don't forget to add a TODO comment or to your checklist.

src/types.d.ts Outdated
export type SynchronizerConfigs = {
synchronizerMode: ExecutionMode;
eventsPerPost?: number;
eventsRequestRetriesAmount?: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this param used?. If events submitter ATTEMPTS_NUMBER is fixed at the moment, maybe we should remove it or at least put some comment to the eventsRequestRetriesAmount config param.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've forgotten to implement it into the submitters. I've just committed the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_sdkApiUrl = env.API_URL;
_eventsApiUrl = env.EVENTS_API_URL;
_storagePrefix = env.STORAGE_PREFIX as string;
synchronizerConfigs.eventsPerPost = env.EVENTS_PER_POST as unknown as number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how yargs works in detail, but if EVENTS_PER_POST is a string, we should parse it into a number (eventsPerPost is a number) and validate it. The same for other places where we must parse a string into a number.

Just as an example to explain it better:

value = parseInt(env.EVENTS_PER_POST, 10);
if (isNaNNumber(value) || value <= 0) {
   log.warn('EVENTS_PER_POST must be a positive integer number. Defaulting to ${DEFAULT_EVENTS_PER_POST');
   synchronizerConfigs.eventsPerPost = DEFAULT_EVENTS_PER_POST
} else {
   synchronizerConfigs.eventsPerPost = value;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, makes sense to preventively parse it to Number in case the value is get from .env or json file.

STORAGE_PREFIX,
customRun,
impressionsDebug,
eventsPerPost,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment, to consider when reviewing all together the public API, maybe this param should be renamed to eventBatchSizePerPost or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but right now I'm applying the same API naming from https://help.split.io/hc/en-us/articles/360019686092-Split-synchronizer-proxy#common-configuration-synchronizer-and-proxy-mode
We should discuss this with the team in order to agree in a common interface for all the synchronizers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants