<commit_before>import logging
import contextlib
import ceph_manager
import time
import gevent
from teuthology import misc as teuthology

log = logging.getLogger(__name__)

class ClockSkewCheck:
  """
  Periodically check if there are any clock skews among the monitors in the
  quorum. By default, assume no skews are supposed to exist; that can be
  changed using the 'expect-skew' option. If 'fail-on-skew' is set to false,
  then we will always succeed and only report skews if any are found.

  This class does not spawn a thread. It assumes that, if that is indeed
  wanted, it should be done by a third party (for instance, the task using
  this class). We intend it as such in order to reuse this class if need be.

  This task accepts the following options:

   interval     amount of seconds to wait in-between checks. (default: 30.0)
   max-skew     maximum skew, in seconds, that is considered tolerable before
                issuing a warning. (default: 0.05)
   expect-skew  'true' or 'false', to indicate whether to expect a skew during
                the run or not. If 'true', the test will fail if no skew is
                found, and succeed if a skew is indeed found; if 'false', it's
                the other way around. (default: false)
   never-fail   Don't fail the run if a skew is detected and we weren't
                expecting it, or if no skew is detected and we were expecting
                it. (default: False)

   at-least-once          Runs at least once, even if we are told to stop.
                          (default: True)
   at-least-once-timeout  If we were told to stop but we are attempting to
                          run at least once, timeout after this many seconds.
                          (default: 600)

  Example:
    Expect a skew higher than 0.05 seconds, but only report it without failing
    the teuthology run.

    - mon_clock_skew_check:
        interval: 30
        max-skew: 0.05
        expect_skew: true
        never-fail: true
  """

  def __init__(self, ctx, manager, config, logger):
    self.ctx = ctx
    self.manager = manager;

    self.stopping = False
    self.logger = logger
    self.config = config

    if self.config is None:
      self.config = dict()

    self.check_interval = float(self.config.get('interval', 30.0))
    self.max_skew = float(self.config.get('max-skew', 0.05))
    self.expect_skew = self.config.get('expect-skew', False)
    self.never_fail = self.config.get('never-fail', False)
    self.at_least_once = self.config.get('at-least-once', True)
    self.at_least_once_timeout = self.config.get('at-least-once-timeout', 600.0)

  def info(self, x):
    self.logger.info(x)

  def warn(self, x):
    self.logger.warn(x)

  def debug(self, x):
    self.logger.debug(x)

  def finish(self):
    self.stopping = True

  def sleep_interval(self):
    if self.check_interval > 0.0:
      self.debug('sleeping for {s} seconds'.format(
        s=self.check_interval))
      time.sleep(self.check_interval)
<commit_msg>task: mon_clock_skew_check: by default, use max skew from global config<commit_after>import logging
import contextlib
import ceph_manager
import time
import gevent
from teuthology import misc as teuthology

log = logging.getLogger(__name__)

class ClockSkewCheck:
  """
  Periodically check if there are any clock skews among the monitors in the
  quorum. By default, assume no skews are supposed to exist; that can be
  changed using the 'expect-skew' option. If 'fail-on-skew' is set to false,
  then we will always succeed and only report skews if any are found.

  This class does not spawn a thread. It assumes that, if that is indeed
  wanted, it should be done by a third party (for instance, the task using
  this class). We intend it as such in order to reuse this class if need be.

  This task accepts the following options:

   interval     amount of seconds to wait in-between checks. (default: 30.0)
   max-skew     maximum skew, in seconds, that is considered tolerable before
                issuing a warning. (default: 0.05)
   expect-skew  'true' or 'false', to indicate whether to expect a skew during
                the run or not. If 'true', the test will fail if no skew is
                found, and succeed if a skew is indeed found; if 'false', it's
                the other way around. (default: false)
   never-fail   Don't fail the run if a skew is detected and we weren't
                expecting it, or if no skew is detected and we were expecting
                it. (default: False)

   at-least-once          Runs at least once, even if we are told to stop.
                          (default: True)
   at-least-once-timeout  If we were told to stop but we are attempting to
                          run at least once, timeout after this many seconds.
                          (default: 600)

  Example:
    Expect a skew higher than 0.05 seconds, but only report it without failing
    the teuthology run.

    - mon_clock_skew_check:
        interval: 30
        max-skew: 0.05
        expect_skew: true
        never-fail: true
  """

  def __init__(self, ctx, manager, config, logger):
    self.ctx = ctx
    self.manager = manager;

    self.stopping = False
    self.logger = logger
    self.config = config

    if self.config is None:
      self.config = dict()

    self.check_interval = float(self.config.get('interval', 30.0))

    # config defined max-skew must have priority over globally defined
    self.max_skew = float(
        self.config.get('max-skew',
          ctx.ceph.conf['global'].get('mon clock drift allowed', 0.05)
          )
        )

    self.expect_skew = self.config.get('expect-skew', False)
    self.never_fail = self.config.get('never-fail', False)
    self.at_least_once = self.config.get('at-least-once', True)
    self.at_least_once_timeout = self.config.get('at-least-once-timeout', 600.0)

  def info(self, x):
    self.logger.info(x)

  def warn(self, x):
    self.logger.warn(x)

  def debug(self, x):
    self.logger.debug(x)

  def finish(self):
    self.stopping = True

  def sleep_interval(self):
    if self.check_interval > 0.0:
      self.debug('sleeping for {s} seconds'.format(
        s=self.check_interval))
      time.sleep(self.check_interval)

{'fraction_non_alphanumeric': 0.08293384467881112, 'fraction_numerical': 0.009268136784915308, 'mean_word_length': 2.5261971830985916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7575611', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1808, 'n_words': 717}