Puppet Class: mcrouter

Defined in:
modules/mcrouter/manifests/init.pp

Overview

SPDX-License-Identifier: Apache-2.0

Class: mcrouter

mcrouter is a fast routing proxy for memcached. It can reduce the connection count on the backend caching servers and also supports layered pools, replication, and key/operation based routing to pools.

Parameters

pools

A hash defining a mcrouter server pool. See <github.com/facebook/mcrouter/wiki/Config-Files>.

routes

A list of hashes that define route handles. See <github.com/facebook/mcrouter/wiki/List-of-Route-Handles>.

region

Datacenter name for the one in this geographical region

cluster

Memcached cluster name

cross_region_timeout_ms

Timeout, in milliseconds, when performing cross-region memcached operations

cross_cluster_timeout_ms

Timeout, in milliseconds, when performing cross-cluster memcached operations

ssl_options

If not undef, this is a hash indicating the port to listen to for ssl and the public cert, private key, and CA cert paths on the filesystem.

num_proxies

Maximum number of connections to each backend. Defaults to 1.

probe_delay_initial_ms

TKO probe retry initial timeout in ms. When a memcached server is marked as TKO (by default after 3 timeouts registered), mcrouter waits this amount of time before sending the first health checks probes (meant to verify the status of memcached before sending traffic again). Defaults to 3000.

timeouts_until_tko

Number of timeouts to happen before marking a memcached server as TKO. Default: undef

Examples

class { '::mcrouter':
  region                   => $::site,
  cluster                  => 'clustername',
  cross_region_timeout_ms  => 250,
  cross_cluster_timeout_ms => 1000,
  pools                    => {
    'clustername-main' => {
      servers => [ '10.68.23.25:11211', '10.68.23.49:11211' ]

# ^ note that these must be IPs, not fqdns

    }
  },
  routes                   => [ {
    aliases => [ "/${::site}/clustername" ],
    route   => {
      type => 'OperationSelectorRoute',
      default_policy => 'PoolRoute|clustername-main',
      operation_policies => {
        set => 'AllFastestRoute|Pool|clustername-main',
        delete => 'AllFastestRoute|Pool|clustername-main'
      }
    }
  } ]
}

Parameters:

  • pools (Hash)
  • routes (Array)
  • region (String)
  • cluster (String)
  • ensure (Wmflib::Ensure) (defaults to: present)
  • port (Stdlib::Port) (defaults to: 11213)
  • cross_region_timeout_ms (Integer) (defaults to: 250)
  • cross_cluster_timeout_ms (Integer) (defaults to: 1000)
  • ssl_options (Mcrouter::Ssl) (defaults to: undef)
  • num_proxies (Integer) (defaults to: 1)
  • probe_delay_initial_ms (Integer) (defaults to: 3000)
  • timeouts_until_tko (Optional[Integer]) (defaults to: undef)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'modules/mcrouter/manifests/init.pp', line 75

class mcrouter(
    Hash              $pools,
    Array             $routes,
    String            $region,
    String            $cluster,
    Wmflib::Ensure    $ensure                   = present,
    Stdlib::Port      $port                     = 11213,
    Integer           $cross_region_timeout_ms  = 250,
    Integer           $cross_cluster_timeout_ms = 1000,
    Mcrouter::Ssl     $ssl_options              = undef,
    Integer           $num_proxies              = 1,
    Integer           $probe_delay_initial_ms   = 3000,
    Optional[Integer] $timeouts_until_tko       = undef,
) {
    ensure_packages('mcrouter')

    $config = { 'pools' => $pools, 'routes' => $routes }

    file { '/etc/mcrouter/config.json':
        ensure       => $ensure,
        content      => to_json_pretty($config),
        owner        => 'root',
        group        => 'root',
        mode         => '0444',
        require      => Package['mcrouter'],
        validate_cmd => "/usr/bin/mcrouter --validate-config --port ${port} --route-prefix ${region}/${cluster} --config file:%",
    }

    file { '/etc/default/mcrouter':
        ensure  => $ensure,
        content => template('mcrouter/default.erb'),
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
    }

    systemd::service { 'mcrouter':
        ensure   => $ensure,
        content  => "[Service]\nLimitNOFILE=64000\nUser=mcrouter\nNice=-19\n",
        override => true,
        restart  => false,
    }

    # Logging management
    logrotate::rule { 'mcrouter':
        ensure       => present,
        file_glob    => '/var/log/mcrouter.log',
        frequency    => 'daily',
        compress     => true,
        missing_ok   => true,
        not_if_empty => true,
        rotate       => 7,
        post_rotate  => ['service rsyslog rotate >/dev/null 2>&1 || true']
    }
    rsyslog::conf { 'mcrouter':
        source   => 'puppet:///modules/mcrouter/mcrouter.rsyslog.conf',
        priority => 20,
        require  => File['/etc/logrotate.d/mcrouter'],
        before   => Service['mcrouter'],
    }
}