Glance client does not correctly forward global request IDs

Bug #1886650 reported by Markus Hentsch on 2020-07-07
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance Client
Status tracked in Victoria
Train
Medium
Erno Kuvaja
Ussuri
Medium
Erno Kuvaja
Victoria
Medium
Erno Kuvaja

Bug Description

This is about the Global Request ID functionality of OpenStack [1].

When the Glance client is used to instantiate a client object for
accessing the Glance API, a global_request_id parameter may be
passed to it. However, due to a coding error in the SessionClient
class, the parameter never reaches the Glance API in form of the
"X-Openstack-Request-Id" header and is instead lost.

# How to reproduce

This can be reproduced simply by creating a server in Nova from an
image in Glance, which will attempt to create the Glance client
instance using the global_request_id [5]. Passing the
"X-Openstack-Request-Id" header during the initial API call for the
server creation, makes it visible in Nova (using a suitable
"logging_context_format_string" setting) but it's not visible in
Glance. Using a Python debugger shows Glance generating a new local ID
instead.

Example for a "logging_context_format_string" showing both IDs:

logging_context_format_string = %(levelname)s %(name)s [%(request_id)s | %(global_request_id)s %(user_identity)s] %(instance)s%(message)s

Note: due to another bug in Glance API, currently the global request
id will never actually show up as %(global_request_id)s in Glance API
but will instead be shown as the %(request_id)s if available, i.e. when
this client bug gets fixed, a global id will show up in the logs as if
it was a local one until the API bug is fixed too. So expect different
behavior when applying this logging setting to both Nova and Glance!

# Technical details

When the SessionClient class is used, the global_request_id is removed
from kwargs in the constructor using pop() [2]. Directly after this,
the parent constructor is called using super(), which in this case is
Adapter from the keystoneauth1 library. Therein the global_request_id
is set again [3] but since it has been removed from the kwargs, it
defaults to None as specified in the Adapter's __init__() header. Thus,
the global_request_id passed to the SessionClient constructor never
actually makes it to the Glance API. This is in contrast to the
HTTPClient class, where get() is used instead of pop() [4].

# Proposed solution

Replace pop() by get() in the code of SessionClient referenced above.

# Link references

[1] https://specs.openstack.org/openstack/oslo-specs/specs/pike/global-req-id.html
[2] https://github.com/openstack/python-glanceclient/blob/de178ac4382716cc93022be06b93697936e816fc/glanceclient/common/http.py#L355
[3] https://github.com/openstack/keystoneauth/blob/dab8e1057ae8bb9a0e778fb8d3141ad4fb36a339/keystoneauth1/adapter.py#L166
[4] https://github.com/openstack/python-glanceclient/blob/de178ac4382716cc93022be06b93697936e816fc/glanceclient/common/http.py#L162
[5] https://github.com/openstack/nova/blob/1cae0cd7229207478b70275509aecd778ca69225/nova/image/glance.py#L78

Erno Kuvaja (jokke) on 2020-07-13
Changed in python-glanceclient:
status: New → Triaged
importance: Undecided → Medium
assignee: nobody → Erno Kuvaja (jokke)

Fix proposed to branch: master
Review: https://review.opendev.org/740821

Changed in python-glanceclient:
status: Triaged → In Progress
Erno Kuvaja (jokke) wrote :

Markus,

Thanks for the great bug. I was first thinking of tagging it as low hanging fruit but tbh it was just quicker to propose a fix as all the details were conveniently in the bug. This should be very trivial to get the fix in and backport. Solution proposed.

Reviewed: https://review.opendev.org/740821
Committed: https://git.openstack.org/cgit/openstack/python-glanceclient/commit/?id=bae1d89cc767949fc61cef63dcacec200a2c236a
Submitter: Zuul
Branch: master

commit bae1d89cc767949fc61cef63dcacec200a2c236a
Author: Erno Kuvaja <email address hidden>
Date: Mon Jul 13 22:35:15 2020 +0100

    Pass Global Request ID on with session client

    Closes-bug: #1886650
    Change-Id: I3a08c1beb398ba9f2556b6779c925f679bdc2c49

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

Other bug subscribers