Middleware for swift can not get correct response

Bug #1223259 reported by Che-Wei Hu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ceilometer
Fix Released
Undecided
Mehdi Abaakouk
Grizzly
Fix Released
Medium
Eoghan Glynn

Bug Description

Hi, all:

After adding ceilometer middleware to the swift proxy, I can not get correct response anymore.

For example:
Before adding ceilometer middleware: I can get the correct container list.
After adding ceilometer middleware: I only got empty reply from server.

I am a beginner for studying wsgi and openstack.

Could any one else help to provide suggestions for this issue?

Thanks a lot.

Revision history for this message
Che-Wei Hu (tethu0822) wrote :

Hi, all:

I found that I can get correct response from swift proxy if I do the following modification for ceilometer/objectstore/swift_middleware.py:

class CeilometerMiddleware(object):
    ...
    def __call__(self, env, start_response):
        ...

        def iter_response(iterable):
            if start_response_args[0]:
                start_response(*start_response_args[0])
            """
            bytes_sent = 0
            try:
                for chunk in iterable:
                    if chunk:
                        bytes_sent += len(chunk)
                    yield chunk
            finally:
                self.publish_sample(env,
                                    input_proxy.bytes_received,
                                    bytes_sent)
            """
            return iterable

        try:
            iterable = self.app(env, my_start_response)
        except Exception:
            self.publish_sample(env, input_proxy.bytes_received, 0)
            raise
        else:
            return iter_response(iterable)

I have no idea why the python for loop makes the response become empty.
Could any one else help to check this issue?

Thanks a lot!

Mehdi Abaakouk (sileht)
Changed in ceilometer:
status: New → Incomplete
status: Incomplete → Confirmed
assignee: nobody → Mehdi Abaakouk (sileht)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to ceilometer (master)

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

Changed in ceilometer:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

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

Revision history for this message
Che-Wei Hu (tethu0822) wrote :

Hi, Mehdi Abaakouk:

Thanks for your reply and help.

I tried the patch and I got the exception for the publishing fail.

But I did the following modification I can get correct response from swift proxy:

class CeilometerMiddleware(object):
    ...
    def __call__(self, env, start_response):
        ...

        def iter_response(iterable):
            if start_response_args[0]:
                start_response(*start_response_args[0])

            bytes_sent = 0
            try:
                """
                for chunk in iterable:
                    if chunk:
                        bytes_sent += len(chunk)
                    yield chunk
                """
                return iterable
            finally:
                self.publish_sample(env,
                                                      input_proxy.bytes_received,
                                                      bytes_sent)

        try:
            iterable = self.app(env, my_start_response)
        except Exception:
            self.publish_sample(env, input_proxy.bytes_received, 0)
            raise
        else:
            return iter_response(iterable)

I think they are different issues.

Revision history for this message
Che-Wei Hu (tethu0822) wrote :

Hi, Mehdi Abaakouk:

Sorry! There is a typo in my test code.

Therefore, the empty response is caused by the failing publish.

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

Reviewed: https://review.openstack.org/46048
Committed: http://github.com/openstack/ceilometer/commit/e52e5070b3e0fb8c71e806eda036631e25628800
Submitter: Jenkins
Branch: master

commit e52e5070b3e0fb8c71e806eda036631e25628800
Author: Mehdi Abaakouk <email address hidden>
Date: Wed Sep 11 11:07:30 2013 +0200

    Don't publish samples if resource_id in missing

    In swift API, the user can call uri without the resource_id.
    This patch skip the samples publishing instead of raising the
    exception:

    Traceback (most recent call last):
    File "ceilometer/objectstore/swift_middleware.py", line 109, in iter_response
        bytes_sent)
    File "ceilometer/objectstore/swift_middleware.py", line 160, in publish_sample
        resource_id=account.partition('AUTH_')[2],
    AttributeError: 'NoneType' object has no attribute 'partition'

    It print the exception of the samples publishing failure instead of
    raising a exception to never break the swift API.

    Fixes bug #1223259

    Change-Id: I5d90fa620c8f8ea82e86524b9703049257ca0345

Changed in ceilometer:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in ceilometer:
milestone: none → havana-rc1
status: Fix Committed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to ceilometer (stable/grizzly)

Fix proposed to branch: stable/grizzly
Review: https://review.openstack.org/51633

Eoghan Glynn (eglynn)
tags: added: grizzly-backport-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ceilometer (stable/grizzly)

Reviewed: https://review.openstack.org/51633
Committed: http://github.com/openstack/ceilometer/commit/5f3fe99ba85f5b56b826c1f458af3d129531cca1
Submitter: Jenkins
Branch: stable/grizzly

commit 5f3fe99ba85f5b56b826c1f458af3d129531cca1
Author: Mehdi Abaakouk <email address hidden>
Date: Wed Sep 11 11:07:30 2013 +0200

    Don't publish samples if resource_id in missing

    In swift API, the user can call uri without the resource_id.
    This patch skip the samples publishing instead of raising the
    exception:

    Traceback (most recent call last):
    File "ceilometer/objectstore/swift_middleware.py", line 109, in iter_response
        bytes_sent)
    File "ceilometer/objectstore/swift_middleware.py", line 160, in publish_sample
        resource_id=account.partition('AUTH_')[2],
    AttributeError: 'NoneType' object has no attribute 'partition'

    It print the exception of the samples publishing failure instead of
    raising a exception to never break the swift API.

    Fixes bug #1223259

    Change-Id: I5d90fa620c8f8ea82e86524b9703049257ca0345
    (cherry picked from commit e52e5070b3e0fb8c71e806eda036631e25628800)

Thierry Carrez (ttx)
Changed in ceilometer:
milestone: havana-rc1 → 2013.2
Alan Pevec (apevec)
tags: removed: grizzly-backport-potential
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.