Puppet Class: arclamp

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

Overview

SPDX-License-Identifier: Apache-2.0

Class: arclamp

Aggregate captured stack traces from MediaWiki application servers, write them to disk, and generate SVG flame graphs.

The aggregator reads captured traces from a Redis instance using pub/sub.

MediaWiki servers capture these traces from PHP.

For PHP 7 we use Excimer: <www.mediawiki.org/wiki/Excimer>

Parameters

ensure

Description

redis_host

Address of Redis server that is publishing stack traces. Default: '127.0.0.1'.

redis_port

Port of Redis server that is publishing stack traces. Default: 6379.

compress_logs_days

How many days to wait before compressing logs. Default: 3

Examples

class { 'arclamp':
    ensure     => present,
    redis_host => 'mwlog.example.net',
    redis_port => 6379,
}

Parameters:

  • ensure (Wmflib::Ensure) (defaults to: 'present')
  • redis_host (Stdlib::Host) (defaults to: '127.0.0.1')
  • redis_port (Stdlib::Port) (defaults to: 6379)
  • errors_mailto (String) (defaults to: 'performance-team-alert@wikimedia.org')
  • compress_logs_days (Integer) (defaults to: 3)
  • retain_hourly_logs_hours (Integer) (defaults to: 336)
  • retain_daily_logs_days (Integer) (defaults to: 90)
  • swift_account_name (Optional[String]) (defaults to: undef)
  • swift_auth_url (Optional[String]) (defaults to: undef)
  • swift_user (Optional[String]) (defaults to: undef)
  • swift_key (Optional[String]) (defaults to: undef)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'modules/arclamp/manifests/init.pp', line 38

class arclamp(
    Wmflib::Ensure $ensure               = 'present',
    Stdlib::Host $redis_host             = '127.0.0.1',
    Stdlib::Port $redis_port             = 6379,
    String $errors_mailto                = 'performance-team-alert@wikimedia.org',
    Integer $compress_logs_days          = 3,
    Integer $retain_hourly_logs_hours    = 336, # 14 days
    Integer $retain_daily_logs_days      = 90,
    Optional[String] $swift_account_name = undef,
    Optional[String] $swift_auth_url     = undef,
    Optional[String] $swift_user         = undef,
    Optional[String] $swift_key          = undef,
){

    ensure_packages(['python3-redis', 'python3-yaml', 'python3-swiftclient'])

    systemd::sysuser { 'xenon':
        ensure      => $ensure,
        description => 'Arc Lamp user',
    }

    file { '/srv/xenon':
        ensure => stdlib::ensure($ensure, 'directory'),
        links  => 'follow',
        owner  => 'xenon',
        group  => 'xenon',
        mode   => '0755',
    }

    file { '/srv/arclamp':
        ensure => stdlib::ensure($ensure, 'link'),
        target => '/srv/xenon',
    }

    scap::target { 'performance/arc-lamp':
        service_name => 'arclamp',
        deploy_user  => 'deploy-service',
    }

    file { '/usr/local/bin/arclamp-grep':
        ensure => stdlib::ensure($ensure, 'link'),
        target => '/srv/deployment/performance/arc-lamp/arclamp-grep.py',
    }

    $timer_environment_file = '/etc/arclamp-timer.env'
    $timer_environment = { 'MAILTO' => $errors_mailto }

    if $swift_account_name == undef {
        $swift_timer_environment = {}
    } else {
        $swift_timer_environment = {
            'ST_AUTH' => "${swift_auth_url}/auth/v1.0",
            'ST_USER' => $swift_user,
            'ST_KEY'  => $swift_key,
        }

        # Also write credentials where they can be sourced by root
        # users who need to manually run the swift CLI tool for setup
        # or debugging:
        $account_file = "/etc/swift/account_${swift_account_name}.env"
        file { '/etc/swift':
            ensure => stdlib::ensure($ensure, 'directory'),
            owner  => 'root',
            group  => 'root',
            mode   => '0750',
        }
        file { $account_file:
            ensure    => $ensure,
            owner     => 'root',
            group     => 'root',
            mode      => '0440',
            content   => "export ST_AUTH=${swift_auth_url}/auth/v1.0\nexport ST_USER=${swift_user}\nexport ST_KEY=${swift_key}\n",
            show_diff => false,
        }
    }

    # Use an 'EnvironmentFile=' directive for sensitive content.
    # 'Environment=' settings in unit files are world-readable via 'systemctl show'
    file { $timer_environment_file:
        ensure    => $ensure,
        owner     => 'xenon',
        group     => 'xenon',
        mode      => '0440',
        show_diff => false,
        content   => (($timer_environment + $swift_timer_environment).map |$k, $v| { "${k}=${v}" } + ['']).join("\n"),
    }

    # Generate flamegraphs from raw log data:
    systemd::timer::job { 'arclamp_generate_svgs':
        ensure             => $ensure,
        description        => 'Regular jobs to generate svg files',
        user               => 'xenon',
        monitoring_enabled => false,
        logging_enabled    => false,
        send_mail          => true,
        environment_file   => $timer_environment_file,
        command            => '/srv/deployment/performance/arc-lamp/arclamp-generate-svgs',
        interval           => {'start' => 'OnCalendar', 'interval' => '*-*-* *:0/15:0'},
        require            => Package['performance/arc-lamp']
    }

    # Compress logs older than X days:
    systemd::timer::job { 'arclamp_compress_logs':
        ensure             => $ensure,
        description        => 'Regular jobs to compress arclamp logs',
        user               => 'xenon',
        monitoring_enabled => false,
        logging_enabled    => false,
        send_mail          => true,
        environment_file   => $timer_environment_file,
        command            => "/srv/deployment/performance/arc-lamp/arclamp-compress-logs ${compress_logs_days}",
        interval           => {'start' => 'OnCalendar', 'interval' => '*-*-* *:17:0'},
        require            => Package['performance/arc-lamp']
    }

    # Write Prometheus metrics to file under HTTP document root:
    systemd::timer::job { 'arclamp_generate_metrics':
        ensure             => $ensure,
        description        => 'Regular jobs to generate arclamp metrics',
        user               => 'xenon',
        monitoring_enabled => false,
        logging_enabled    => false,
        send_mail          => true,
        environment        => $timer_environment,
        command            => '/srv/deployment/performance/arc-lamp/arclamp-generate-metrics',
        interval           => {'start' => 'OnCalendar', 'interval' => '*-*-* *:0/2:0'},
        require            => Package['performance/arc-lamp']
    }

    # This supports running multiple pipelines; we profile CPU and
    # wall clock time separately.
    arclamp::profiler {
        default:
            ensure                   => present,
            redis_host               => $redis_host,
            redis_port               => $redis_port,
            retain_hourly_logs_hours => $retain_hourly_logs_hours,
            retain_daily_logs_days   => $retain_daily_logs_days;
        'excimer':
            description => 'PHP Excimer (CPU)';
        'excimer-wall':
            description => 'PHP Excimer (wall clock)';
        'excimer-k8s': # T288165
            description => 'PHP Excimer (k8s CPU)';
        'excimer-k8s-wall': # T288165
            description => 'PHP Excimer (k8s wall clock)';
    }
}