logging: support service_config_settings configuration mechanism
This commit implements the necessary support in puppet-tripleo to process fluentd configuration delivered via service_config_settings. Added the fluentd unit test regarding the new configuration: - A file by service - Added the group to the fluentd user Partial-bug: #1715187 Change-Id: I2b057190ec0e4e75ee4ee47ebe0164c2644e5ab7
This commit is contained in:
parent
5f635d6e56
commit
58355c95b7
|
@ -36,9 +36,10 @@
|
|||
# [*fluentd_groups*]
|
||||
# (Optional) List of strings. Add the 'fluentd' user to these groups.
|
||||
#
|
||||
# [*fluentd_pos_file_path*]
|
||||
# (Optional) String. Path to a directory that will be created
|
||||
# if it does not exist and made writable by the fluentd user.
|
||||
# [*fluentd_manage_groups*]
|
||||
# (Optional) Boolean. If true, modify the group membership of the
|
||||
# fluentd_config_user using information provided by fluentd_groups
|
||||
# and the per-service configurations.
|
||||
#
|
||||
# [*fluentd_use_ssl*]
|
||||
# (Optional) Boolean. If true, use the secure_forward plugin.
|
||||
|
@ -63,40 +64,77 @@
|
|||
# (Optional) List. Specifies [find, replace] arguments that will be
|
||||
# used to transform the 'path' value for logging sources using puppet's
|
||||
# regsubst function.
|
||||
#
|
||||
# [*fluentd_pos_file_path*]
|
||||
# (Optional) String. Path to a directory that will be created
|
||||
# if it does not exist and made writable by the fluentd user.
|
||||
#
|
||||
# [*fluentd_default_format*]
|
||||
# (Optional) String. Default log format if not otherwise specified
|
||||
# in a log source definition.
|
||||
#
|
||||
# [*service_names*]
|
||||
# (Optional) List of services enabled on the current role. This is used
|
||||
# to obtain per-service configuration information.
|
||||
class tripleo::profile::base::logging::fluentd (
|
||||
$step = Integer(hiera('step')),
|
||||
$fluentd_sources = undef,
|
||||
$fluentd_filters = undef,
|
||||
$fluentd_servers = undef,
|
||||
$fluentd_groups = undef,
|
||||
$fluentd_pos_file_path = undef,
|
||||
$fluentd_manage_groups = true,
|
||||
$fluentd_use_ssl = undef,
|
||||
$fluentd_ssl_certificate = undef,
|
||||
$fluentd_shared_key = undef,
|
||||
$fluentd_listen_syslog = true,
|
||||
$fluentd_syslog_port = 42185,
|
||||
$fluentd_path_transform = undef
|
||||
$fluentd_path_transform = undef,
|
||||
$fluentd_pos_file_path = undef,
|
||||
$fluentd_default_format = undef,
|
||||
$service_names = hiera('service_names', [])
|
||||
) {
|
||||
|
||||
if $step >= 4 {
|
||||
include ::fluentd
|
||||
|
||||
if $fluentd_groups {
|
||||
Package<| tag == 'openstack' |>
|
||||
-> user { $::fluentd::config_owner:
|
||||
ensure => present,
|
||||
groups => $fluentd_groups,
|
||||
membership => 'minimum',
|
||||
# Load per-service plugin configuration
|
||||
::tripleo::profile::base::logging::fluentd::fluentd_service {
|
||||
$service_names:
|
||||
pos_file_path => $fluentd_pos_file_path,
|
||||
default_format => $fluentd_default_format
|
||||
}
|
||||
|
||||
if $fluentd_manage_groups {
|
||||
# compute a list of all the groups of which the fluentd user
|
||||
# should be a member.
|
||||
$_tmpgroups1 = $service_names.map |$srv| {
|
||||
hiera("tripleo_fluentd_groups_${srv}", undef)
|
||||
}.filter |$new_srv| { ! empty($new_srv) }.flatten()
|
||||
|
||||
$_tmpgroups2 = any2array($fluentd_groups)
|
||||
$groups = concat($_tmpgroups2,
|
||||
$_tmpgroups1)
|
||||
|
||||
if !empty($groups) {
|
||||
Package<| tag == 'openstack' |>
|
||||
-> user { $::fluentd::config_owner:
|
||||
ensure => present,
|
||||
groups => $groups,
|
||||
membership => 'minimum',
|
||||
}
|
||||
~> Service[$::fluentd::service_name]
|
||||
}
|
||||
}
|
||||
|
||||
if $fluentd_pos_file_path {
|
||||
file { $fluentd_pos_file_path:
|
||||
ensure => 'directory',
|
||||
owner => $::fluentd::config_owner,
|
||||
group => $::fluentd::config_group,
|
||||
mode => '0750',
|
||||
ensure => 'directory',
|
||||
owner => $::fluentd::config_owner,
|
||||
group => $::fluentd::config_group,
|
||||
mode => '0750',
|
||||
recurse => true,
|
||||
}
|
||||
~> Service[$::fluentd::service_name]
|
||||
}
|
||||
|
||||
::fluentd::plugin { 'rubygem-fluent-plugin-add':
|
||||
|
@ -149,7 +187,8 @@ class tripleo::profile::base::logging::fluentd (
|
|||
group => 'root',
|
||||
mode => '0644',
|
||||
} ~> exec { 'reload rsyslog':
|
||||
command => '/bin/systemctl restart rsyslog',
|
||||
command => '/bin/systemctl restart rsyslog',
|
||||
refreshonly => true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
# This is used to look up a list of service-specific fluentd configurations
|
||||
# in the hiera data provided by THT.
|
||||
#
|
||||
# [*pos_file_path*]
|
||||
# Default location for fluentd pos files (used to track file
|
||||
# position for the 'tail' input type).
|
||||
#
|
||||
# [*default_format*]
|
||||
# Default regular expression against which to match log messages.
|
||||
define tripleo::profile::base::logging::fluentd::fluentd_service (
|
||||
$pos_file_path = undef,
|
||||
$default_format = undef
|
||||
) {
|
||||
$sources = hiera("tripleo_fluentd_sources_${title}", [])
|
||||
$filters = hiera("tripleo_fluentd_filters_${title}", [])
|
||||
$matches = hiera("tripleo_fluentd_matches_${title}", [])
|
||||
|
||||
$default_source = {
|
||||
format => $default_format,
|
||||
type => 'tail',
|
||||
}
|
||||
|
||||
# Check that we have something to configure to avoid creating
|
||||
# stub config files.
|
||||
if !empty($sources) or !empty($filters) or !empty($matches) {
|
||||
|
||||
# Insert default values into list of sources.
|
||||
$_sources = $sources.map |$src| {
|
||||
$default_source
|
||||
+ {pos_file => "${pos_file_path}/${src['tag']}.pos"}
|
||||
+ $src
|
||||
}
|
||||
|
||||
::fluentd::config { "100-openstack-${title}.conf":
|
||||
config => {
|
||||
'source' => $_sources,
|
||||
'filter' => $filters,
|
||||
'match' => $matches,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,6 +19,10 @@ require 'spec_helper'
|
|||
describe 'tripleo::profile::base::logging::fluentd' do
|
||||
shared_examples_for 'tripleo::profile::base::logging::fluentd' do
|
||||
|
||||
before :each do
|
||||
facts.merge!({ :step => params[:step] })
|
||||
end
|
||||
|
||||
context 'with step less than 4' do
|
||||
let(:params) { { :step => 3 } }
|
||||
|
||||
|
@ -92,6 +96,39 @@ describe 'tripleo::profile::base::logging::fluentd' do
|
|||
}
|
||||
) }
|
||||
end
|
||||
|
||||
context 'Config by service -- ceilometer_agent_central' do
|
||||
let(:params) { {
|
||||
:step => 4,
|
||||
:fluentd_default_format => '/(?<time>\\d{4}-\\d{2}-\\d{2} \\d{2} =>\\d{2}:\\d{2}.\\d+) (?<pid>\\d+) (?<priority>\\S+) (?<message>.*)$/',
|
||||
:fluentd_manage_groups => false,
|
||||
:fluentd_pos_file_path => '/var/cache/fluentd/',
|
||||
:service_names => [ 'ceilometer_agent_central' ]
|
||||
} }
|
||||
it { is_expected.to contain_class('fluentd') }
|
||||
it { is_expected.to contain_file('/var/cache/fluentd/') }
|
||||
it { is_expected.to contain_tripleo__profile__base__logging__fluentd__fluentd_service('ceilometer_agent_central').with(
|
||||
:pos_file_path => '/var/cache/fluentd/',
|
||||
:default_format => '/(?<time>\\d{4}-\\d{2}-\\d{2} \\d{2} =>\\d{2}:\\d{2}.\\d+) (?<pid>\\d+) (?<priority>\\S+) (?<message>.*)$/'
|
||||
) }
|
||||
it { is_expected.to contain_fluentd__config('100-openstack-ceilometer_agent_central.conf') }
|
||||
it { is_expected.to contain_file('/etc/fluentd/config.d/100-openstack-ceilometer_agent_central.conf') }
|
||||
end
|
||||
|
||||
context 'Groups by service -- ceilometer_agent_central added ceilometer' do
|
||||
let(:params) { {
|
||||
:step => 4,
|
||||
:fluentd_manage_groups => true,
|
||||
:fluentd_groups => [ 'fluentd' ]
|
||||
} }
|
||||
it { is_expected.to contain_class('fluentd') }
|
||||
it { is_expected.to contain_user('fluentd').with(
|
||||
:ensure =>'present',
|
||||
:groups => [ 'fluentd', 'ceilometer' ],
|
||||
:membership => 'minimum'
|
||||
) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
on_supported_os.each do |os, facts|
|
||||
|
|
|
@ -8,3 +8,21 @@ tripleo::profile::base::cinder::volume::nfs::cinder_nfs_servers:
|
|||
- '127.0.0.1'
|
||||
cinder::backend::eqlx::eqlx_chap_login: 'user'
|
||||
cinder::backend::eqlx::eqlx_chap_password: 'user'
|
||||
service_names:
|
||||
- 'ceilometer_agent_central'
|
||||
tripleo_fluentd_groups_ceilometer_agent_central:
|
||||
- 'ceilometer'
|
||||
tripleo_fluentd_sources_ceilometer_agent_central:
|
||||
- 'path': '/var/log/ceilometer/central.log'
|
||||
'tag': 'openstack.ceilometer.agent.central'
|
||||
|
||||
fluentd::config_file: "/etc/fluentd/fluent.conf"
|
||||
fluentd::config_group: "fluentd"
|
||||
fluentd::config_owner: "fluentd"
|
||||
fluentd::config_path: "/etc/fluentd/config.d"
|
||||
fluentd::package_name: "fluentd"
|
||||
fluentd::plugin_provider: "yum"
|
||||
fluentd::repo_install: false
|
||||
fluentd::service_name: "fluentd"
|
||||
fluentd::service_provider: "systemd"
|
||||
|
||||
|
|
Loading…
Reference in New Issue