Пример #1
0
  def test_sample_by_process_from_history(self, mock_get_active_processes):

    fake_process_name_1 = 'fake-process-name-1'
    fake_process_name_2 = 'fake-process-name-2'
    task_path = '.'
    task_monitor = TaskMonitor(task_path, 'fake-task-id')
    fake_process_status_1 = ProcessStatus(process=fake_process_name_1)
    fake_process_status_2 = ProcessStatus(process=fake_process_name_2)
    mock_get_active_processes.return_value = [(fake_process_status_1, 1),
                                              (fake_process_status_2, 2)]

    fake_history = ResourceHistory(2)
    fake_history.add(time(), ResourceMonitorBase.FullResourceResult(
        {fake_process_status_1: ResourceMonitorBase.ProcResourceResult(ProcessSample.empty(), 1),
         fake_process_status_2: ResourceMonitorBase.ProcResourceResult(ProcessSample.empty(), 2),
         }, 10))

    task_resource_monitor = TaskResourceMonitor('fake-task-id', task_monitor,
        history_provider=self.FakeResourceHistoryProvider(fake_history))

    assert task_resource_monitor.name == 'TaskResourceMonitor[fake-task-id]'
    assert task_resource_monitor.sample_by_process(fake_process_name_1) == ProcessSample.empty()
    assert task_resource_monitor.sample_by_process(fake_process_name_2) == ProcessSample.empty()

    _, sample = task_resource_monitor.sample()
    assert sample.num_procs == 3  # 1 pid in fake_process_status_1 and 2 in fake_process_status_2
    assert sample.process_sample == ProcessSample.empty()
    assert sample.disk_usage == 10
    assert mock_get_active_processes.mock_calls == [mock.call(task_monitor),
        mock.call(task_monitor)]
Пример #2
0
  def test_sample_by_process_no_process(self, mock_get_active_processes):
    task_path = '.'

    task_monitor = TaskMonitor(task_path, 'fake-task-id')
    mock_get_active_processes.return_value = []

    task_resource_monitor = TaskResourceMonitor('fake-task-id', task_monitor)

    with self.assertRaises(ValueError):
      task_resource_monitor.sample_by_process('fake-process-name')

    assert mock_get_active_processes.mock_calls == [mock.call(task_monitor)]
Пример #3
0
  def test_sample_by_process(self, mock_get_active_processes, mock_sample):
    fake_process_name = 'fake-process-name'
    task_path = '.'
    task_monitor = TaskMonitor(task_path, 'fake-task-id')
    fake_process_status = ProcessStatus(process=fake_process_name)
    mock_get_active_processes.return_value = [(fake_process_status, 1)]
    fake_process_sample = ProcessSample.empty()
    mock_sample.return_value = fake_process_sample

    task_resource_monitor = TaskResourceMonitor('fake-task-id', task_monitor)

    assert fake_process_sample == task_resource_monitor.sample_by_process(fake_process_name)
    assert mock_get_active_processes.mock_calls == [mock.call(task_monitor)]
    assert mock_sample.mock_calls == [mock.call(
        task_resource_monitor._process_collectors[fake_process_status])]
Пример #4
0
    def __on_active(self, root, task_id):
        log.debug('on_active(%r, %r)', root, task_id)
        if task_id in self.finished_tasks:
            log.error('Found an active task (%s) in finished tasks?', task_id)
            return
        task_monitor = TaskMonitor(root, task_id)

        if self._disable_task_resource_collection:
            resource_monitor = NullTaskResourceMonitor()

        else:
            disk_collector_provider = DiskCollectorProvider(
                self._enable_mesos_disk_collector,
                self._disk_collector_settings)

            resource_monitor = TaskResourceMonitor(
                task_id,
                task_monitor,
                disk_collector_provider=disk_collector_provider,
                process_collection_interval=self.
                _task_process_collection_interval,
                disk_collection_interval=self._disk_collector_settings.
                disk_collection_interval)

        resource_monitor.start()
        self._active_tasks[task_id] = ActiveObservedTask(
            root, task_id, task_monitor, resource_monitor)
Пример #5
0
 def from_assigned_task(self, assigned_task, sandbox):
     task_id = assigned_task.taskId
     resources = mesos_task_instance_from_assigned_task(
         assigned_task).task().resources()
     task_monitor = TaskMonitor(self._checkpoint_root, task_id)
     resource_monitor = TaskResourceMonitor(
         task_id, task_monitor, **self._resource_monitor_options)
     return ResourceManager(resources, resource_monitor)
Пример #6
0
 def __on_active(self, root, task_id):
   log.debug('on_active(%r, %r)' % (root, task_id))
   if task_id in self.finished_tasks:
     log.error('Found an active task (%s) in finished tasks?' % task_id)
     return
   task_monitor = TaskMonitor(root, task_id)
   resource_monitor = TaskResourceMonitor(
       task_id,
       task_monitor,
       process_collection_interval=self._task_process_collection_interval,
       disk_collection_interval=self._task_disk_collection_interval)
   resource_monitor.start()
   self._active_tasks[task_id] = ActiveObservedTask(
       root,
       task_id,
       task_monitor,
       resource_monitor
   )
Пример #7
0
 def from_assigned_task(self, assigned_task, sandbox):
     task_id = assigned_task.taskId
     resources = mesos_task_instance_from_assigned_task(
         assigned_task).task().resources()
     task_path = TaskPath(root=self._checkpoint_root, task_id=task_id)
     task_monitor = TaskMonitor(task_path, task_id)
     resource_monitor = TaskResourceMonitor(
         task_monitor,
         sandbox.root,
         disk_collector=self._disk_collector,
         disk_collection_interval=self._disk_collection_interval)
     return ResourceManager(resources, resource_monitor)
Пример #8
0
  def __on_active(self, root, task_id):
    log.debug('on_active(%r, %r)', root, task_id)
    if task_id in self.finished_tasks:
      log.error('Found an active task (%s) in finished tasks?', task_id)
      return
    task_monitor = TaskMonitor(root, task_id)

    disk_collector_provider = DiskCollectorProvider(
      self._enable_mesos_disk_collector,
      self._disk_collector_settings)

    resource_monitor = TaskResourceMonitor(
        task_id,
        task_monitor,
        disk_collector_provider=disk_collector_provider,
        process_collection_interval=self._task_process_collection_interval,
        disk_collection_interval=self._disk_collector_settings.disk_collection_interval)
    resource_monitor.start()
    self._active_tasks[task_id] = ActiveObservedTask(
        root,
        task_id,
        task_monitor,
        resource_monitor)