-
Notifications
You must be signed in to change notification settings - Fork 35
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 cancel/kill all invocations to a service or service instance #1529
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH. | ||
// All rights reserved. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the LICENSE file. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0. | ||
|
||
use crate::cli_env::CliEnv; | ||
use crate::clients::datafusion_helpers::find_active_invocations_simple; | ||
use crate::clients::{self, MetaClientInterface}; | ||
use crate::ui::console::{confirm_or_exit, Styled}; | ||
use crate::ui::invocations::render_simple_invocation_list; | ||
use crate::ui::stylesheet::Style; | ||
use crate::{c_println, c_success}; | ||
|
||
use anyhow::{bail, Result}; | ||
use cling::prelude::*; | ||
|
||
#[derive(Run, Parser, Collect, Clone)] | ||
#[cling(run = "run_cancel")] | ||
#[clap(visible_alias = "rm")] | ||
pub struct Cancel { | ||
/// A target string exact match or prefix, e.g.: | ||
/// * `serviceName` | ||
/// * `serviceName/handler` | ||
/// * `virtualObjectName` | ||
/// * `virtualObjectName/key` | ||
/// * `virtualObjectName/key/handler` | ||
/// * `workflowName` | ||
/// * `workflowName/key` | ||
/// * `workflowName/key/handler` | ||
query: String, | ||
/// Ungracefully kill the invocation and its children | ||
#[clap(long)] | ||
kill: bool, | ||
} | ||
|
||
pub async fn run_cancel(State(env): State<CliEnv>, opts: &Cancel) -> Result<()> { | ||
let client = crate::clients::MetasClient::new(&env)?; | ||
let sql_client = clients::DataFusionHttpClient::new(&env)?; | ||
|
||
let q = opts.query.trim(); | ||
let filter =match q.find('/').unwrap_or_default() { | ||
0 => format!("target LIKE '{}/%'", q), | ||
// If there's one slash, let's add the wildcard depending on the service type, | ||
// so we discriminate correctly with serviceName/handlerName with workflowName/workflowKey | ||
1 => format!("(target = '{}' AND target_service_ty = 'service') OR (target LIKE '{}/%' AND target_service_ty != 'service'))", q, q), | ||
// Can only be exact match here | ||
_ => format!("target LIKE '{}'", q), | ||
}; | ||
|
||
let invocations = find_active_invocations_simple(&sql_client, &filter).await?; | ||
if invocations.is_empty() { | ||
bail!("No invocations found for query {}!", opts.query); | ||
}; | ||
|
||
render_simple_invocation_list(&env, &invocations); | ||
|
||
// Get the invocation and confirm | ||
let prompt = format!( | ||
"Are you sure you want to {} these invocations?", | ||
if opts.kill { | ||
Styled(Style::Danger, "kill") | ||
} else { | ||
Styled(Style::Warn, "cancel") | ||
}, | ||
); | ||
confirm_or_exit(&env, &prompt)?; | ||
|
||
for inv in invocations { | ||
let result = client.cancel_invocation(&inv.id, opts.kill).await?; | ||
let _ = result.success_or_error()?; | ||
} | ||
|
||
c_println!(); | ||
c_success!("Request was sent successfully"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A) Should we put an upper bound on how many we display on the screen? (maybe a few examples and a message that says how many more?)
B) Do you think it'd cause problems to have this be an unbounded loop of cancellations (in situations with potentially large number of invocations)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could introduce an upper bound, but then this means either that we don't show all the invocations we kill, or we need to shave off some invocations, meaning that during dev the user might have to run many times the kill command to kill all the invocations...
Only way to find out is testing it 😄 In principle here we just append commands to the log, so many commands probably will slow down the system a bit while all of those are processed.