コード例 #1
0
ファイル: initializer.py プロジェクト: zenmind101/socorro
def createPersistentInitialization(configModule):
    storage = sutil.DotDict()

    storage.config = config = socorro.lib.ConfigurationManager.newConfiguration(
        configurationModule=configModule, automaticHelp=False)
    storage.logger = logger = logging.getLogger("collector")

    logger.setLevel(logging.DEBUG)

    address = None
    if config.syslogTransport == 'socket':
        address = config.syslogSocket
    elif config.syslogTransport == 'udp':
        address = (config.syslogHost, config.syslogPort)
    else:
        from socorro.lib.ConfigurationManager import OptionError
        raise OptionError(
            'Unknown syslog transport %s') % config.syslogTransport

    syslog = logging.handlers.SysLogHandler(
        address=address,
        facility=config.syslogFacilityString,
    )
    syslog.setLevel(config.syslogErrorLoggingLevel)
    syslogFormatter = logging.Formatter(config.syslogLineFormatString)
    syslog.setFormatter(syslogFormatter)
    logger.addHandler(syslog)

    logger.info("current configuration:")
    for value in str(config).split('\n'):
        logger.info('%s', value)

    storage.config['logger'] = logger

    storage.crashStorage = config.primaryStorageClass(config)

    storage.legacyThrottler = cstore.LegacyThrottler(config)

    return storage
コード例 #2
0
def testLegacyThrottler():
    config = util.DotDict()
    config.throttleConditions = [('alpha', re.compile('ALPHA'), 100),
                                 ('beta', 'BETA', 100),
                                 ('gamma', lambda x: x == 'GAMMA', 100),
                                 ('delta', True, 100), (None, True, 0)]
    config.minimalVersionForUnderstandingRefusal = {
        'product1': '3.5',
        'product2': '4.0'
    }
    config.neverDiscard = False
    config.logger = util.SilentFakeLogger()
    thr = cstore.LegacyThrottler(config)
    expected = 5
    actual = len(thr.processedThrottleConditions)
    assert expected == actual, "expected thr.preprocessThrottleConditions to have length %d, but got %d instead" % (
        expected, actual)

    json1 = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.0',
        'alpha': 'ALPHA',
    })
    expected = False
    actual = thr.understandsRefusal(json1)
    assert expected == actual, "understand refusal expected %d, but got %d instead" % (
        expected, actual)

    json1 = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'alpha': 'ALPHA',
    })
    expected = True
    actual = thr.understandsRefusal(json1)
    assert expected == actual, "understand refusal expected %d, but got %d instead" % (
        expected, actual)

    expected = cstore.LegacyThrottler.ACCEPT
    actual = thr.throttle(json1)
    assert expected == actual, "regexp throttle expected %d, but got %d instead" % (
        expected, actual)

    json1 = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.4',
        'alpha': 'not correct',
    })
    expected = cstore.LegacyThrottler.DEFER
    actual = thr.throttle(json1)
    assert expected == actual, "regexp throttle expected %d, but got %d instead" % (
        expected, actual)

    json1 = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'alpha': 'not correct',
    })
    expected = cstore.LegacyThrottler.DISCARD
    actual = thr.throttle(json1)
    assert expected == actual, "regexp throttle expected %d, but got %d instead" % (
        expected, actual)

    json1 = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'beta': 'BETA',
    })
    expected = cstore.LegacyThrottler.ACCEPT
    actual = thr.throttle(json1)
    assert expected == actual, "string equality throttle expected %d, but got %d instead" % (
        expected, actual)

    json1 = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'beta': 'not BETA',
    })
    expected = cstore.LegacyThrottler.DISCARD
    actual = thr.throttle(json1)
    assert expected == actual, "string equality throttle expected %d, but got %d instead" % (
        expected, actual)

    json1 = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'gamma': 'GAMMA',
    })
    expected = cstore.LegacyThrottler.ACCEPT
    actual = thr.throttle(json1)
    assert expected == actual, "string equality throttle expected %d, but got %d instead" % (
        expected, actual)

    json1 = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'gamma': 'not GAMMA',
    })
    expected = cstore.LegacyThrottler.DISCARD
    actual = thr.throttle(json1)
    assert expected == actual, "string equality throttle expected %d, but got %d instead" % (
        expected, actual)

    json1 = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'delta': "value doesn't matter",
    })
    expected = cstore.LegacyThrottler.ACCEPT
    actual = thr.throttle(json1)
    assert expected == actual, "string equality throttle expected %d, but got %d instead" % (
        expected, actual)
    # phase 2 tests

    config = util.DotDict()
    config.throttleConditions = [
        ('*', lambda x: 'alpha' in x, None),
        ('*', lambda x: x['beta'] == 'BETA', 100),
    ]
    config.minimalVersionForUnderstandingRefusal = {
        'product1': '3.5',
        'product2': '4.0'
    }
    config.neverDiscard = True
    config.logger = mock.Mock()
    thr = cstore.LegacyThrottler(config)
    expected = 2
    actual = len(thr.processedThrottleConditions)
    assert expected == actual, \
      "expected thr.preprocessThrottleConditions to have length %d, but got " \
      "%d instead" % (expected, actual)

    raw_crash = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'beta': 'ugh',
        'alpha': "value doesn't matter",
    })
    expected = cstore.LegacyThrottler.IGNORE
    actual = thr.throttle(raw_crash)
    assert expected == actual, \
      "IGNORE expected %d, but got %d instead" % \
      (expected, actual)

    raw_crash = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'beta': 'ugh',
        'delta': "value doesn't matter",
    })
    expected = cstore.LegacyThrottler.DEFER
    actual = thr.throttle(raw_crash)
    assert expected == actual, \
      "DEFER expected %d, but got %d instead" % \
      (expected, actual)

    raw_crash = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'beta': 'BETA',
        'alpha': "value doesn't matter",
    })
    expected = cstore.LegacyThrottler.IGNORE
    actual = thr.throttle(raw_crash)
    assert expected == actual, \
      "IGNORE expected %d, but got %d instead" % \
      (expected, actual)
    raw_crash = util.DotDict({
        'ProductName': 'product1',
        'Version': '3.6',
        'beta': 'BETA',
        'delta': "value doesn't matter",
    })
    expected = cstore.LegacyThrottler.ACCEPT
    actual = thr.throttle(raw_crash)
    assert expected == actual, \
      "ACCEPT expected %d, but got %d instead" % \
      (expected, actual)
コード例 #3
0
ファイル: collector.py プロジェクト: snorp/socorro
syslog.setLevel(config.syslogErrorLoggingLevel)
syslogFormatter = logging.Formatter(config.syslogLineFormatString)
syslog.setFormatter(syslogFormatter)
logger.addHandler(syslog)

sutil.echoConfig(logger, config)

config.logger = logger

#-------------------------------------------------------------------------------
import socorro.storage.crashstorage as cstore
crashStoragePool = cstore.CrashStoragePool(config,
                                    config.primaryStorageClass)
config.crashStoragePool = crashStoragePool

legacyThrottler = cstore.LegacyThrottler(config)
config.legacyThrottler = legacyThrottler

#-------------------------------------------------------------------------------
web.webapi.internalerror = web.debugerror
web.config.debug = False
servicesList = (wscol.Collector,
               )
urls = tuple(y for aTuple in ((x.uri, cpart.class_with_partial_init(x, config))
                    for x in servicesList) for y in aTuple)
logger.info(str(urls))

if config.modwsgiInstallation:
    logger.info('This is a mod_wsgi installation')
    application = web.application(urls, globals()).wsgifunc()
else: