Upgrading to Varnish 6.0·续2

Another big difference between Red Hat and Debian derivatives was the way we handled VCL reloads via the service manager. We introduced a new varnishreload script that operates on top of varnishadm to perform hot reloads of one VCL configuration or label at a time. All you need is enough privileges to contact varnishd’s command line interface, which should not be a problem for package managers.

Once the varnish package is installed, you can learn more:

varnishreload -h

Again, many thanks to downstream maintainers and some early adopters for their help in testing the new script.

To stay on the topic of the command line interface, packages no longer create a secret file for the CLI, and services omit -S and -T options on the varnishd command. This means that out of the box, you can only connect to the CLI locally with enough privileges to read a secret generated randomly. This means less noise in our packages, and you need to change the service configuration to enable remote access to the CLI. With previous packages, you also needed to change your configuration because the CLI would only listen to the loopback interface anyway.

To change how varnishd is started, please refer to the systemd documentation.

Virtual provides#

Last but not least in the packaging space, we took a first step towards improving dependency management between official varnish packages and VMODs built on top of them. RPMs and Deb packages now provide the strict and VRT ABIs from varnishd and the goal is to ultimately prevent a package installation or upgrade that would prevent a VMOD from being loaded.

For Deb packages:

Provides:
 varnishd-abi-SHA1,
 varnishd-vrt (= x.y)

And for RPMs:

Provides: varnishd(abi)(x86-64) = SHA1
Provides: varnishd(vrt)(x86-64) = x.y

For VMOD authors or downstream distributors, this means that depending on the $ABI stanza in the VMOD descriptor, they can either tie their backend manually to the git hash Varnish was built from or to the VRT version used at the time.

For example, a VMOD RPM built against Varnish 6.0.0 could have:

Requires: varnishd(vrt)%{?_isa} >= 7.0
Requires: varnishd(vrt)%{?_isa} < 8

Future plans include the ability to automate this for out-of-tree VMODs and remove manual steps. To learn more about the history behind this change, it was formalized via the Varnish Improvement Process:

<https://github.com/varnishcache/varnish-cache/wiki/VIP20%3A-Varnish-ABI-and-packaging>

Another thing available only to RPM packages as of 6.0.0 is virtual provides for VMODs.

Instead of showing shared objects that aren’t even in the dynamic linker’s default path:

Provides: libvmod_std.so(64bit)
Provides: libvmod_directors.so(64bit)
[...]

You get virtual VMOD provides with a version:

Provides: vmod(std)(x86-64) = 6.0.0-1
Provides: vmod(directors)(x86-64) = 6.0.0-1
[...]

With the same mechanism it becomes possible to require a VMOD directly and let it bring along its dependencies, like varnish. As this is currently not automated for out-of-tree VMODs, consider this a preview of what you will be able to do once VIP 20 is completed.

Other changes#

  • varnishd(1):
    • The umem storage allocator, which was removed as of Varnish 5.1, has been restored and is now the default on a system where libumem is available (SunOS and descendants).
  • varnishlog(1):

    • Added a third field to the ReqStart log record that contains the name of the listener address over which the request was received, see VSL.
  • 0.0.0.0 and port 0 appear in the logs where an IP and port otherwise appear, when the connection in question was addressed as a Unix domain socket. This affects ReqStart, SessOpen, BackendStart and BackendOpen.

If you have more than one UDS listener, they can be distinguished with the “listener name” field – the third field for both ReqStart and SessOpen.

If you have more than one UDS backend, they can be distinguished with the backend name field – the second field in BackendOpen.

  • The byte counters logged with ReqAcct now report the numbers returned from the operating system telling us how many bytes were actually sent in a request and response, rather than what Varnish thought it was going to send. This gives a more accurate account when there are errors, for example when a client hung up early without receiving the entire response. The figures also include any overhead in a request or response body, for example due to chunked encoding.

  • Debugging logs for the PROXY protocol are turned off by default. They can be turned on with the protocol flag of the varnishd debug parameter (-p debug=+protocol).

  • varnishstat(1)

    • Added the counter cache_hit_grace – how often objects in the cache were hit when their TTL had expired, but they were still in grace.
  • varnishncsa(1)

    • The %h formatter (remote host) gets its value from ReqStart for client requests and BackendStart for backend requests. The value will be 0.0.0.0 for client requests when the listener is UDS, and for backend requests when the backend is UDS.
  • The %r formatter (first line of the request) is reconstructed in part from the Host request header. For UDS backends, Host may be 0.0.0.0 for the reasons explained above (no client Host header and no .host_header setting for the backend), so that may appear in the output for %r. You can avoid that with the measures discussed above.

  • If you have more than one UDS listener and/or more than one UDS backend, and you want to tell them apart in the varnishncsa output (rather than just see 0.0.0.0), use the %{VSL}x formatter to capture the listener name and the backend name.

