示例#1
0
def test_check_metrics_1_13(aggregator, mock_metrics, mock_leader):
    c = KubeSchedulerCheck(CHECK_NAME, None, {}, [instance])
    c.check(instance)

    def assert_metric(name, **kwargs):
        # Wrapper to keep assertions < 120 chars
        aggregator.assert_metric(NAMESPACE + name, **kwargs)

    assert_metric('.pod_preemption.victims', value=0.0, tags=[])
    assert_metric('.pod_preemption.attempts', value=10.0, tags=[])
    assert_metric('.binding_duration.count', value=0.0, tags=['upper_bound:0.001'])
    assert_metric('.binding_duration.sum', value=4.08376, tags=[])
    assert_metric('.scheduling.scheduling_duration.count', value=15.0, tags=['operation:binding'])
    assert_metric('.scheduling.scheduling_duration.sum', value=0.40872890000000006, tags=['operation:binding'])
    assert_metric('.scheduling.algorithm.predicate_duration.sum', value=0.0278, tags=[])
    assert_metric('.scheduling.e2e_scheduling_duration.count', value=0.0, tags=['upper_bound:0.001'])
    assert_metric('.scheduling.algorithm_duration.count', value=14.0, tags=['upper_bound:0.001'])
    assert_metric('.scheduling.e2e_scheduling_duration.sum', value=4.32862, tags=[])
    assert_metric(
        '.scheduling.scheduling_duration.quantile', value=0.0225032, tags=['operation:binding', 'quantile:0.5']
    )
    assert_metric('.scheduling.algorithm.priority_duration.sum', value=0.00237, tags=[])
    assert_metric('.scheduling.algorithm.priority_duration.count', value=15.0, tags=['upper_bound:0.004'])
    assert_metric('.scheduling.algorithm.preemption_duration.sum', value=0.51777, tags=[])
    assert_metric('.scheduling.algorithm.predicate_duration.count', value=15.0, tags=['upper_bound:0.001'])
    assert_metric('.scheduling.algorithm.preemption_duration.count', value=0.0, tags=['upper_bound:0.001'])
    assert_metric('.schedule_attempts', value=15.0, tags=['result:scheduled'])
    assert_metric('.cache.lookups')
    assert_metric('.volume_scheduling_duration.sum', value=0.0003541, tags=['operation:assume'])
    assert_metric(
        '.client.http.requests_duration.count',
        tags=['url:https://172.17.0.2:6443/%7Bprefix%7D', 'upper_bound:0.001', 'verb:GET'],
    )
    assert_metric(
        '.client.http.requests_duration.sum',
        value=86.3256595999997,
        tags=['url:https://172.17.0.2:6443/%7Bprefix%7D', 'verb:GET'],
    )
    assert_metric('.goroutines')
    assert_metric('.gc_duration_seconds.sum')
    assert_metric('.gc_duration_seconds.count')
    assert_metric('.gc_duration_seconds.quantile')
    assert_metric('.threads')
    assert_metric('.open_fds')
    assert_metric('.max_fds')
    assert_metric('.client.http.requests')
    assert_metric(
        '.volume_scheduling_duration.count', value=15.0, tags=['operation:predicate', 'upper_bound:1024000.0']
    )
    # check historgram transformation from microsecond to second
    assert_metric('.scheduling.algorithm_duration.sum', value=0.06377, tags=[])
    # Leader election mixin
    expected_le_tags = ["record_kind:endpoints", "record_name:kube-scheduler", "record_namespace:kube-system"]
    assert_metric('.leader_election.transitions', value=3, tags=expected_le_tags)
    assert_metric('.leader_election.lease_duration', value=15, tags=expected_le_tags)
    aggregator.assert_service_check(NAMESPACE + ".leader_election.status", tags=expected_le_tags)
    aggregator.assert_all_metrics_covered()
def test_check_metrics_1_14(aggregator, mock_metrics, mock_leader):
    c = KubeSchedulerCheck(CHECK_NAME, None, {}, [instance])
    c.check(instance)

    def assert_metric(name, **kwargs):
        # Wrapper to keep assertions < 120 chars
        aggregator.assert_metric(NAMESPACE + name, **kwargs)

    assert_metric('.pod_preemption.victims', value=0.0, tags=[])
    assert_metric('.pod_preemption.attempts', value=6.0, tags=[])
    assert_metric('.binding_duration.count', value=0.0, tags=['upper_bound:0.001'])
    assert_metric('.binding_duration.sum', value=0.16221686500000002, tags=[])
    assert_metric('.scheduling.scheduling_duration.count', value=14.0, tags=['operation:binding'])
    assert_metric('.scheduling.scheduling_duration.sum', value=0.16236949099999998, tags=['operation:binding'])
    assert_metric('.scheduling.algorithm.predicate_duration.sum', value=0.001379, tags=[])
    assert_metric('.scheduling.e2e_scheduling_duration.count', value=0.0, tags=['upper_bound:0.001'])
    assert_metric('.scheduling.algorithm_duration.count', value=14.0, tags=['upper_bound:0.001'])
    assert_metric('.scheduling.e2e_scheduling_duration.sum', value=0.166793941, tags=[])
    assert_metric(
        '.scheduling.scheduling_duration.quantile', value=0.01050672, tags=['operation:binding', 'quantile:0.5']
    )
    assert_metric('.scheduling.algorithm.priority_duration.sum', value=0.0, tags=[])
    assert_metric('.scheduling.algorithm.priority_duration.count', value=14.0, tags=['upper_bound:0.004'])
    assert_metric('.scheduling.algorithm.preemption_duration.sum', value=0.05524, tags=[])
    assert_metric('.scheduling.algorithm.predicate_duration.count', value=14.0, tags=['upper_bound:0.001'])
    assert_metric('.scheduling.algorithm.preemption_duration.count', value=0.0, tags=['upper_bound:0.001'])
    assert_metric('.schedule_attempts', value=14.0, tags=['result:scheduled'])
    assert_metric('.volume_scheduling_duration.sum', value=3.3576e-05, tags=['operation:assume'])
    assert_metric('.volume_scheduling_duration.count', value=14.0, tags=['upper_bound:1000.0', 'operation:assume'])
    assert_metric(
        '.client.http.requests_duration.count',
        tags=['url:https://172.17.0.2:6443/%7Bprefix%7D', 'upper_bound:0.001', 'verb:GET'],
    )
    assert_metric(
        '.client.http.requests_duration.sum',
        value=24.374537649,
        tags=['url:https://172.17.0.2:6443/%7Bprefix%7D', 'verb:GET'],
    )
    assert_metric('.goroutines')
    assert_metric('.gc_duration_seconds.sum')
    assert_metric('.gc_duration_seconds.count')
    assert_metric('.gc_duration_seconds.quantile')
    assert_metric('.threads')
    assert_metric('.open_fds')
    assert_metric('.max_fds')
    assert_metric('.client.http.requests')
    # check historgram transformation from microsecond to second
    assert_metric('.scheduling.algorithm_duration.sum', value=0.0018508010000000002, tags=[])
    # Leader election mixin
    expected_le_tags = ["record_kind:endpoints", "record_name:kube-scheduler", "record_namespace:kube-system"]
    assert_metric('.leader_election.transitions', value=3, tags=expected_le_tags)
    assert_metric('.leader_election.lease_duration', value=15, tags=expected_le_tags)
    aggregator.assert_service_check(NAMESPACE + ".leader_election.status", tags=expected_le_tags)
    aggregator.assert_all_metrics_covered()
def test_service_check_ok(monkeypatch):
    instance = {'prometheus_url': 'http://localhost:10251/metrics'}
    instance_tags = []

    check = KubeSchedulerCheck(CHECK_NAME, {}, [instance])

    monkeypatch.setattr(check, 'service_check', mock.Mock())

    calls = [
        mock.call('kube_scheduler.up', AgentCheck.OK, tags=instance_tags),
        mock.call('kube_scheduler.up',
                  AgentCheck.CRITICAL,
                  tags=instance_tags,
                  message='health check failed'),
    ]

    # successful health check
    with mock.patch("requests.get",
                    return_value=mock.MagicMock(status_code=200)):
        check._perform_service_check(instance)

    # failed health check
    raise_error = mock.Mock()
    raise_error.side_effect = requests.HTTPError('health check failed')
    with mock.patch("requests.get",
                    return_value=mock.MagicMock(raise_for_status=raise_error)):
        check._perform_service_check(instance)

    check.service_check.assert_has_calls(calls)
示例#4
0
def test_check_metrics_1_23(aggregator, mock_metrics, mock_leader):
    c = KubeSchedulerCheck(CHECK_NAME, {}, [instance])
    c.check(instance)

    def assert_metric(name, **kwargs):
        # Wrapper to keep assertions < 120 chars
        aggregator.assert_metric(NAMESPACE + name, **kwargs)

    assert_metric('.scheduling.algorithm_duration.count',
                  value=7,
                  tags=['upper_bound:0.001'])
    assert_metric('.scheduling.algorithm_duration.sum', value=0.002138012)

    assert_metric('.scheduling.e2e_scheduling_duration.sum', value=0.000195006)
    assert_metric(
        '.scheduling.e2e_scheduling_duration.count',
        value=7.0,
        tags=[
            'profile:default-scheduler', 'result:scheduled', 'upper_bound:none'
        ],
    )
    assert_metric(
        '.scheduling.e2e_scheduling_duration.count',
        value=3.0,
        tags=[
            'profile:default-scheduler', 'result:unschedulable',
            'upper_bound:none'
        ],
    )

    assert_metric('.schedule_attempts',
                  value=7.0,
                  tags=['profile:default-scheduler', 'result:scheduled'])
    assert_metric('.schedule_attempts',
                  value=3.0,
                  tags=['profile:default-scheduler', 'result:unschedulable'])

    assert_metric('.scheduling.attempt_duration.sum',
                  value=0.000195006,
                  tags=[])
    assert_metric(
        '.scheduling.attempt_duration.count',
        value=7.0,
        tags=[
            'profile:default-scheduler', 'result:scheduled', 'upper_bound:none'
        ],
    )
    assert_metric(
        '.scheduling.attempt_duration.count',
        value=3.0,
        tags=[
            'profile:default-scheduler', 'result:unschedulable',
            'upper_bound:none'
        ],
    )

    assert_metric('.scheduling.pod.scheduling_duration.sum',
                  value=0.056623216,
                  tags=['attempts:1'])
    assert_metric('.scheduling.pod.scheduling_duration.sum',
                  value=20.781201637,
                  tags=['attempts:2'])
    assert_metric('.scheduling.pod.scheduling_duration.count',
                  value=4.0,
                  tags=['attempts:1', 'upper_bound:none'])
    assert_metric('.scheduling.pod.scheduling_duration.count',
                  value=3.0,
                  tags=['attempts:2', 'upper_bound:none'])

    assert_metric('.scheduling.pod.scheduling_attempts.sum', value=10.0)
    assert_metric('.scheduling.pod.scheduling_attempts.count', value=7.0)

    assert_metric('.goroutines')
    assert_metric('.gc_duration_seconds.sum')
    assert_metric('.gc_duration_seconds.count')
    assert_metric('.gc_duration_seconds.quantile')
    assert_metric('.threads')
    assert_metric('.open_fds')
    assert_metric('.max_fds')
    assert_metric('.client.http.requests')

    expected_le_tags = [
        "record_kind:endpoints", "record_name:kube-scheduler",
        "record_namespace:kube-system"
    ]
    assert_metric('.leader_election.transitions',
                  value=3,
                  tags=expected_le_tags)
    assert_metric('.leader_election.lease_duration',
                  value=15,
                  tags=expected_le_tags)
    aggregator.assert_service_check(NAMESPACE + ".leader_election.status",
                                    tags=expected_le_tags)

    aggregator.assert_all_metrics_covered()