Skip to content

CLI - cancel execution upon signal reception#367

Merged
mum4k merged 21 commits intoenvoyproxy:masterfrom
oschaaf:execution-cancellation
Jun 24, 2020
Merged

CLI - cancel execution upon signal reception#367
mum4k merged 21 commits intoenvoyproxy:masterfrom
oschaaf:execution-cancellation

Conversation

@oschaaf
Copy link
Copy Markdown
Member

@oschaaf oschaaf commented Jun 17, 2020

Teach the CLI to handle SIGTERM/SIGINT, and handle those as a request to
gracefully cancel execution.

Partially resolves #280


In preparation of sharing functionality for signal handling,
extract what we have right now into SignalHandler.

Status: draft

For fixing envoyproxy#280

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
…ndler

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
…ndler

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf marked this pull request as ready for review June 17, 2020 14:32
oschaaf added 4 commits June 19, 2020 00:33
…ation

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf added P1 waiting-for-review A PR waiting for a review. labels Jun 18, 2020
…ation

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@mum4k mum4k requested a review from eric846 June 19, 2020 19:02
@mum4k mum4k self-assigned this Jun 19, 2020
@mum4k
Copy link
Copy Markdown
Collaborator

mum4k commented Jun 19, 2020

@eric846 please review and assign to me once ready.

…ation

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
cluster_manager_ = cluster_manager_factory_->clusterManagerFromProto(bootstrap);
maybeCreateTracingDriver(bootstrap.tracing());
cluster_manager_->setInitializedCb([this]() -> void { init_manager_.initialize(init_watcher_); });
{
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note to reviewers: The "hide whitespace" toggle in Github makes this a lot more fun to review.
(The scope introduced for the lock guard introduces a lot of whitespace noise).

@eric846 eric846 added waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. and removed waiting-for-review A PR waiting for a review. labels Jun 22, 2020
oschaaf added 2 commits June 22, 2020 20:47
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf added waiting-for-review A PR waiting for a review. and removed waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. labels Jun 22, 2020
@oschaaf
Copy link
Copy Markdown
Member Author

oschaaf commented Jun 22, 2020

Thanks @eric846 for the review. Just marked this as ready for another pass

OutputFormatterFactoryImpl output_formatter_factory;
OutputCollectorImpl output_collector(time_system, *options_);
const bool res = process->run(output_collector);
bool res;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(nit) If we can, we should try to avoid abbreviations in variable names (res).


bool RemoteProcessImpl::requestExecutionCancellation() {
ENVOY_LOG(error, "Remote process cancellation not supported yet");
// TODO(XXX): Send a cancel request to the gRPC service.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did we want to replace XXX with a value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I filed #380 (and updated XXX to #380) in the changes I'm about to push.


void configureComponentLogLevels(spdlog::level::level_enum level);
const std::vector<ClientWorkerPtr>& createWorkers(const uint32_t concurrency);
void createWorkers(const uint32_t concurrency);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(optional) Is this a good time to document the method?



def send_sigterm(p):
# Sleep for a while, under tsan the client needs a lot of time
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we add a Python style docstring, since the function is public.

assertCounterEqual(counters, "benchmark.http_2xx", (total_requests))


def send_sigterm(p):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we choose a more readable name than "p".

stdout, stderr = client_process.communicate()
client_process.wait()
output = stdout.decode('utf-8')
assert (client_process.returncode == 0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we add a custom error message giving some context?

Or should this be a regular test assertion like below?

if (do_cancel) {
cancel_thread = std::thread([&process, terminate_right_away] {
if (!terminate_right_away) {
sleep(5);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we add a comment explaining the sleep and the choice of 5?

@mum4k mum4k added waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. and removed waiting-for-review A PR waiting for a review. labels Jun 22, 2020
This was referenced Jun 22, 2020
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf added waiting-for-review A PR waiting for a review. and removed waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. labels Jun 22, 2020
@oschaaf
Copy link
Copy Markdown
Member Author

oschaaf commented Jun 22, 2020

@mum4k thanks for the review. I pushed 3198623 to address your feedback.

@mum4k mum4k merged commit 3fe461c into envoyproxy:master Jun 24, 2020
wjuan-AFK pushed a commit to wjuan-AFK/nighthawk that referenced this pull request Jul 14, 2020
Teach the CLI to handle SIGTERM/SIGINT, and handle those as a request to
gracefully cancel execution.

Partially resolves envoyproxy#280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 waiting-for-review A PR waiting for a review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nighthawk_client: handle termination signal

3 participants