New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 755415 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Closed: Apr 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 2
Type: Bug



Sign in to add a comment

Allow creating Metric objects at import-time when using indirect=True

Project Member Reported by pho...@chromium.org, Aug 15 2017

Issue description

Currently, 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.
 
Cc: jkop@chromium.org
+jkop candidate starter bug

Paul have you got some idea in mind how this could be accomplished?

Comment 2 by pho...@chromium.org, 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
    

Comment 3 by pho...@chromium.org, 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.
Project Member

Comment 4 by bugdroid1@chromium.org, 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

Comment 5 by pho...@chromium.org, Apr 21 2018

Owner: akes...@chromium.org
assigning to akeshet for triage
Status: WontFix (was: Untriaged)
Probably not needed, we can avoid import-time creation of metrics.

Sign in to add a comment