For the listener name, use %{VSL:ReqStart[3]}x for client logs (the third field of ReqStart logs).

For the backend name, use %{VSL:BackendOpen[2]}x for backend logs.

  • varnishncsa does not accept output format strings (from the -F command-line argument or a configuration file) if they specify tags for log entries whose payloads may contain control or binary characters.

  • varnishtest(1) and vtc(7):

    • The client -connect and server -listen commands in vtc scripts now allow Unix domain sockets as addresses, recognized when the argument begins with a /.

A client attempts the connection immediately, so the socket file must exist at the given path when the client is started, and the client must be able to access it.

The server -listen command must be able to create the socket file when it executes bind(2). To make it easier for other processes to connect to the socket, the server’s umask is temporarily set to 0 before the listen is attempted, to minimize issues with permissions. No further attempt is made to set the socket’s permissions.

To test a Varnish instance listening at a UDS, just use the varnish -arg command with the appropriate settings for the -a command line argument, see varnishd.

The varnish -vcl+backend command now works to include backend definitions for server objects that are listening at UDS. Backend declarations are implicitly included for such servers with the appropriate .path setting.

A convenient location for socket files to be used in a test is the temporary directory created by varnishtest for each test, whose path is held in the macro ${tmpdir}. So this is a common idiom for tests that involve UDSen:

      server s1 -listen "${tmpdir}/s1.sock" { ... } -start

      varnish v1 -arg "-a ${tmpdir}/v1.sock" -vcl+backend { ... } -start

      client c1 -connect "${tmpdir}/v1.sock" { ... } -run

When a Varnish instance in a vtc test is listening at a UDS, then its vN_* macros are set like this:

  • v1_addr: /path/to/socket
    • v1_port: - (hyphen)
    • v1_sock: /path/to/socket -

When a server s1 is listening at a UDS:

  • s1_addr: 0.0.0.0
    • s1_port: 0
    • s1_sock: /path/to/socket

The vtc variables remote.ip and remote.port, which can be used in expect expressions for both server and client scripts, are set to 0.0.0.0 and 0, respectively, when the peer address is a UDS.

We have added the variable remote.path as a counterpart to the other two. Its value is the path when the peer address is a UDS, and NULL otherwise (matching <undef> in the latter case).

  • Changes for developers:

    • The VRT API version has been bumped to 7.0, and comprises a variety of new additions and changes. See vrt.h and the change log for details.
  • There are new rules about including API headers – some may only be included once, others must included in a specific order. Only cache.h or vrt.h may be included (cache.h includes vrt.h). See the #error directives in the headers.

  • VMOD authors can use the VRT_VSC_*() series of functions and the new vsctool to create statistics for a VMOD that will be displayed by varnishstat. Varnish uses the same technique to create its counters, so you can look to the core code to see how it’s done.

  • The VCL_INT and VCL_BYTES types are now defined to be strictly 64 bit (rather than leave it to whatever your platform defines as long). But you may not get that full precision, for reasons discussed in the change log.

  • As part of VRT version 7.0, the path field has been added to to struct vrt_backend, which a VMOD can use with VRT_new_backend() to create a dynamic backend with a UDS address (see vrt.h).

If path is non-NULL, then both of the IPv4 and IPv6 addresses must be NULL. If path is NULL, then (as before) one or both of the IP addresses must be non-NULL. The dyn_uds object in VMOD debug (available in the source tree) illustrates how this can be done.

  • VMOD vcc sources may now include a directive $Prefix, whose value is the string prepended to the names of C objects and functions in the generated C interface (in vcc_if.h). So you may choose another prefix besides vmod_, if so desired.

  • vcc sources may also include a directive $Synopsis whose value may be auto or manual, default auto.

When $Synopsis is auto, the vmodtool generates a more comprehensive SYNOPSIS section in the documentation than in previous versions – an overview of the objects, methods and functions in your VMOD, with their type signatures.

When $Synopsis is manual, the SYNOPSIS is left out of the generated docs altogether; so you can write the SYNOPSIS section yourself, if you prefer.

  • Support for a new declaration of optional arguments in vcc files has been added: [ argname ] can be used to mark argname as optional.

If this declaration is used for any argument, all user arguments and PRIV_* pointers (no object pointers) to the respective function/method will be passed in a struct funcname_arg specific to this function which contains the arguments by their name (or the name arg n for unnamed arguments, n being the argument position starting with 1) plus valid_argname members for optional arguments which are being set to non-zero iff the respective argname was provided.

Argument presence is determined at VCC time, so it is not possible to pass an unset argument from another function call.

eof