Allow log path transformation in fluentd glue
authorLars Kellogg-Stedman <lars@redhat.com>
Mon, 11 Sep 2017 16:00:18 +0000 (10:00 -0600)
committerMartin Mágr <mmagr@redhat.com>
Tue, 26 Sep 2017 11:37:13 +0000 (13:37 +0200)
Logs in a containerized deployment are not in the same location as on
a baremetal deployment. This commit adds the $fluentd_path_transform
paramter to the fluentd glue module. This is a regular expression that
is used to transform log paths.  To use this feature, include in your
hiera configuration something like:

    tripleo::profile::base::logging::fluentd::fluentd_path_transform:
      - /var/log/
      - /var/log/containers/

Change-Id: I585b6877074353b5de62e5efaabfbe62432c473d
Partial-bug: #1716427
(cherry picked from commit 1ff0903a3950bc4adbc8c84b5153df6ca0fb6a3d)

manifests/profile/base/logging/fluentd.pp

index b23610a..2e41942 100644 (file)
 # [*fluentd_syslog_port*]
 #   (Optional, default 42185) Port on which fluentd should listen if
 #   $fluentd_listen_syslog is true.
+#
+# [*fluentd_path_transform*]
+#   (Optional) List. Specifies [find, replace] arguments that will be
+#   used to transform the 'path' value for logging sources using puppet's
+#   regsubst function.
 class tripleo::profile::base::logging::fluentd (
   $step = Integer(hiera('step')),
   $fluentd_sources = undef,
@@ -69,7 +74,8 @@ class tripleo::profile::base::logging::fluentd (
   $fluentd_ssl_certificate = undef,
   $fluentd_shared_key = undef,
   $fluentd_listen_syslog = true,
-  $fluentd_syslog_port = 42185
+  $fluentd_syslog_port = 42185,
+  $fluentd_path_transform = undef
 ) {
 
   if $step >= 4 {
@@ -98,9 +104,28 @@ class tripleo::profile::base::logging::fluentd (
     }
 
     if $fluentd_sources {
+
+      if $fluentd_path_transform {
+        $_fluentd_sources = map($fluentd_sources) |$source| {
+          if $source['path'] {
+            $newpath = {
+              'path' => regsubst($source['path'],
+                        $fluentd_path_transform[0],
+                        $fluentd_path_transform[1])
+            }
+
+            $source + $newpath
+          } else {
+            $source
+          }
+        }
+      } else {
+        $_fluentd_sources = $fluentd_sources
+      }
+
       ::fluentd::config { '100-openstack-sources.conf':
         config => {
-          'source' => $fluentd_sources,
+          'source' => $_fluentd_sources,
         }
       }
     }