def test_invalid_boto_config(aggregator, instance, dd_run_check, caplog): instance = copy.deepcopy(instance) HTTP_PROXY = {"http": "example.com"} init_config = {"proxy": HTTP_PROXY} instance["boto_config"] = {"proxies_config": {}, "read_timeout": True} c = AmazonMskCheck('amazon_msk', init_config, [instance]) with pytest.raises( Exception, match= r'Timeout cannot be a boolean value. It must be an int, float or None.' ): dd_run_check(c) cluster_arn = instance['cluster_arn'] region_name = cluster_arn.split(':')[3] global_tags = [ 'cluster_arn:{}'.format(cluster_arn), 'region_name:{}'.format(region_name), 'test:msk' ] aggregator.assert_service_check( AmazonMskCheck.SERVICE_CHECK_CONNECT, AmazonMskCheck.CRITICAL, message= "Timeout cannot be a boolean value. It must be an int, float or None.", tags=global_tags, ) assert c._boto_config.proxies == HTTP_PROXY
def test_custom_metric_path(aggregator, instance_legacy, mock_client): instance_legacy['prometheus_metrics_path'] = '/' c = AmazonMskCheck('amazon_msk', {}, [instance_legacy]) assert not c.run() caller, client = mock_client cluster_arn = instance_legacy['cluster_arn'] region_name = cluster_arn.split(':')[3] caller.assert_called_once_with('kafka', region_name=region_name, config=ANY) client.list_nodes.assert_called_once_with(ClusterArn=cluster_arn) global_tags = [ 'cluster_arn:{}'.format(cluster_arn), 'region_name:{}'.format(region_name) ] global_tags.extend(instance_legacy['tags']) aggregator.assert_service_check(c.SERVICE_CHECK_CONNECT, c.OK, tags=global_tags) for node_info in client.list_nodes()['NodeInfoList']: broker_info = node_info['BrokerNodeInfo'] broker_tags = ['broker_id:{}'.format(broker_info['BrokerId'])] broker_tags.extend(global_tags) assert_node_metrics_legacy(aggregator, broker_tags) assert_jmx_metrics_legacy(aggregator, broker_tags) for endpoint in broker_info['Endpoints']: for port in (11001, 11002): service_check_tags = [ 'endpoint:http://{}:{}/'.format(endpoint, port) ] service_check_tags.extend(global_tags) aggregator.assert_service_check('aws.msk.prometheus.health', c.OK, tags=service_check_tags) aggregator.assert_all_metrics_covered()
def test_disabled_exporter_legacy( aggregator, dd_run_check, instance_legacy, mock_client, jmx_exporter_port, node_exporter_port, assert_jmx_metrics_enabled, assert_node_metrics_enabled, ): inst = copy.deepcopy(instance_legacy) # Test both JMX and NODE exporters disabled inst.update({ "jmx_exporter_port": jmx_exporter_port, "node_exporter_port": node_exporter_port, }) c = AmazonMskCheck('amazon_msk', {}, [inst]) assert not c.run() assert_jmx_metrics(aggregator, [], is_enabled=assert_jmx_metrics_enabled) assert_node_metrics(aggregator, [], is_enabled=assert_node_metrics_enabled)
def test_boto_config(instance): instance = copy.deepcopy(instance) HTTP_PROXY = {"http": "example.com"} init_config = {"proxy": HTTP_PROXY} instance["boto_config"] = { "proxies_config": { "proxy_use_forwarding_for_https": True }, "read_timeout": 60 } c = AmazonMskCheck('amazon_msk', init_config, [instance]) assert c._boto_config.proxies == HTTP_PROXY assert c._boto_config.proxies_config.get("proxy_use_forwarding_for_https") assert c._boto_config.read_timeout == 60
def test_node_check(aggregator, dd_run_check, instance, mock_client): c = AmazonMskCheck('amazon_msk', {}, [instance]) dd_run_check(c) caller, client = mock_client cluster_arn = instance['cluster_arn'] region_name = cluster_arn.split(':')[3] caller.assert_called_once_with('kafka', config=ANY, region_name=region_name) client.list_nodes.assert_called_once_with(ClusterArn=cluster_arn) global_tags = [ 'cluster_arn:{}'.format(cluster_arn), 'region_name:{}'.format(region_name) ] global_tags.extend(instance['tags']) aggregator.assert_service_check('aws.msk.{}'.format( c.SERVICE_CHECK_CONNECT), c.OK, tags=global_tags) for node_info in client.list_nodes()['NodeInfoList']: broker_info = node_info['BrokerNodeInfo'] broker_tags = ['broker_id:{}'.format(broker_info['BrokerId'])] broker_tags.extend(global_tags) for endpoint in broker_info['Endpoints']: for port, metric_assertion in ((11001, assert_jmx_metrics), (11002, assert_node_metrics)): endpoint_tag = 'endpoint:http://{}:{}/metrics'.format( endpoint, port) metric_tags = [endpoint_tag] metric_tags.extend(broker_tags) metric_assertion(aggregator, metric_tags) service_check_tags = [endpoint_tag] service_check_tags.extend(global_tags) aggregator.assert_service_check('aws.msk.openmetrics.health', c.OK, tags=service_check_tags) aggregator.assert_all_metrics_covered()
def test_proxy_config(instance): HTTP_PROXY = {"http": "example.com"} init_config = {"proxy": HTTP_PROXY} c = AmazonMskCheck('amazon_msk', init_config, [instance]) assert c._boto_config.proxies == HTTP_PROXY