Skip to content

Look up TriggerDB objects by id / uid if available - #2788

Merged
Kami merged 6 commits into
masterfrom
trigger_lookup_workaround
Jul 1, 2016
Merged

Kami merged 6 commits into
masterfrom
trigger_lookup_workaround

Conversation

@Kami

@Kami Kami commented Jul 1, 2016 •

Copy link
Copy Markdown
Member

With this change we now try to look up TriggerDB objects by id / uid if either of those fields is available.

This way we can avoid lookup by type and parameters dictionary which fails in some scenarios. There are at least two bugs related "by parameters dictionary" lookup. One is related to unicode caching bug in mongoengine (I've added a nasty hack / work-around for it a while back) and the other one is yet to be tracked down.

My goal also is to confirm that id / uid field is always available so we can get rid of parameters dictionary lookup all together (that's something I wanted to do more than a year ago and I believe now it's finally possible to do that without much effort).

This hopefully resolves issue described in #2765.

TODO

  • Tests
  • Changelog entry

Kami added 3 commits July 1, 2016 17:04
If id or uid is available, use that instead of trying to look up trigger by
"parameters" dictionary. This way we can avoid parameters dictionary lookup
related bugs in pymongo / mongoengine.
@Kami Kami changed the title Look up TriggerDB objects by id / uid if available [WIP] Look up TriggerDB objects by id / uid if available Jul 1, 2016
@codyaray

codyaray commented Jul 1, 2016

Copy link
Copy Markdown
Contributor

No bueno.

2016-07-01 11:27:00,011 139970562091760 ERROR consumers [-] StagedQueueConsumer failed to process message: {'trace_context': <st2common.models.api.trace.TraceContext object at 0x7f4d6f6d46d0>, 'trigger': {'uid': u'trigger:core:0cd7ccb4-685f-4190-be21-646d69ab2684:425f230deef6d69b5555fc811ae3be29', 'parameters': {u'minute': u'*', u'hour': u'*', u'day': u'*'}, 'description': None, 'ref_count': 1, 'pack': u'core', 'type': u'core.st2.CronTimer', 'id': '577698a170608e477922f94f', 'name': u'0cd7ccb4-685f-4190-be21-646d69ab2684'}, 'payload': {'executed_at': '2016-07-01 16:27:00.007196+00:00', 'schedule': None}}
Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/transport/consumers.py", line 76, in process
    response = self._handler.pre_ack_process(body)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/rules/worker.py", line 56, in pre_ack_process
    raise_on_no_trigger=True)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/container/utils.py", line 53, in create_trigger_instance
    trigger_db = TriggerService.get_trigger_db_by_id(id=id)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/services/triggers.py", line 107, in get_trigger_db_by_id
    return Trigger.get_by_id(id)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/persistence/base.py", line 84, in get_by_id
    return cls._get_impl().get_by_id(value)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/models/db/__init__.py", line 170, in get_by_id
    return self.get(id=value, raise_exception=True)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/models/db/__init__.py", line 189, in get
    instance = instances[0] if instances else None
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 47, in __len__
    list(self._iter_results())
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 81, in _iter_results
    self._populate_cache()
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 93, in _populate_cache
    self._result_cache.append(self.next())
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 1137, in next
    raw_doc = self._cursor.next()
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 1182, in _cursor
    self._cursor_obj = self._collection.find(self._query,
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 1215, in _query
    self._mongo_query = self._query_obj.to_query(self._document)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/queryset/visitor.py", line 92, in to_query
    query = query.accept(QueryCompilerVisitor(document))
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/queryset/visitor.py", line 157, in accept
    return visitor.visit_query(self)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/queryset/visitor.py", line 80, in visit_query
    return transform.query(self.document, **query.query)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/queryset/transform.py", line 87, in query
    value = field.prepare_query_value(op, value)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/base/fields.py", line 405, in prepare_query_value
    return self.to_mongo(value)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/base/fields.py", line 401, in to_mongo
    self.error(unicode(e))
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/mongoengine/base/fields.py", line 124, in error
    raise ValidationError(message, errors=errors, field_name=field_name)
ValidationError: u'<built-in function id>' is not a valid ObjectId, it must be a 12-byte input of type 'str' or a 24-character hex string

@codyaray

codyaray commented Jul 1, 2016

Copy link
Copy Markdown
Contributor

This seems to work for me. When I manually applied this patch to our dev cluster which was exhibiting these issues, jobs started triggering again immediately. I'm feeling hopeful.

I'm keeping an eye on it today and will check when I return from vacation after next week to see how well its done. My colleagues will likely just yank our jobs back out of st2 while I'm gone, so hopefully this patch holds. :)

Once you merge, we'll upgrade to the latest unstable/dev version which is slightly better than my manually-patched version. ;) Then we'll upgrade to 1.5.1 once its out.

Thanks Kami.

@Kami

Kami commented Jul 1, 2016

Copy link
Copy Markdown
Member Author

@codyaray Great, thanks for reporting and confirming. And yeah, please keep us posted :)

@Kami Kami changed the title [WIP] Look up TriggerDB objects by id / uid if available Look up TriggerDB objects by id / uid if available Jul 1, 2016
@Kami
Kami merged commit 266903d into master Jul 1, 2016
@Kami
Kami deleted the trigger_lookup_workaround branch July 1, 2016 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants