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

Add cloud CLI tunnel command #1552

Merged
merged 14 commits into from
Jun 5, 2024
Merged

Conversation

jackkleeman
Copy link
Contributor

@jackkleeman jackkleeman commented May 26, 2024

Adds a command that can expose a local port to restate cloud

BInary size impact; 475kB

@jackkleeman jackkleeman force-pushed the cloud-cli-expose branch 8 times, most recently from ea9c548 to d8c9ab2 Compare June 1, 2024 10:37
Copy link
Contributor

@igalshilman igalshilman left a comment

Choose a reason for hiding this comment

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

I've tried this out locally,
was able to:

  • login
  • successfully create a tunnel
  • register a service
  • invoke it.
  • re attach to a previously created tunnel
  • use non standard local network configuration

So functionality wise looks really good to me.

@pcholakov
Copy link
Contributor

Running tunnel without any parameters works fine, but when I start it with any remote-port arguments and NO local-port argument, the CLI crashes:

❯ RUST_BACKTRACE=full cargo run --bin restate -- cloud env tunnel -r 8080

restate cloud environment tunnel - Press Ctrl-C to exit

     →↓→↓
    →↓→↓→↓→→→               →→→→
    ↓→↓→↓→↓↓→↓→→           →↓↓→↓→↓→
    →↓→↓→↓→↓→↓↓→↓→↓       →↓→↓→↓→↓→↓→
    →↓→↓→↓→↓→↓→↓→↓→↓→→      →↓→↓→↓→↓→↓→→
    →↓→↓→↓→ →↓→↓→↓→↓→↓→↓→      →↓→↓→↓→↓↓→↓→↗
    →↓→↓→↓→    →↓→↓→↓→↓→↓→↓→     →→↓→↓→↓→↓↓→↓→
    →↓→↓→↓→       →↓→↓→↓→↓→↓→↓→     →→↓→↓→↓→↓→↓→→
    →↓→↓→↓→          →↓→↓→↓→↓→↓→↓→     →→↓→↓→↓→↓↓→↓→
    →↓→↓→↓→             →↓→↓→↓→↓→↓→       →→↓→↓→↓→↓→↓
    →↓→↓→↓→             →↓→↓→↓→↓→↓→      →→↓→↓→↓→↓→↓→
    →↓→↓→↓→          →↓→↓→↓→↓→↓→↓      →↓→↓→↓→↓→↓→→
    →↓→↓→↓→       →→↓→↓→↓→↓→↓→→     →↓→↓→↓→↓→↓→→
    →↓→↓→↓→      →↓→↓→↓→↓→↓→     →↓→↓→↓→↓→↓→↓
    →↓→↓→↓→     →↓→↓→↓→↓→     →↓→↓→↓→↓→↓→↓→
    →↓→↓→↓→      ↓→↓→→      →↓→↓→↓→↓→↓→→
    →↓→↓→↓→               →↓→↓→↓→↓→↓→
    →↓→↓→↓→                →↓→↓→↓→
    ↓→↓→↓→↓
     →↓→→

  💡   Source                  →    💡   Destination
  🏠   http://localhost:8080   →    🌎   public ingress

