Skip to content

Instantly share code, notes, and snippets.

@terriyu
Last active December 19, 2015 13:38
Show Gist options
  • Save terriyu/5963249 to your computer and use it in GitHub Desktop.
Save terriyu/5963249 to your computer and use it in GitHub Desktop.
Journal for OpenStack Ceilometer work -- 9 Jul 2013

9 Jul 2013

Note on using Markdown in Gist

  • Mixed nested lists don't work in GitHub flavored Markdown, as seen here:

    1. Mixing
    2. Ordered (numbered) lists
    3. With unordered (bulleted) lists
    4. Doesn't work -- gets rendered as a code block

More on MIM

I asked jd "what is MIM and why is it used?" This is his answer:

it's a Python library providing the same API as PyMongo, but which instead of connecting to MongoDB like Pymongo does, implements the API internally with Python code + a JavaScript via Spidermonkey

so the unit tests thinks we are using Pymongo and talking with MongoDB, but actually that's not true

why we picked it up, that's because we didn't want to have to run MongoDB on the CI infrastructure back in time

and for our usage of MongoDB, MIM was good enough

now as you can see, we're having problem in MongoDB we can't see in MIM, so that's causing major issues

plus the fact that I want to use advanced function in MongoDB like aggregate() and MIM doesn't implement that

Bug I'm working on, "unable to sort data with MongoDB"

Status

Indexing references and notes

Attempt to add index and fix the bug

  • In this section, I'm working on the file ceilometer/storage/impl_mongodb.py

  • I inserted a line

    self.db.meter.create_index([('timestamp', pymongo.DESCENDING)], name='timestamp_idx')
    

    in __init__() of Class Connection.

  • Since it's an index on a single field, I don't have to specify the order, so I changed this to

    self.db.meter.create_index('timestamp', name='timestamp_idx')
    
  • Tried both create_index() and ensure_index() but neither worked; I still got the error about too much data to sort properly and needing an index.

  • Tried providing hints in get_samples() -- the function I'm testing, but this didn't work either.

    samples = self.db.meter.find(q, sort=[("timestamp", pymongo.DESCENDING)], hint='timestamp_idx')
    
    samples = self.db.meter.find(q, sort=[("timestamp", pymongo.DESCENDING)], hint='timestamp')
    

Debugging

  • In PyMongo, you use the function index_information() to get information on a collection's indexes. It returns a dictionary containing all the defined indexes. Reference: http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.index_information

  • I used an assert statement to find out the value of db.meter.index_information():

    assert False, self.db.meter.index_information()
    

    Inside __init__(), the value was

    {u'_id_': {u'key': [(u'_id', 1)], u'v': 1}, u'timestamp_idx': {u'key': [(u'timestamp', 1)], u'v': 1}, u'meter_idx': {u'key': [(u'resource_id', 1), (u'user_id', 1), (u'counter_name', 1), (u'timestamp', 1), (u'source', 1)], u'v': 1}}
    

    Inside get_samples(), the value was

    {u'_id_': {u'key': [(u'_id', 1)], u'v': 1}}
    

    So it seems like the index is created and visible where it is defined in __init__(), but it either doesn't exist or isn't visible to get_samples()

    I also tried pulling the latest changes and rebasing, but the value of db.meter.index_information() inside get_samples() is still

    {u'_id_': {u'key': [(u'_id', 1)], u'v': 1}}
    
  • I tried going back to the MIM implementation instead of using the MongoDB instance, by running the command

    $ unset CEILOMETER_TEST_MONGODB_URL
    

    This deletes the CEILOMETER_TEST_MONGODB_URL environment variable. When Ceilometer can't find this variable, it defaults to using MIM.

    Inside __init__(), the value was

    {'timestamp_idx': {'key': (('timestamp', 1),)}, 'meter_idx': {'key': (('resource_id', 1), ('project_id', 1), ('counter_name', 1), ('timestamp', 1), ('source', 1))}}
    

    Inside get_samples(), the value of index_information() was

    {'timestamp_idx': {'key': (('timestamp', 1),)}, 'meter_idx': {'key': (('resource_id', 1), ('project_id', 1), ('counter_name', 1), ('timestamp', 1), ('source', 1))}}
    

    So interestingly enough, with the MIM implementation, the indexes are present in get_samples()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment