Example #1
0
def test_will_report_route_ids():
    config = Config(ParsedConfig('ReportRouteIDs true'))
    assert config.will_report_route_ids
    config = Config(ParsedConfig('ReportRouteIDs false'))
    assert not config.will_report_route_ids
    config = Config(ParsedConfig('ReportRouteIDs false\nRouteIDs'))
    assert not config.will_report_route_ids
    config = Config(ParsedConfig('ReportRouteIDs true\nRouteIDs "808-808"'))
    assert config.will_report_route_ids
    config = Config(ParsedConfig('ReportRouteIDs false\nRouteIDs "808-808"'))
    assert config.will_report_route_ids
Example #2
0
def test_will_report_http_methods():
    config = Config(ParsedConfig('ReportHTTPMethods true'))
    assert config.will_report_http_methods
    config = Config(ParsedConfig('ReportHTTPMethods false'))
    assert not config.will_report_http_methods
    config = Config(ParsedConfig('ReportHTTPMethods false\nHTTPMethods'))
    assert not config.will_report_http_methods
    config = Config(ParsedConfig('ReportHTTPMethods true\nHTTPMethods "GET"'))
    assert config.will_report_http_methods
    config = Config(ParsedConfig('ReportHTTPMethods false\nHTTPMethods "GET"'))
    assert config.will_report_http_methods
Example #3
0
def test_will_report_api_ids():
    config = Config(ParsedConfig('ReportAPIIDs true'))
    assert config.will_report_api_ids
    assert config.will_report_apis
    config = Config(ParsedConfig('ReportAPIIDs false'))
    assert not config.will_report_api_ids
    assert config.will_report_apis  # default
    config = Config(ParsedConfig('ReportAPIIDs false\nAPIIDs'))
    assert not config.will_report_api_ids
    assert config.will_report_apis  # default
    config = Config(ParsedConfig('ReportAPIIDs true\nAPIIDs "808-808"'))
    assert config.will_report_api_ids
    assert config.will_report_apis
    config = Config(ParsedConfig('ReportAPIIDs false\nAPIIDs "808-808"'))
    assert config.will_report_api_ids
    assert config.will_report_apis
Example #4
0
def test_will_report_api_names():
    config = Config(ParsedConfig('ReportAPINames true'))
    assert config.will_report_api_names
    assert config.will_report_apis
    config = Config(ParsedConfig('ReportAPINames false'))
    assert not config.will_report_api_names
    assert config.will_report_apis  # default
    config = Config(ParsedConfig('ReportAPINames false\nAPINames'))
    assert not config.will_report_api_names
    assert config.will_report_apis  # default
    config = Config(ParsedConfig('ReportAPINames true\nAPINames "MyAPI"'))
    assert config.will_report_api_names
    assert config.will_report_apis
    config = Config(ParsedConfig('ReportAPINames false\nAPINames "MyAPI"'))
    assert config.will_report_api_names
    assert config.will_report_apis
Example #5
0
def test_parsed_config():
    config_string = (
        '\n\n\n\t\t\t\t     Key1 "Value1"\n\n\n\n\n\t\t\t\t\t  \n\n\n Key2 "Value2" "Value3"\n\t\t'
        '\t\t\tKey3 true\n Key4 false\nKey5 100\n\n\n Key5 200\n\n\nKey6 "multiple component" '
        '"strings with spaces"')
    config = ParsedConfig(config_string)
    children = config.children
    assert children
    child = children[0]
    assert child.key == 'Key1'
    assert child.values == ['Value1']
    child = children[1]
    assert child.key == 'Key2'
    assert child.values == ['Value2', 'Value3']
    child = children[2]
    assert child.key == 'Key3'
    assert child.values == [True]
    child = children[3]
    assert child.key == 'Key4'
    assert child.values == [False]
    child = children[4]
    assert child.key == 'Key5'
    assert child.values == [100]
    child = children[5]
    assert child.key == 'Key5'
    assert child.values == [200]
    child = children[6]
    assert child.key == 'Key6'
    assert child.values == ['multiple component', 'strings with spaces']
Example #6
0
def test_will_report_service_ids():
    config = Config(ParsedConfig('ReportServiceIDs true'))
    assert config.will_report_service_ids
    assert config.will_report_services
    config = Config(ParsedConfig('ReportServiceIDs false'))
    assert not config.will_report_service_ids
    assert config.will_report_services  # default
    config = Config(ParsedConfig('ReportServiceIDs false\nServiceIDs'))
    assert not config.will_report_service_ids
    assert config.will_report_services  # default
    config = Config(
        ParsedConfig('ReportServiceIDs true\nServiceIDs "808-808"'))
    assert config.will_report_service_ids
    assert config.will_report_services
    config = Config(
        ParsedConfig('ReportServiceIDs false\nServiceIDs "808-808"'))
    assert config.will_report_service_ids
    assert config.will_report_services
Example #7
0
def test_will_report_service_names():
    config = Config(ParsedConfig('ReportServiceNames true'))
    assert config.will_report_service_names
    assert config.will_report_services
    config = Config(ParsedConfig('ReportServiceNames false'))
    assert not config.will_report_service_names
    assert config.will_report_services  # default
    config = Config(ParsedConfig('ReportServiceNames false\nServiceNames'))
    assert not config.will_report_service_names
    assert config.will_report_services  # default
    config = Config(
        ParsedConfig('ReportServiceNames true\nServiceNames "MyService"'))
    assert config.will_report_service_names
    assert config.will_report_services
    config = Config(
        ParsedConfig('ReportServiceNames false\nServiceNames "MyService"'))
    assert config.will_report_service_names
    assert config.will_report_services
def test_metrics_with_using_defaults():
    cfg_str = '''
    MetrIc "metric_two" true
    MeTric "metric_four" true
    '''
    cfg = Config(ParsedConfig(cfg_str), metrics=metrics)
    assert cfg.metric_one is True
    assert cfg.metric_two is True
    assert cfg.metric_three is True
    assert cfg.metric_four is True
Example #9
0
def test_confirm_metrics_source_extra_dimensions(reporter, metric):
    cfg_str = '''
    ExtraDimension "test_dimension" "test_val"
    ExtraDimension "another_dimension" "another_val"
    '''
    reporter.config = Config(ParsedConfig(cfg_str))
    reporter.update_http_method_scope_groups()
    metrics = reporter.calculate_status_code_scope_metrics(metric)
    assert metrics
    for met in metrics:
        assert met.dimensions['test_dimension'] == 'test_val'
        assert met.dimensions['another_dimension'] == 'another_val'
Example #10
0
def test_extra_dimensions():
    cfg_str = '''
    ExTraDiMension "dimension_one" "thing_one"
    EXTraDimenSion "dimension_two" "thing_two"
    ExtraDimension "dimension_three" "one"
    ExtraDimension "dimension_three" "two"
    ExtraDimension "invalid" "too" "many" "arguments"
    ExtraDimension "invalid"
    '''
    cfg = Config(ParsedConfig(cfg_str))
    assert cfg.extra_dimensions == dict(dimension_one='thing_one',
                                        dimension_two='thing_two',
                                        dimension_three='two')
Example #11
0
def test_https_settings():
    assert config.auth_header == [
        'Authorization', 'Basic YWRtaW46cGFzc3dvcmQ='
    ]
    assert config.verify_certs is True
    assert config.ca_bundle == '/etc/certs'
    assert config.client_cert == '/usr/local/kong/cert.pem'
    assert config.client_cert_key == '/usr/local/kong/cert.key'
    cfg = Config(ParsedConfig('VerifyCerts false'))
    assert cfg.auth_header is None
    assert cfg.verify_certs is False
    assert cfg.ca_bundle is None
    assert cfg.client_cert is None
    assert cfg.client_cert_key is None
Example #12
0
def test_descriptors_with_using_defaults():
    cfg_str = '''
    DescrIptorOne true
    DescriptorSix true true 123 false "test"
    DescriptorFive "four" "five"
    DescripTorFive "six"
    '''
    cfg = Config(ParsedConfig(cfg_str), descriptors=descriptors)
    assert cfg.descriptor_one is True
    assert cfg.descriptor_two is True
    assert cfg.descriptor_three == 234.0
    assert cfg.descriptor_four == ['one', 'two']
    assert cfg.descriptor_five == [['four', 'five'], ['six']]
    assert cfg.descriptor_six == [True, True, 123.0, False, 'test']
Example #13
0
def test_descriptors_without_using_defaults():
    cfg_str = '''
    DesCriptorOne true
    DescriptorTwo false
    DescripTorThree 123
    DesCriptorFour -123.456
    DescriptorFive "one" "two" "three"
    DesCriptorSix true true 123 false "test"
    Descriptorfive "four" "five"
    DescripTorFive "six"
    '''
    cfg = Config(ParsedConfig(cfg_str), descriptors=descriptors)
    assert cfg.descriptor_one is True
    assert cfg.descriptor_two is False
    assert cfg.descriptor_three == 123.0
    assert cfg.descriptor_four == -123.456
    assert cfg.descriptor_five == [['one', 'two', 'three'], ['four', 'five'],
                                   ['six']]
    assert cfg.descriptor_six == [True, True, 123.0, False, 'test']
Example #14
0
def test_will_report_status_codes():
    with pytest.raises(Exception) as e:
        config = Config(
            ParsedConfig(
                'ReportStatusCodes true\nReportStatusCodeGroups true'))
    assert 'Cannot simultaneously' in str(e)
    config = Config(
        ParsedConfig('ReportStatusCodes true\nReportStatusCodeGroups false'))
    assert config.will_report_status_codes
    config = Config(
        ParsedConfig('ReportStatusCodes false\nReportStatusCodeGroups true'))
    assert config.will_report_status_codes
    config = Config(
        ParsedConfig('ReportStatusCodes false\nReportStatusCodeGroups false'))
    assert not config.will_report_status_codes
    with pytest.raises(Exception) as e:
        config = Config(
            ParsedConfig(
                'ReportStatusCodes true\nReportStatusCodeGroups true\n'
                'ReportStatusCodes 200'))
    assert 'Cannot simultaneously' in str(e)
    config = Config(
        ParsedConfig(
            'ReportStatusCodes true\nReportStatusCodeGroups false\nStatusCodes 200'
        ))
    assert config.will_report_status_codes
    assert config.status_codes_whitelist.elements == ['200']
    config = Config(
        ParsedConfig(
            'ReportStatusCodes false\nReportStatusCodeGroups true\nStatusCodes 200'
        ))
    assert config.will_report_status_codes
    config = Config(
        ParsedConfig(
            'ReportStatusCodes false\nReportStatusCodeGroups false\nStatusCodes 200'
        ))
    assert config.will_report_status_codes
Example #15
0
ServiceNames "MyOther*"
ServiceNamesBlacklist "MyOtherService"
ReportServiceIDs false
ServiceIDs "808-808"
ServiceIDs "101-101"
ServiceIDsBlacklist "102-102"
ServiceIDsBlacklist "202-202"
ReportRouteIDs false
RouteIDs "808-808"
RouteIDs "101-101"
RouteIDsBlacklist "102-102"
RouteIDsBlacklist "202-202"
Verbose true
ExtraDimension "some_dimension" "some_val"
"""
parsed_config = ParsedConfig(config_string)
config = Config(parsed_config)


def test_metric_attributes():
    assert config.total_requests is True
    assert config.request_size is True
    assert config.request_latency is True
    assert config.kong_latency is True
    assert config.upstream_latency is True
    assert config.response_size is False
    assert config.response_count is False


def test_boolean_report_attributes():
    assert config.interval == 10
Example #16
0
def test_metrics_with_invalid_registration():
    with pytest.raises(TypeError):
        Config(ParsedConfig('Metric'), metrics=metrics)