It's not necessary to pass context as kwarg to oslo.log in most cases

Bug #1500896 reported by Matt Riedemann
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Undecided
Bhagyashri Shewale
OpenStack Compute (nova)
Fix Released
Low
Sivasathurappan Radhakrishnan

Bug Description

Nova is using oslo.context's RequestContext which means the context object is in scope when doing logging using oslo.log:

http://docs.openstack.org/developer/oslo.log/usage.html#passing-context

But there are a lot of places in nova where we do something like:

        context = context.elevated()
        LOG.info(_LI("Rebooting instance"), context=context, instance=instance)

This is confusing because it makes you wonder if (1) you should be passing context in logging method and (2) if it's OK to pass the elevated context in this case or if you should be passing the original context.

It turns out that in this case neither is necessary. The elevated context just has the admin flag set, the request / user / project IDs in the context are left unchanged, which is what we want for logging. And the context is already in scope because of:

http://git.openstack.org/cgit/openstack/oslo.context/tree/oslo_context/context.py#n71

So we don't need to pass it as a kwarg.

This bug is meant to scrub through nova and remove any unnecessary passing of the context object to oslo.log methods.

Changed in nova:
assignee: nobody → Rahul U Nair (rahulunair)
Changed in nova:
status: Triaged → In Progress
Revision history for this message
Nikhil P (nikhilgowda3210) wrote :

sir, if u let us we going to continue with this bug...thank you...

Revision history for this message
Rahul U Nair (rahulunair) wrote :

Go ahead Nikhil, I am un assigning my self from the bug. Thank you.

Changed in nova:
assignee: Rahul U Nair (rahulunair) → nobody
Changed in nova:
assignee: nobody → Nikhil P (nikhilgowda3210)
Changed in nova:
status: In Progress → Confirmed
Changed in nova:
status: Confirmed → In Progress
Revision history for this message
Markus Zoeller (markus_z) (mzoeller) wrote :

@Nikhil: Are you still working on this?

Revision history for this message
Markus Zoeller (markus_z) (mzoeller) wrote :

In case someone wants to query the occurrences of the contexts, you can use:

    $ grep -r -B 1 "context=context" --include "*.py" | grep -n LOG

"-B 1" because sometimes loggings are multiline statements. See this for current master: http://paste.openstack.org/show/493920/

Changed in nova:
assignee: Nikhil P (nikhilgowda3210) → Sivasathurappan Radhakrishnan (siva-radhakrishnan)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

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

Changed in cinder:
assignee: nobody → Bhagyashri Shewale (bhagyashri-shewale)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

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

Changed in cinder:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/351495
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=1a495922edf2ac3b18bfddce0b88dc52fec24e43
Submitter: Jenkins
Branch: master

commit 1a495922edf2ac3b18bfddce0b88dc52fec24e43
Author: bhagyashris <email address hidden>
Date: Wed Aug 3 19:41:51 2016 +0530

    Remove context object in oslo.log method

    Removed context object while logging as Cinder uses oslo.context's
    RequestContext which means the context object is in scope when doing
    logging.

    Change-Id: I7cc434ad10967596f8354775399e0c6c92ab5570
    Closes-Bug:#1500896

Changed in cinder:
status: In Progress → Fix Released
Revision history for this message
Thierry Carrez (ttx) wrote : Fix included in openstack/cinder 9.0.0.0b3

This issue was fixed in the openstack/cinder 9.0.0.0b3 development milestone.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/317109
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=b3d58ed718db91015582cf759a7c8af1874ef093
Submitter: Jenkins
Branch: master

commit b3d58ed718db91015582cf759a7c8af1874ef093
Author: Sivasathurappan Radhakrishnan <email address hidden>
Date: Mon May 16 22:09:44 2016 +0000

    Remove context object in oslo.log method

    Removed context object while logging as Nova uses oslo.context's
    RequestContext which means the context object is in scope when doing
    logging. Added hack to notify, in case if someone uses it in logging
    statements in future.

    Change-Id: I5aaa869f2e6155964827e659d18e2bcaad9d866b
    Closes-Bug:#1500896

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 15.0.0.0b1

This issue was fixed in the openstack/nova 15.0.0.0b1 development milestone.

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.