Allow creating Metric objects at import-time when using indirect=True |
|||
Issue descriptionCurrently, chromite.lib.metric uses decorators for supporting sending metrics with a separate process (via the "indirect" flag to SetupTsMonGlobalState). This forces the decision of whether to send the metric indirectly to be made at the metric creation time. Therefore, a metric constructed at the module- or class-level will NEVER be indirect, because the message queue will not have been setup yet (via chromite.lib.ts_mon_config.SteupTsMonGlobalState). This is inconvenient and leads to silent failures where a metrics object is constructed and set, but never gets sent by the metrics-publishing subprocess.
,
Aug 15 2017
The problem is chromite.lib._Indirect makes the decision at metric-creation time as to whether to create a proxymetric or not:
def _Indirect(fn):
"""Decorates a function to be indirect If MESSAGE_QUEUE is set.
If MESSAGE_QUEUE is set, the indirect function will return a proxy metrics
object; otherwise, it behaves normally.
"""
@wraps(fn)
def AddToQueueIfPresent(*args, **kwargs):
if MESSAGE_QUEUE:
return ProxyMetric(fn.__name__, args, kwargs)
else:
# Whether to reset the metric after the flush; this is only used by
# |ProxyMetric|, so remove this from the kwargs.
kwargs.pop('reset_after', None)
return fn(*args, **kwargs)
return AddToQueueIfPresent
One way to solve this would be to wait until a method is called to decide whether to send to the MESSAGE_QUEUE or whether to create the metric in-process.
Something like
class MaybeProxy(object):
def __init__(*args, **kwargs):
#store args and kwargs
self._metric = None
def __getattr__(self, name):
if self._metric:
return getattr(self._metric, name):
elif MESSAGE_QUEUE:
# create a proxy, call the method on it
else:
# create a non-proxy, call the method on it
,
Aug 15 2017
If you want to avoid __getattr__ magic you can spell out the specific methods you want to allow to be called, although, that won't be forwards-compatible.
,
Aug 24 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromiumos/third_party/autotest/+/e141622063f241bf81dbd7db9aebffca02d3e888 commit e141622063f241bf81dbd7db9aebffca02d3e888 Author: Paul Hobbs <phobbs@google.com> Date: Thu Aug 24 02:04:06 2017 drone_manager: Fix drone/active_processes metric Chromite metrics cannot be created at the module level because of crbug.com/755415 BUG= chromium:755415 TEST=None Change-Id: Ib8042a120f4bd3e76be0292e4749d55050d552d1 Reviewed-on: https://chromium-review.googlesource.com/627978 Commit-Ready: Paul Hobbs <phobbs@google.com> Tested-by: Paul Hobbs <phobbs@google.com> Reviewed-by: Dan Shi <dshi@google.com> [modify] https://crrev.com/e141622063f241bf81dbd7db9aebffca02d3e888/scheduler/drone_manager.py
,
Apr 21 2018
assigning to akeshet for triage
,
Apr 24 2018
Probably not needed, we can avoid import-time creation of metrics. |
|||
►
Sign in to add a comment |
|||
Comment 1 by akes...@chromium.org
, Aug 15 2017