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

feat: zinniad for Filecoin Station #141

Merged
merged 8 commits into from
Mar 28, 2023
Merged

feat: zinniad for Filecoin Station #141

merged 8 commits into from
Mar 28, 2023

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Mar 27, 2023

Implement a new binary zinniad that can run multiple modules at the same time and acts as another Filecoin Station Module.

See #75

Out of Scope

Usage

❯ zinniad --help
Zinnia daemon runs Zinnia modules inside Filecoin Station.

Usage: zinniad [OPTIONS] --wallet-address <WALLET_ADDRESS> [FILES]...

Arguments:
  [FILES]...  List of modules to run, where each module is a single JS file. We don't make any assumptions about the directory layout of modules. Paths are resolved relatively to the current working directory

Options:
  -w, --wallet-address <WALLET_ADDRESS>
          Address of Station's built-in wallet (required) [env: WALLET_ADDRESS=]
  -r, --root-dir <ROOT_DIR>
          Directory where to keep state files (optional). Defaults to a platform-specific location, e.g. $XDG_STATE_HOME/zinniad on Linux [env: ROOT_DIR=] [default: "/Users/bajtos/Library/Application Support/app.filstation.zinniad"]
  -h, --help
          Print help
  -V, --version
          Print version

In Action

Screenshot 2023-03-27 at 17 47 46

Raw stdout (ND-JSON):

❯ cargo run -p zinniad -- -w f1asd ping-probe.js 2>/dev/null
{"type":"activity:info","module":null,"message":"Module Runtime started."}
{"type":"jobs-completed","total":1,"modules":{"ping-probe":1}}
{"type":"jobs-completed","total":2,"modules":{"ping-probe":2}}

Raw stderr - notice that Console logs are printed via Rust logging API, annotated with module name and timestamp:

❯ NO_COLOR=1 cargo run -p zinniad -- -w f1asd ping-probe.js >/dev/null
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/zinniad -w f1asd ping-probe.js`
[2023-03-27T15:50:18Z INFO  zinniad] Starting zinniad with config CliArgs { wallet_address: "f1asd", root_dir: "/Users/bajtos/Library/Application Support/app.filstation.zinniad", files: ["ping-probe.js"] }
[2023-03-27T15:50:18Z INFO  zinniad] Starting module file:///Users/bajtos/src/zinnia/zinnia/ping-probe.js
[2023-03-27T15:50:18Z INFO  module:ping-probe] Pinging /dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb
[2023-03-27T15:50:19Z INFO  module:ping-probe] RTT: 518ms
[2023-03-27T15:50:19Z INFO  module:ping-probe] Submitted stats to InfluxDB.
[2023-03-27T15:50:20Z INFO  module:ping-probe] Pinging /dns/saturn-link-poc.fly.dev/tcp/3030/p2p/12D3KooWRH71QRJe5vrMp6zZXoH4K7z5MDSWwTXXPriG9dK8HQXk
[2023-03-27T15:50:20Z INFO  module:ping-probe] RTT: 538ms
[2023-03-27T15:50:21Z INFO  module:ping-probe] Submitted stats to InfluxDB.

Implement a new binary `zinniad` that can run multiple modules
at the same time and acts as another Filecoin Station Module.

Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
@bajtos bajtos requested a review from juliangruber March 27, 2023 13:22
@bajtos bajtos mentioned this pull request Mar 27, 2023
11 tasks
bajtos added 5 commits March 27, 2023 16:38
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
@juliangruber juliangruber marked this pull request as ready for review March 27, 2023 15:58
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
Comment on lines +113 to +115
self.tracker
.borrow_mut()
.job_completed(|n| self.print_jobs_completed(n));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.tracker
.borrow_mut()
.job_completed(|n| self.print_jobs_completed(n));
self.print_jobs_completed(self.tracker
.borrow_mut()
.job_completed());

API question: Is a closure the way to go, or could we simply return the value?

Copy link
Member Author

Choose a reason for hiding this comment

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

So I want to log the message only if it's at least 500ms since we printed the message for the last time.

I suppose I could change job_completed() and flush() function to return a tuple (job_count: u64, should_log: bool) and let the caller handle should_log.

let (job_count, should_log) = self.tracker.borrow_mut().job_completed();
if should_log { self.print_jobs_completed(job_count); }

Do you find this version easier to understand and work with?

Copy link
Member Author

Choose a reason for hiding this comment

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

So I want to log the message only if it's at least 500ms since we printed the message for the last time.

Meaning that if we call reporter.job_completed twice within 500ms, the first call will trigger calling the printer closure but the second call will not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, returning (job_count, should_log) would not work well. The tracker will not know whether it should reset the timer or not. It can reset the timer every time job_completed returns should_log = true, but that relies on the caller logging the message when told so. I find that brittle.

Copy link
Member

Choose a reason for hiding this comment

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

Ah gotcha, I didn't know the closure was being called optionally. That works 👍

@bajtos bajtos merged commit 3aec19a into main Mar 28, 2023
@bajtos bajtos deleted the feat-zinniad branch March 28, 2023 12:26
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