Skip to content

Commit

Permalink
add fluentd logging driver config check
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Jun 26, 2017
1 parent 0b0e0d1 commit 5b998dd
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions roles/openshift_health_checker/openshift_checks/logging/fluentd.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,72 @@ def run(self, tmp, task_vars):
"{}".format(check_error))
return {"failed": True, "changed": False, "msg": msg}

config_error = self.check_logging_config(fluentd_pods, task_vars)
if config_error:
msg = ("The following Fluentd logging configuration issue was found:"
"\n-------\n"
"{}".format(config_error))
return {"failed": True, "changed": False, "msg": msg}

# TODO(lmeyer): run it all again for the ops cluster
return {"failed": False, "changed": False, "msg": 'No problems found with Fluentd deployment.'}

def check_logging_config(self, fluentd_pods, task_vars):
"""Ensure that the configured Docker logging driver matches fluentd settings.
This means that, at least for now, if the following condition is met:
openshift_logging_fluentd_use_journal == True
then the value of the configured Docker logging driver should be "journald".
Otherwise, the value of the Docker logging driver should be "json-file".
Returns an error string if the above condition is not met, or None otherwise."""

pod_name = fluentd_pods[0]["metadata"]["name"]
use_journald = self._exec_oc("exec {} /bin/printenv USE_JOURNAL".format(pod_name), [], task_vars)

docker_info = self.execute_module("docker_info", {}, task_vars)
if not docker_info.get("info", False):
return "No information was returned by the Docker client. Unable to verify the logging driver in use."

if not docker_info["info"].get("LoggingDriver", False):
return "No logging driver information was returned by the Docker client."

logging_driver = docker_info["info"]["LoggingDriver"]
recommended_logging_driver = "journald"
error = None

# If fluentd is set to use journald but Docker is not, recommend setting the `--log-driver`
# option as an inventory file variable, or adding the log driver value as part of the
# Docker configuration in /etc/docker/daemon.json. There is no global --log-driver flag that
# can be passed to the Docker binary; the only other recommendation that can be made, would be
# to pass the `--log-driver` flag to the "run" sub-command of the `docker` binary when running
# individual containers.
if use_journald and logging_driver != "journald":
error = ('Your Fluentd configuration is set to aggregate Docker container logs from "journald".\n'
'This differs from your Docker configuration, which has been set to use "{driver}" '
'as the default method of storing logs.\n'
'This discrepancy in configuration will prevent Fluentd from receiving any logs'
'from your Docker containers.\n').format(driver=logging_driver)
elif not use_journald and logging_driver != "json-file":
recommended_logging_driver = "json-file"
error = ('Your Fluentd configuration is set to aggregate Docker container logs from '
'individual json log files per container.\n '
'This differs from your Docker configuration, which has been set to use '
'"{driver}" as the default method of storing logs.\n'
'This discrepancy in configuration will prevent Fluentd from receiving any logs'
'from your Docker containers.\n').format(driver=logging_driver)

if error:
error += ('To resolve this issue, add the following variable to your Ansible inventory file:\n\n'
' openshift_docker_options="--log-driver={driver}"\n\n'
'Alternatively, you can add the following option to your Docker configuration, located in'
'"/etc/docker/daemon.json":\n\n'
'{{ "log-driver": "{driver}" }}\n\n'
'See https://docs.docker.com/engine/admin/logging/json-file '
'for more information.').format(driver=recommended_logging_driver)

return error

@staticmethod
def _filter_fluentd_labeled_nodes(nodes_by_name, node_selector):
"""Filter to all nodes with fluentd label. Returns dict(name: node), error string"""
Expand Down

0 comments on commit 5b998dd

Please sign in to comment.