-
Notifications
You must be signed in to change notification settings - Fork 376
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 tell/ear interface for CLI access to vmod objects #3729
base: master
Are you sure you want to change the base?
Conversation
bc454ea
to
9734f89
Compare
force push: moved from VRT to VPI |
I have implemented the TODOs and force pushed.
RST generation in vmodtool is still todo once we have agreement on the current PR. |
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.
I like this iteration much better already, and I have a few comments.
if (objname) { | ||
n = strndup(av[2], objname - av[2]); | ||
objname++; |
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.
AN(n);
if (s->n > 0 && ! strcmp(s->p[0], "fail")) { | ||
VSB_cat(ctx->msg, "You asked me to fail"); | ||
return (300); | ||
} | ||
VSB_cat(ctx->msg, o->vcl_name); | ||
VSB_putc(ctx->msg, ':'); | ||
|
||
for (i = 0; i < s->n; i++) { | ||
VSB_putc(ctx->msg, ' '); | ||
VSB_cat(ctx->msg, s->p[i]); | ||
} | ||
|
||
return (200); |
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.
Should we expose (or even restrict to) a subset of the VCLI status constants to VMODs?
if self.cli is not None: | ||
self.cli.json(ll) | ||
|
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.
Maybe make $CLI
unconditional like $INIT
and $FINI
to simplify the libvcc side.
/*-------------------------------------------------------------------- | ||
* tell interface. | ||
* | ||
* we all agree it does not quite fit the purpose of VPI, but it fits here | ||
* better than anywhere else | ||
* | ||
* XXX: Replace instance info with a tree indexed by name | ||
*/ |
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.
It probably belongs to cache_vcl.c
, just like sending events happens from there, alongside vcl_cli_tell()
.
I think this is fundamentally a good idea. I think this PR is a competent prototype that shows it is possible. I am also pretty certain this is not how the final solution will look. For one thing, object instances are not the only things we want to tell things:
People have also been wanting to frob probes and backends without reloading VCL's from day one. So I suggest the next step is to write the proposed user documentation for this feature, including examples, because that is a great way to find weaknesses in the design. |
The existing documentation is here and in the commit message. I did not write documentation for vmod authors yet because the interface should be settled first. My understanding from pow wow is that we should have proposed documentation for how this feature would look like when it has evolved further. My suggestion to that effect would be this (reflecting the change of the command to
|
The more I think about this, the more I feel tempted to extend the vcli all the way out there. For instance, what about That needs to do more than just say "Say something to something"
|
I've looked at vcli today, with an eye to the "help" question, and I think we can swing that by allowing help functions to emit their own help (marking these with a flag letter). |
614239e
to
4752409
Compare
1891940
to
79a661c
Compare
de0ac6d
to
a502f6d
Compare
01d9add
to
d3c526d
Compare
Should we put this on hold until the security model question from #3906 is resolved? This ticket should definitely serve as input, I will mention it there as well. Since you touch on flags and the help command, we have a downstream change that cleans certain things up and streamlines others in this area that we should be able to submit soon-ish. |
0f13712
to
aab9d34
Compare
dbbb7c3
to
af79676
Compare
91de6ca
to
88b5843
Compare
14b6669
to
00e4210
Compare
Runtime modification of vmod object properties has been a long standing item on our wishlist. For example, varnishcache#3652 is about a use case to change a custom director property, which is not covered by the director health state. Another simple example is to instruct a vmod object to emit log messages for tracing only when needed. This commit implements a basic interface for CLI access to vmod objects: VMOD objects now can have a single $Cli method, and the CLI gets a command to tell messages by invoking that method. vmod $Cli method ---------------- VMOD object classes gain a special method type $Cli, which is almost identical to $Method, except that only one method is supported per class, and only the specific signature $Cli INT cli_method(STRANDS) is supported. The cli method receives input via the single STRANDS arguments. It is expected to write output to ctx->msg and return the CLI status. cli tell command ---------------- The tell command takes an optional vcl name, object name and message to send. Individual message arguments are passed as constituents of the STRANDS argument to the object's cli method. demo ---- A new test case demos the functionality: The debug.obj class has gained a cli method which just returns the instance name followed by the original message: varnish> help tell 200 tell [<vcl>.]<object> <msg> ... Tell <msg> to <object> from the given <vcl> or the active vcl varnish> tell obj0 is there anybody out there? 200 obj0: is there anybody out there? varnish> tell whoisit hello? 300 No object named whoisit found varnish> tell obj0 fail 300 You asked me to fail
Runtime modification of vmod object properties has been a long standing item on our wishlist. For example, #3652 is about a use case to change a custom director property, which is not covered by the director health state. Another simple example is to instruct a vmod object to emit log messages for tracing only when needed.
This commit implements a basic interface for CLI access to vmod objects:
VMOD objects now can have ears, and the CLI gets a command to tell messages to ears.
vmod ears
VMOD object classes gain a special method type
$Ear
, which is almost identical to$Method
, except that only one ear is supported per class, and only the specific signatureis supported.
The ear receives input via the single
STRANDS
argument and can either returnNULL
for error, or a response as aSTRANDS
.For the error case, the ear can write details to
ctx->msg
.cli tell command
The tell command takes an optional vcl name, object name and message to send. Individual message arguments are passed as constituents of the
STRANDS
argument to the ear.demo
A new test case demos the functionality: The
debug.obj
class has gained an ear which just returns the instance name followed by the original message: