Page MenuHomePhabricator

Sort out analytics service dependency issues for cp* cache hosts
Closed, DeclinedPublic

Description

There are a number of analytics services which run on the cache hosts, e.g. multiple instantiations of varnishkafka, varnish varnishprocessor daemons like varnishrls, etc...

Right now, the only runtime service dependencies (as in, configured metadata for systemd) is that they all depend on varnish services. That is, they all have lines like
After=varnish-frontend.service (and also sometimes BindsTo=varnish-frontend.service) in their systemd unit files. This makes sense from a certain perspective: they probably require the varnish instance they pull logs from to already be running, and perhaps they could crash or error if varnish is stopped before them as well.

However, I'm not entirely sure they each require the varnish service they're reading shm logs from to actually be started first, or that they'd error out badly if varnish stopped first. It may be the case that they're capable of starting and stopping asynchronously from the related varnish instance. It would be a nice property to have, and if they don't already have that property, it may be worth investing in some code updates for it.

Because systemd has ultimate control over the parallelism and execution order of all start/stop on boot/shutdown, there's no guarantee that varnish and the analytics daemons' start/stop actions execute in a tight batch in wallclock terms. Therefore with the current dependency scheme, for example, varnishkafka might start several minutes after varnish-frontend does, and varnishkafka might be stopped several minutes before varnish-frontend does as well. This leaves racy timing gaps where legitimate traffic may flow unlogged by these analytics services. In most cases, especially in the past, this is a trivial time offset on a rare event (reboot), so it's not generally a critical issue, but things are changing...

These days we're looking at auto-(de|re)pool scripts hooked into the init system, which pool or depool services in confd and may wait (for now, via over-long sleeps) to ensure those pooling changes take effect before allowing the main varnish (or nginx) service to stop or start. The net result in practice has been a sequence on shutdown like: "stop varnishkafka; depool self from confd; sleep 45 seconds; stop varnish-frontend". This is a legal interpretation of current dependencies, and leaves a more-significant window of unlogged traffic. A further related complication is that we have the same issue with confd dependencies itself, where confd may already be stopped before the depool action, and thus the node doesn't depool itself from inter-service dependecies during the window of depool time....

TL;DR - find out if various analytics daemons are capable of being asynch (in service dep terms) from varnish itself. If they are, or once they are, we need to flip the systemd dependencies around to avoid unlogged traffic windows: e.g. varnish should depend on varnishkafka, so that the logging is always running if the daemon is running.

Event Timeline

Milimetric triaged this task as Medium priority.Feb 29 2016, 5:12 PM
Milimetric moved this task from Incoming to Radar on the Analytics board.
Milimetric moved this task from Radar to Event Platform on the Analytics board.

T138747 upgraded Varnishkafka to a new version able to start at any time and poll periodically the Varnish shm logs to see if they are open or not. This should allow us to start Varnishkafka before Varnish without any issue.

Question for the Traffic team: is this task still valid after T138747 or shall we call it done?

I think there's still some work here to do, if nothing else to audit the situation as it stands. There's basically two things to sort out for all of the varnish-logging bits and pieces:

  1. Have we killed the hard dependency on Varnish being online? (Can we start the logger first and have it connect/reconnect as Varnish goes up and down?)
  2. Have we re-ordered the systemd level dependencies to ensure we're not losing log events? (Can we make Varnish services dependent on the loggers being ready to receive events?)

Number 1 was done in T138747, but I was a bit reluctant to create any dependency between Varnish and Varnishkafka that could for some reason risk to end up in a situation like "Varnishkafka is not available then Varnish stays down".

The only use case that I have in mind where we could risk to loose events is after boot, when Varnish might start serving traffic while varnishkafka is still waiting to start (if possible). Any other ones?

Will investigate the possible solutions offered by systemd and report back :)

Milimetric raised the priority of this task from Medium to Needs Triage.Apr 2 2018, 3:50 PM
Milimetric triaged this task as Low priority.
Milimetric moved this task from Wikistats to Operational Excellence on the Analytics board.
Milimetric subscribed.

The fix for this would be high risk and low gain. So keeping around to just have context in case the problem does manifest.

This is too-stale now and a lot of these bits have been replaced over time and are known to have their deps correct.