-
Notifications
You must be signed in to change notification settings - Fork 119
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
Expose in ops a jhack-eval-like entrypoint #1449
Comments
I would have thought that |
@dimaqq No, it looks like the
|
This is an interesting idea, though I wonder about the UI. On the one hand, it's nice that
would work out of the box. But that command is also non-obvious (documentation could solve that) and awkward (why the environment variable? what is What if it was a two-step thing, where you
Alternatively, what if charmcraft included an
The other question I had is whether it's What expressions/commands do you (or others) typically evaluate/run with |
The whole point of this exercise is to allow people to 'eval' without needing jhack since the environment could be locked down. As to including it in the packed charms by default, that's not a bad idea but also it's not ideal that it wouldn't work with existing deployments. Common workflows:
|
But isn't that true of any update to ops? Any changes to ops will require a newly-packed charm, right? Thanks for the list of common workflows. |
jhack eval
is a command that allows you to evaluate python expressions in the context of a charm, without having to wait for the charm to receive an event.jhack eval traefik/0 "self.unit.name"
will print to stdouttraefik/0
.This has proved to be extremely useful in debugging and troubleshooting.
It is implemented by scp'ing a file into the unit and then juju-exec'ing it. The file contains much of the machinery in ops.main.main, but never calls the
_emit_charm_event
function; instead, it eval's the user-provided expression while binding the following globals:self
: the charm instanceops
: the ops module, to let the user evaluate expressions such assetattr(self.unit.status, ops.ActiveStatus())
json
: the json module, to let the user output json instead of plain str/repr.In certain environments where jhack is not available, it would be handy to have a way to ask the user to evaluate an expression for debugging purposes, to inspect the charm's current state outside of what the logging output shows.
It would be fantastic if we could offer a way for the user to achieve the same functionality without much hackery.
My proposal is to add to ops.main logic to skip event emission if the charm is being executed with a special envvar set.
The user would need to run:
juju exec --unit traefik/0 OPS_EVAL_EXPR="self.unit.name" ./dispatch
(or something like that).
When called with that envvar set, ops.main will not emit an event on the charm, but instead will evaluate the provided exception while binding the same globals that jhack exposes.
see #1450 for a proof of concept implementation
The text was updated successfully, but these errors were encountered: