Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Tool: Events indexing service - Milestone 3 #95

Merged
merged 1 commit into from
Nov 4, 2021

Conversation

prpatel05
Copy link
Contributor

@prpatel05 prpatel05 commented Oct 30, 2021

New Tool: Events indexing service - Milestone 3

Description

This PR is for issue #15

  • Implement the remaining minimum feature set and the event delivery (consumer) mechanism.

Submission Links & Documents

Code Package: https://github.com/prpatel05/FlowRider (reach out if you need access)

> The service should deliver each event to an external consumer (i.e. a dapp backend) as a JSON payload.
>> At a minimum, the service should support event delivery via HTTP webhooks. In this scenario, the consuming application will provide an HTTP endpoint as part of the startup configuration. The consumer should respond with appropriate status consumes to indicate a successful or unsuccessful delivery — these status codes are defined by the indexer.
Event Publisher Interface - This allows different publishing mechanism beyond HTTP, e.g. SNS, SQS, etc. For now I implement two publishers -
Console Log - Really straightforward, outputs the event to the console. Useful for testing just to validate that everything is configured and working. Don't expect anyone to use this, but shows the ability to have >1 publisher and how simple it is to implement it.
HTTP - POSTs the event to a configured endpoint and expects the response to be a 200 || 204. Additionally, includes a signature so that the consumer can verify the event came from the trusted source (for now the secret is provided by the customer, this can be provided by a managed service as well).
>> The service only needs to support delivery to a single consumer.
Done here - Currently just one publisher, however, it should be simple to make this an Array and multiplex the events.
>> All events should be delivered in the same order they were emitted on-chain.
Done here - JS is single threaded and we await each publish event. Additionally, we will stop processing events if one fails and pick up from where we last tried.
>> Each event should be delivered exactly once. The indexer will need to implement logic to ensure idempotency of events.
Interface
In Memory Implementation - We moved this into the implementing logic based on feedback from Milestone 2. For now I just implemented a simple in-memory store. However, post Flip Fest, we can make this more "Production" ready and use a DB/local DB to have this data persisted.

Tests

Requirements Check

  • Have have you met the milestone requirements? - Yes
  • Have you included tests (if applicable)? - Yes
  • Have you met the contribution guidelines of the repos you have submitted code to (if applicable)? - Yes
  • If this is the last milestone: - N/A
    • Demonstrate that you've met all the acceptance criteria (link to code, demos, instructions to run etc.) - N/A
    • Demonstrate that you've met all milestone requirements and highlight any extensions or additional work done. - N/A
    • Include a payout structure by percentage for each team member (ie. Bob: 20%, Alice: 80%). - N/A

Other Details

@prpatel05
Copy link
Contributor Author

See some context here - #45 and #74

The main thing I want to highlight here is that we want to prove feasibility of the product first as a development tool used along side the Flow Emulator. Because of this we are doing some caching locally in memory for data and it is by-design that these things will not be persisted. I think the important thing to review here is the interfaces and see if they make sense and we can implement more "production" grade tech down the line (e.g. DB, Cloud, etc). Let me know if you agree with this approach.

In Milestone 4 what I am really pushing for is a simple CLI you run alongside the Flow Emulator that let's you build/test dapps events very quickly.

@kerrywei kerrywei requested a review from nvdtf November 1, 2021 17:29
@nvdtf
Copy link
Member

nvdtf commented Nov 2, 2021

I followed the instructions here https://www.flowrider.io/install to get the project running but I'm getting:

~/go/src/github.com/prpatel05/FlowRider on git:main ●
→ lerna run build
info cli using local version of lerna
lerna notice cli v4.0.0
lerna info versioning independent
lerna info Executing command in 2 packages: "yarn run build"
lerna info run Ran npm script 'build' in '@flow-rider/event-indexer' in 9.4s:
yarn run v1.22.10
$ tsc
Done in 9.18s.
lerna info run Ran npm script 'build' in '@flow-rider/cli' in 2.9s:
yarn run v1.22.10
$ tsc
Done in 2.73s.
lerna success run Ran npm script 'build' in 2 packages in 12.3s:
lerna success - @flow-rider/cli
lerna success - @flow-rider/event-indexer

