Skip to content

Commit

Permalink
[ROVER-301] Fixes => rover dev prematurely outputs that the supergr…
Browse files Browse the repository at this point in the history
…aph is running.
  • Loading branch information
monkpow committed Jan 31, 2025
1 parent c0517c5 commit 0c86eb1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/command/dev/do_dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ impl Dev {
override_install_path: Option<Utf8PathBuf>,
client_config: StudioClientConfig,
) -> RoverResult<RoverOutput> {
warnln!(
"Do not run this command in production! It is intended for local development only.\n"
);

let elv2_license_accepter = self.opts.plugin_opts.elv2_license_accepter;
let skip_update = self.opts.plugin_opts.skip_update;
let read_file_impl = FsReadFile::default();
Expand Down Expand Up @@ -240,6 +244,11 @@ impl Dev {
.address(router_address)
.build();

infoln!(
"Attempting to start router at {}.",
router_address.pretty_string()
);

let mut run_router = run_router
.run(
FsWriteFile::default(),
Expand All @@ -253,13 +262,6 @@ impl Dev {
.watch_for_changes(write_file_impl, composition_messages, hot_reload_overrides)
.await;

warnln!(
"Do not run this command in production! It is intended for local development only."
);

let pretty_router_addr_string = router_address.pretty_string();
infoln!("Your supergraph is running! head to {pretty_router_addr_string} to query your supergraph");

loop {
tokio::select! {
_ = tokio::signal::ctrl_c() => {
Expand All @@ -271,8 +273,8 @@ impl Dev {
match router_log {
Ok(router_log) => {
if !router_log.to_string().is_empty() {
eprintln!("{}", router_log);
}
eprintln!("{}", router_log);
}
}
Err(err) => {
tracing::error!("{:?}", err);
Expand Down
18 changes: 17 additions & 1 deletion src/command/dev/router/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,21 @@ pub enum RouterLog {
Stderr(String),
}

fn should_select_log_message(log_message: &str) -> bool {
// For most info-level messages, we want to pipe them to tracing only.
// However, a few info-level messages (e.g. for confirming that the router started up)
// we want to let them fall through to (usually) stderr.
!log_message
.matches("exposed at http")
.collect::<Vec<&str>>()
.is_empty()
}

impl fmt::Display for RouterLog {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let warn_prefix = Style::WarningPrefix.paint("WARN:");
let error_prefix = Style::ErrorPrefix.paint("ERROR:");
let info_prefix = Style::InfoPrefix.paint("INFO:");
let unknown_prefix = Style::ErrorPrefix.paint("UNKNOWN:");
match self {
Self::Stdout(stdout) => {
Expand All @@ -45,7 +56,12 @@ impl fmt::Display for RouterLog {
.unwrap_or(stdout);

match level {
"INFO" => tracing::info!(%message),
"INFO" => {
if should_select_log_message(message) {
write!(f, "{} {}", info_prefix, &message)?
}
tracing::info!(%message)
}
"DEBUG" => tracing::debug!(%message),
"TRACE" => tracing::trace!(%message),
"WARN" => write!(f, "{} {}", warn_prefix, &message)?,
Expand Down

0 comments on commit 0c86eb1

Please sign in to comment.