async def _run(self):
     logger.info("{!r}: started", self)
     try:
         while True:
             if self._last_timestamp is None or self._throttle:
                 # We either never got bumped or we just missed a deadline
                 # and ran the timeout callback.  Wait for the entire
                 # timeout duration in either case, so that we don't spam
                 # the timeout callback.
                 timeout = self._timeout + self._grace_period
                 await self._run_timeout_callback_after(timeout)
             else:
                 # Calculate a deadline by which we expect the next bump,
                 # based on the last time at which we got bumped.
                 # We assume our local clock and the clock source for the
                 # last timestamp to be synchronized within the grace period.
                 # If the deadline is in the past, immediately run the
                 # timeout callback.
                 now = Timestamp.now()
                 deadline = self._last_timestamp + self._timeout + self._grace_period
                 if deadline <= now:
                     logger.debug("{!r}: deadline in the past!", self)
                     self._run_timeout_callback()
                     self._throttle = True
                 else:
                     wait_duration = deadline - now
                     await self._run_timeout_callback_after(wait_duration)
     except CancelledError:
         logger.info("{!r}: stopped", self)
         raise
     except Exception as e:  # pylint: disable=broad-except
         logger.exception(
             "{!r}: unexpected error inside TimeoutCheck callback: {}",
             self, e)
async def test_timeout_check_bump_once(timeout_check: TimeoutCheck):
    now = Timestamp.now()
    timeout_check.bump(now)

    await step()

    callback = cast(Callback, timeout_check._timeout_callback)
    assert not callback.called
    assert timeout_check._last_timestamp == now
def run_source(ssource):
    ssource.declare_metrics(
        {"dummy.time": {
            "unit": "s",
            "location": "localhost"
        }})
    try:
        while True:
            ssource.send("dummy.time", Timestamp.now(), time.time())
            time.sleep(0.1)
    except KeyboardInterrupt:
        logger.info("stopping SynchronousSource")
    ssource.stop()
Beispiel #4
0
    def run(self):
        assert self.import_begin is None
        if not click.confirm(f'Please make sure the MetricQ db with the token '
                             f'{self.token}" is not running! Continue?'):
            return

        self.update_config()
        self.create_bindings()
        self.import_begin = Timestamp.now()
        self.run_import()

        if self.failed_imports:
            print('The following metrics have failed to import:')
            for metric in self.failed_imports:
                print(f' - {metric.metricq_name}')
Beispiel #5
0
    def real_run(self):
        assert self._import_begin is None
        self._confirm(f"Please make sure the MetricQ db with the token "
                      f'"{self._metricq_token}" is not running! Continue?')

        self._update_config()
        if not self._resume:
            self._create_bindings()
        self._import_begin = Timestamp.now()
        self._run_import()

        if self._failed_imports:
            print("The following metrics have failed to import:")
            for metric in self._failed_imports:
                print(f" - {metric.metricq_name}")
Beispiel #6
0
def synchronous_source(server, token):
    ssource = SynchronousSource(token=token, management_url=server)
    ssource.declare_metrics({
        "test.example.random": {
            "unit": "s",
            "description":
            "a test metric that just contains random numbers in the range [0.0, 1.0)",
            "rate": 10.0,
            "location": "localhost",
        }
    })
    try:
        while True:
            ssource.send("test.example.random", Timestamp.now(),
                         random.random())
            time.sleep(0.1)
    except KeyboardInterrupt:
        logger.info("stopping SynchronousSource")
    ssource.stop()