LOG calls use caller-side string formatting

Bug #1659055 reported by Andreas Maier
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
nova-dpm
Fix Released
Low
Juergen Leopold

Bug Description

In most modules of the DPM Nova driver, there are logging calls that format the string on the caller's side, like in this code (link: https://github.com/openstack/nova-dpm/blob/886fa3ae007589de2d41d7b345ae105cdc72c6bb/nova_dpm/virt/dpm/driver.py#L62):

    LOG.debug("HMC details %(zhmc)s %(userid)s"
              % {'zhmc': zhmc, 'userid': userid})

This happens in:

    nova_dpm/virt/dpm/driver.py
    nova_dpm/virt/dpm/host.py
    nova_dpm/virt/dpm/vm.py

The issue with this is that the formatting takes place in any case, even if logging is not turned on at all. This is not a huge performance impact, but it should be cleaned up at some point.

What should be done instead is to pass the format string (using old-style percent-formatting) and the values as separate arguments. There are two good ways to pass the values:

As positional arguments (if the values are in separate variables):

    LOG.debug("HMC details %s %s", zhmc, userid)

As a dictionary (if the values are in that dictionary already):

    LOG.debug("HMC details %(zhmc)s %(userid)s", mydict)

where in this example the dictionary mydict exists even if that log call would not be made, and has items with keys 'zhmc' and 'userid'.

IMO, it is less desirable (because of complexity) to build up a dictionary just for the purpose of passing it to the logging call, as shown here:

    LOG.debug("HMC details %(zhmc)s %(userid)s",
              {'zhmc': zhmc, 'userid': userid})

Andreas Maier (maiera)
description: updated
Andreas Maier (maiera)
description: updated
Andreas Maier (maiera)
description: updated
Changed in nova-dpm:
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova-dpm (master)

Fix proposed to branch: master
Review: https://review.openstack.org/456179

Changed in nova-dpm:
assignee: nobody → Juergen Leopold (leopoldj)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova-dpm (master)

Reviewed: https://review.openstack.org/456179
Committed: https://git.openstack.org/cgit/openstack/nova-dpm/commit/?id=cb0074b90e432ffcb3c971576cfda65d84d855dc
Submitter: Jenkins
Branch: master

commit cb0074b90e432ffcb3c971576cfda65d84d855dc
Author: Juergen Leopold <email address hidden>
Date: Wed Apr 12 11:33:14 2017 +0000

    Use caller-side string formatting for LOG calls

    Formatting should only take place in case logging
    is turned on. For that, the format string
    and the values should be passed as separate arguments
    to the LOG method.

    Closes-Bug: #1659055

    Change-Id: Ic4f80bbee8ecec5631ac29f83e0163824c660960
    Signed-off-by: Juergen Leopold <email address hidden>

Changed in nova-dpm:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.