thread 'main' panicked at cli/src/commands/cloud/environments/tunnel/local.rs:44:29:
`async fn` resumed after completion
stack backtrace:
   0:        0x10413c254 - std::backtrace_rs::backtrace::libunwind::trace::h2966c6fbfac9d426
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:        0x10413c254 - std::backtrace_rs::backtrace::trace_unsynchronized::h8a5f4aefe890b7c5
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x10413c254 - std::sys_common::backtrace::_print_fmt::h7574dd98fd39c257
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:67:5
   3:        0x10413c254 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h298c9ab285ff3934
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x10415e92c - core::fmt::rt::Argument::fmt::hf9661447f7b99899
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/fmt/rt.rs:142:9
   5:        0x10415e92c - core::fmt::write::h4e276abdb6d0c2a1
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/fmt/mod.rs:1120:17
   6:        0x104138b1c - std::io::Write::write_fmt::hd421848f5f0bf9d0
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/io/mod.rs:1762:15
   7:        0x10413c090 - std::sys_common::backtrace::_print::h09e653c6686dbd70
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:47:5
   8:        0x10413c090 - std::sys_common::backtrace::print::hd8bd9ecab1f94b94
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:34:9
   9:        0x10413d4e0 - std::panicking::default_hook::{{closure}}::h520eeb743fc98fb4
  10:        0x10413d228 - std::panicking::default_hook::ha6550ffe49b63df1
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:292:9
  11:        0x10413d908 - std::panicking::rust_panic_with_hook::hddb0e884a202de7c
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:779:13
  12:        0x10413d7e4 - std::panicking::begin_panic_handler::{{closure}}::hd2798398a2fd9077
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:649:13
  13:        0x10413c6bc - std::sys_common::backtrace::__rust_end_short_backtrace::h9201cc364dbb8a23
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:170:18
  14:        0x10413d5a4 - rust_begin_unwind
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
  15:        0x1041920c8 - core::panicking::panic_fmt::h4d5168028d4c43c7
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
  16:        0x10419213c - core::panicking::panic::h40561ff494e2b577
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:127:5
  17:        0x102f2d3fc - restate_cli::commands::cloud::environments::tunnel::local::run_local::{{closure}}::h949a0ce1bbcd317f
                               at /Users/pavel/restate/restate/cli/src/commands/cloud/environments/tunnel/local.rs:44:29
  18:        0x102dd42c8 - <core::pin::Pin<P> as core::future::future::Future>::poll::he621bbe829a83fd7
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/future/future.rs:125:9
  19:        0x102dd3078 - <&mut F as core::future::future::Future>::poll::hcd12bbf48fe4c6a6
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/future/future.rs:113:9
  20:        0x102f7f448 - restate_cli::commands::cloud::environments::tunnel::run_tunnel::{{closure}}::{{closure}}::hcf821b050da5e31a
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/macros/select.rs:524:49
  21:        0x102c2dc90 - <tokio::future::poll_fn::PollFn<F> as core::future::future::Future>::poll::hed085773a165cdf2
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/future/poll_fn.rs:58:9
  22:        0x102f7dcb4 - restate_cli::commands::cloud::environments::tunnel::run_tunnel::{{closure}}::hb3c4001c3f340089
                               at /Users/pavel/restate/restate/cli/src/commands/cloud/environments/tunnel/mod.rs:151:13
  23:        0x102eb98b8 - <T as cling::effects::IntoEffect<cling::effects::_Async>>::into_effect::{{closure}}::h7d0942aef787394d
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cling-0.1.2/src/effects.rs:101:14
  24:        0x102dd3f8c - <core::pin::Pin<P> as core::future::future::Future>::poll::h57126802a3811201
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/future/future.rs:125:9
  25:        0x102f7f054 - <restate_cli::commands::cloud::environments::tunnel::Tunnel as cling::app::Run>::call::{{closure}}::he26b6d3ca1ba5e60
                               at /Users/pavel/restate/restate/cli/src/commands/cloud/environments/tunnel/mod.rs:31:15
  26:        0x102dd3f8c - <core::pin::Pin<P> as core::future::future::Future>::poll::h57126802a3811201
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/future/future.rs:125:9
  27:        0x102d97268 - <restate_cli::commands::cloud::environments::Environments as cling::app::Run>::call::{{closure}}::h363a2a3308487376
                               at /Users/pavel/restate/restate/cli/src/commands/cloud/environments/mod.rs:26:5
  28:        0x102dd3f8c - <core::pin::Pin<P> as core::future::future::Future>::poll::h57126802a3811201
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/future/future.rs:125:9
  29:        0x102d7dfd8 - <restate_cli::commands::cloud::Cloud as cling::app::Run>::call::{{closure}}::h0b2ac02b2b50324a
                               at /Users/pavel/restate/restate/cli/src/commands/cloud/mod.rs:106:5
  30:        0x102dd3f8c - <core::pin::Pin<P> as core::future::future::Future>::poll::h57126802a3811201
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/future/future.rs:125:9
  31:        0x102f8b998 - <restate_cli::app::Command as cling::app::Run>::call::{{closure}}::h331bbccf4910a479
                               at /Users/pavel/restate/restate/cli/src/app.rs:111:5
  32:        0x102dd3f8c - <core::pin::Pin<P> as core::future::future::Future>::poll::h57126802a3811201
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/future/future.rs:125:9
  33:        0x102f8b14c - <restate_cli::app::CliApp as cling::app::Run>::call::{{closure}}::h871324533b555b3d
                               at /Users/pavel/restate/restate/cli/src/app.rs:31:14
  34:        0x102dd3f8c - <core::pin::Pin<P> as core::future::future::Future>::poll::h57126802a3811201
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/future/future.rs:125:9
  35:        0x102b8b654 - cling::app::Cling<T,cling::app::_private::Ready>::run::{{closure}}::h73f89d6c92f30abe
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cling-0.1.2/src/app.rs:307:71
  36:        0x102b8b358 - cling::app::Cling<T>::parse_and_run::{{closure}}::h977eaecb61caf4e9
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cling-0.1.2/src/app.rs:169:54
  37:        0x102b8e03c - restate::main::{{closure}}::hde9b1b76d5ed0fc4
                               at /Users/pavel/restate/restate/cli/src/main.rs:40:28
  38:        0x102b8cbc4 - <tracing::instrument::Instrumented<T> as core::future::future::Future>::poll::h08506faf33245042
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-0.1.40/src/instrument.rs:321:9
  39:        0x102b8de98 - tokio::runtime::park::CachedParkThread::block_on::{{closure}}::h3504e71dc1751610
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/park.rs:281:63
  40:        0x102b8dda4 - tokio::runtime::coop::with_budget::haa421d6f543a71bd
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:107:5
  41:        0x102b8dda4 - tokio::runtime::coop::budget::h8df19335fcdf4ab8
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:73:5
  42:        0x102b8dda4 - tokio::runtime::park::CachedParkThread::block_on::hdcaa3f31b064e74e
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/park.rs:281:31
  43:        0x102b8fc38 - tokio::runtime::context::blocking::BlockingRegionGuard::block_on::h4867e16eaa18a13e
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/context/blocking.rs:66:9
  44:        0x102b92bc0 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}::h6f154bfa4a61323b
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/scheduler/multi_thread/mod.rs:873
  45:        0x102b92ff8 - tokio::runtime::context::runtime::enter_runtime::h34d62f1fadbc19d9
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/context/runtime.rs:65:16
  46:        0x102b92b60 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h6997021f65bff9ab
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/scheduler/multi_thread/mod.rs:869
  47:        0x102b92e2c - tokio::runtime::runtime::Runtime::block_on::ha5cdc3b9e160613d
                               at /Users/pavel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/runtime.rs:350:45
  48:        0x102b8aeb0 - restate::main::h68ad2bda31788648
                               at /Users/pavel/restate/restate/cli/src/main.rs:40:5
  49:        0x102b8f268 - core::ops::function::FnOnce::call_once::h6d4d122ac567411e
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
  50:        0x102b8edd8 - std::sys_common::backtrace::__rust_begin_short_backtrace::h1d9f4ec48f2c69e0
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:154:18
  51:        0x102b8ff20 - std::rt::lang_start::{{closure}}::h15f16465af4d3566
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs:167:18
  52:        0x104130f78 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h1a7c0e059d971da5
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:284:13
  53:        0x104130f78 - std::panicking::try::do_call::h07a34a23e615022b
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
  54:        0x104130f78 - std::panicking::try::h1111644420b4cc09
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
  55:        0x104130f78 - std::panic::catch_unwind::h31a3b9d6e2ef9973
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
  56:        0x104130f78 - std::rt::lang_start_internal::{{closure}}::h63c3452500a36531
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs:148:48
  57:        0x104130f78 - std::panicking::try::do_call::h9c5c8a2a0a297bb7
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
  58:        0x104130f78 - std::panicking::try::h424cfcafca1bde97
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
  59:        0x104130f78 - std::panic::catch_unwind::h345d3d448041017f
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
  60:        0x104130f78 - std::rt::lang_start_internal::h5b246d44f1526226
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs:148:20
  61:        0x102b8fed8 - std::rt::lang_start::hc7a36c6b00e71e54
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs:166:17
  62:        0x102b8aef4 - _main
zsh: abort      RUST_BACKTRACE=full cargo run --bin restate -- cloud env tunnel -r 8080

But for example these all work just fine:

cargo run --bin restate -- cloud env tunnel --remote-port 8080 --remote-port 9070 --local-port 9080
cargo run --bin restate -- cloud env tunnel --remote-port 8080 --local-port 9080
cargo run --bin restate -- cloud env tunnel --local-port 9080
cargo run --bin restate -- cloud env tunnel


loop {
tokio::select! {
Err(local_err) = &mut local_fut => break Err(Error::Local(local_err)),
Copy link
Contributor

Choose a reason for hiding this comment

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

The panic on setting a remote-port but no local-port goes away if I change this line to:

Suggested change
Err(local_err) = &mut local_fut => break Err(Error::Local(local_err)),
Err(local_err) = &mut local_fut, if opts.local_port.is_some() => break Err(Error::Local(local_err)),

Though I'm not sure why it works that way, since local_fut should evaluate to Ok(()) when local port is unset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. I suspect I'm using select subtly wrong. Will take a look and report back

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to fuse the future otherwise it will panic when polled again after already returning Poll::Ready(Ok(())). Bit of a footgun with tokio::select!.
https://users.rust-lang.org/t/why-doesnt-tokio-select-require-fusedfuture/46975/13

@jackkleeman jackkleeman merged commit 3804e88 into restatedev:main Jun 5, 2024
5 checks passed
@jackkleeman jackkleeman deleted the cloud-cli-expose branch June 5, 2024 07:24
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