~/go/src/github.com/prpatel05/FlowRider on git:main ●
→ yarn install --force
yarn install v1.22.10
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "workspace-aggregator-0d4b1ce1-738c-4d2c-9634-f61fcd19c9cd > @flow-rider/cli > [email protected]" has unmet peer dependency "@types/node@*".
warning "workspace-aggregator-0d4b1ce1-738c-4d2c-9634-f61fcd19c9cd > @flow-rider/event-indexer > @onflow/fcl > @onflow/sdk > @improbable-eng/[email protected]" has unmet peer dependency "google-protobuf@^3.14.0".
[4/4] 🔨  Rebuilding all packages...
success Saved lockfile.
✨  Done in 2.13s.

~/go/src/github.com/prpatel05/FlowRider on git:main ●
→ flow-rider -h
zsh: command not found: flow-rider

Am I doing something wrong?

@prpatel05
Copy link
Contributor Author

Hmmm seems like might be a PATH issue. Can you try running yarn bin flow-rider in that directory? It should return the path to the binary, and from there you can try to invoke it using that absolute path.

FYI: This is not the long-term UX from installation, once this is in a public NPM repo npm install -g flow-rider is all that they will need to do.

@nvdtf
Copy link
Member

nvdtf commented Nov 2, 2021

Thanks yeah I got it working. The binary ended up in github.com/prpatel05/FlowRider/node_modules/.bin

Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.
Indexing Events For A.c1e4f4f4c4257510.Market.MomentWithdrawn starting at 19944775
No Events found.  Exiting.

The console log here seems confusing. The logic to check if we have already processed a block is after the log so it might be misleading if we're double processing all these block heights. We also need to change "Exiting" as the program is not exiting at that point.

Looking at the repo generally, I think it's came together well. Thanks for the great work!

@prpatel05
Copy link
Contributor Author

Yeah that makes sense, I will play around with some dynamic console logging like using something like this - https://www.npmjs.com/package/cli-progress

I am curious on your thoughts about what to do once we have read all events and are at the "latest" block height. While waiting for new blocks to seal, should we just continually loop? Or is there some average "time to seal block" time that we can sleep on so we don't continually ping that API while waiting.

@nvdtf
Copy link
Member

nvdtf commented Nov 2, 2021

At that point we're just waiting for a new block to be available to process, so the message can be "Processed up to height 424242. Waiting for a new block ..." on each iteration.

The Flow block time is ~1s so if you loop with that interval it would roughly match the block seal rate. In reality the number can differ (right now it's ~2.5s sometimes).

@prpatel05
Copy link
Contributor Author

prpatel05 commented Nov 2, 2021

OK made the terminal output cleaner, see - https://gyazo.com/d2bc83c2489f5d3e69f53cfc2e3bffc9 (the right terminal). Much more dynamic in that we will only show the latest actions. Additionally, this will work in a no TTY setup and simply just log the entire line.

@prpatel05
Copy link
Contributor Author

Let me know if you would like to see anything else specific to this Milestone, otherwise feel free to merge and ill work on the comments for Milestone 4.

@nvdtf
Copy link
Member

nvdtf commented Nov 2, 2021

Nice!
Can you update the logger to print new lines on each output instead of updating 1 line? If you're looking into containerization that type of log makes it much more easier to debug. I imagine the CLI binary will be run inside a Docker image and the logs will be captured by a logging service of some sort.

@prpatel05
Copy link
Contributor Author

This will actually be supported by default if we detect a non-TTY environment, e.g. CloudWatch Logs, Docker logs, etc. See - https://gyazo.com/1bccbdb42f97b2d798e72ea58d0a5904 - for an example of this. That being said, I will make this a CLI argument as well, e.g. flow-rider start ... (-d || --debug) in case a user running locally wants to see everything.

@nvdtf
Copy link
Member

nvdtf commented Nov 2, 2021

Oh nice thank you for the clarification. I think we're good enough for acceptance criteria here. Nice work!

@kerrywei
Copy link

kerrywei commented Nov 4, 2021

merge in the PR per Navid's comment

@kerrywei kerrywei merged commit fc11948 into onflow:main Nov 4, 2021
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.

3 participants