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

(TK-487) Allow friendly init/start fail fast via ::exit throw #289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rbrw
Copy link
Contributor

@rbrw rbrw commented Jul 24, 2020

Allow init and start methods to throw a request-shutdown style ex-info
map to short circuit the startup process and exit with a specified
message and status, rather than a backtrace.

This just provides a short circuiting (immediate) counterpart to the
existing, deferred shutdown requests provided by request-shutdown.

@rbrw rbrw added the work in progress (...and please don't merge) label Jul 24, 2020
@rbrw rbrw requested a review from a team July 24, 2020 16:44
@rbrw
Copy link
Contributor Author

rbrw commented Jul 24, 2020

This isn't quite ready (e.g. at least needs tests), but I wanted to see if it seemed plausible before proceeding further. The current motivation is wanting to be able to shut down in a friendly way when a service detects a problem with the configuration it retrieves via (get-config), without having to carefully coordinate with all other services in order to safely rely on a deferred request-shtudown.

@puppetcla
Copy link

CLA signed by all contributors.

Base automatically changed from master to main January 26, 2021 21:12
@CLAassistant
Copy link

CLAassistant commented Sep 1, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@rbrw rbrw force-pushed the tk-487-friendly-startup-short-circuits branch from c450c97 to 3ae4471 Compare December 14, 2021 17:37
@rbrw rbrw force-pushed the tk-487-friendly-startup-short-circuits branch from 3ae4471 to 1a7f88e Compare August 29, 2022 21:51
@rbrw rbrw requested a review from a team as a code owner August 29, 2022 21:51

(defn exit-exception? [ex]
(and (instance? ExceptionInfo ex)
(not (schema/check {(schema/optional-key :puppetlabs.trapperkeeper.core/exit)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a confused why there is a not here..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, right, because I believe check returns nil if it matches, info about the mismatch, otherwise.

[exception]
(if (exit-exception? exception)
(merge {:cause :requested}
(select-keys (ex-data exception) [:puppetlabs.trapperkeeper.core/exit]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why select-keys instead of including all the exception data?
Also, based on your documentation, it looks like :puppetlabs.trapperkeeper.core/exit is not a top-level key, it's the value for the :kind key. so not sure what the intention was here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I recall correctly, it's just to be sure that the exception only contributes the key that it's supposed to, e.g. can't clobber other top-level keys, etc.

And I think the idea is that :kind is a non-namespaced key that tells you what type of ex-data map you have. Everything else in the map can be type-specific. The ':kind` value is namespaced to avoid collisions across namespaces and even across different projects.

We could namespace :kind, as say :puppetlabs/kind, but I believe there's some precedence at puppet (and I vaguely recall maybe elsewhere) to use :kind globally. TK itself is already using :kind for some exit-related code.

@rbrw rbrw force-pushed the tk-487-friendly-startup-short-circuits branch from 1a7f88e to 715d414 Compare May 10, 2023 19:23
Allow init and start methods to throw a request-shutdown style ex-info
map to short circuit the startup process and exit with a specified
message and status, rather than a backtrace.

This just provides a short circuiting (immediate) counterpart to the
existing, deferred shutdown requests provided by request-shutdown.
@rbrw rbrw force-pushed the tk-487-friendly-startup-short-circuits branch from 715d414 to 8d56968 Compare May 10, 2023 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work in progress (...and please don't merge)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants