Пример #1
0
def get_grouping_variants_for_event(event, config=None):
    """Returns a dict of all grouping variants for this event."""
    # If a checksum is set the only variant that comes back from this
    # event is the checksum variant.
    checksum = event.data.get("checksum")
    if checksum:
        if HASH_RE.match(checksum):
            return {"checksum": ChecksumVariant(checksum)}

        rv = {
            "hashed-checksum": ChecksumVariant(hash_from_values(checksum), hashed=True),
        }

        # The legacy code path also supported arbitrary values here but
        # it will blow up if it results in more than 32 bytes of data
        # as this cannot be inserted into the database.  (See GroupHash.hash)
        if len(checksum) <= 32:
            rv["checksum"] = ChecksumVariant(checksum)

        return rv

    # Otherwise we go to the various forms of fingerprint handling.
    fingerprint = event.data.get("fingerprint") or ["{{ default }}"]
    defaults_referenced = sum(1 if d in DEFAULT_FINGERPRINT_VALUES else 0 for d in fingerprint)

    # If no defaults are referenced we produce a single completely custom
    # fingerprint.
    if defaults_referenced == 0:
        fingerprint = resolve_fingerprint_values(fingerprint, event)
        return {"custom-fingerprint": CustomFingerprintVariant(fingerprint)}

    if config is None:
        config = load_default_grouping_config()

    # At this point we need to calculate the default event values.  If the
    # fingerprint is salted we will wrap it.
    components = _get_calculated_grouping_variants_for_event(event, config)
    rv = {}

    # If the fingerprints are unsalted, we can return them right away.
    if defaults_referenced == 1 and len(fingerprint) == 1:
        for (key, component) in six.iteritems(components):
            rv[key] = ComponentVariant(component, config)

    # Otherwise we need to salt each of the components.
    else:
        fingerprint = resolve_fingerprint_values(fingerprint, event)
        for (key, component) in six.iteritems(components):
            rv[key] = SaltedComponentVariant(fingerprint, component, config)

    # Ensure we have a fallback hash if nothing else works out
    if not any(x.contributes for x in six.itervalues(rv)):
        rv["fallback"] = FallbackVariant()

    return rv
Пример #2
0
def get_grouping_variants_for_event(event, config=None):
    """Returns a dict of all grouping variants for this event."""
    # If a checksum is set the only variant that comes back from this
    # event is the checksum variant.
    checksum = event.data.get('checksum')
    if checksum:
        if HASH_RE.match(checksum):
            return {
                'checksum': ChecksumVariant(checksum),
            }
        return {
            'checksum':
            ChecksumVariant(checksum),
            'hashed-checksum':
            ChecksumVariant(hash_from_values(checksum), hashed=True),
        }

    # Otherwise we go to the various forms of fingerprint handling.
    fingerprint = event.data.get('fingerprint') or ['{{ default }}']
    defaults_referenced = sum(1 if d in DEFAULT_FINGERPRINT_VALUES else 0
                              for d in fingerprint)

    # If no defaults are referenced we produce a single completely custom
    # fingerprint.
    if defaults_referenced == 0:
        fingerprint = resolve_fingerprint_values(fingerprint, event)
        return {
            'custom-fingerprint': CustomFingerprintVariant(fingerprint),
        }

    if config is None:
        config = load_default_grouping_config()

    # At this point we need to calculate the default event values.  If the
    # fingerprint is salted we will wrap it.
    components = _get_calculated_grouping_variants_for_event(event, config)
    rv = {}

    # If the fingerprints are unsalted, we can return them right away.
    if defaults_referenced == 1 and len(fingerprint) == 1:
        for (key, component) in six.iteritems(components):
            rv[key] = ComponentVariant(component, config)

    # Otherwise we need to salt each of the components.
    else:
        fingerprint = resolve_fingerprint_values(fingerprint, event)
        for (key, component) in six.iteritems(components):
            rv[key] = SaltedComponentVariant(fingerprint, component, config)

    # Ensure we have a fallback hash if nothing else works out
    if not any(x.contributes for x in six.itervalues(rv)):
        rv['fallback'] = FallbackVariant()

    return rv
Пример #3
0
def get_grouping_variants_for_event(event, config=None):
    """Returns a dict of all grouping variants for this event."""
    # If a checksum is set the only variant that comes back from this
    # event is the checksum variant.
    checksum = event.data.get("checksum")
    if checksum:
        if HASH_RE.match(checksum):
            return {"checksum": ChecksumVariant(checksum)}

        rv = {
            "hashed-checksum": ChecksumVariant(hash_from_values(checksum), hashed=True),
        }

        # The legacy code path also supported arbitrary values here but
        # it will blow up if it results in more than 32 bytes of data
        # as this cannot be inserted into the database.  (See GroupHash.hash)
        if len(checksum) <= 32:
            rv["checksum"] = ChecksumVariant(checksum)

        return rv

    # Otherwise we go to the various forms of fingerprint handling.  If the event carries
    # a materialized fingerprint info from server side fingerprinting we forward it to the
    # variants which can export additional information about them.
    fingerprint = event.data.get("fingerprint") or ["{{ default }}"]
    fingerprint_info = event.data.get("_fingerprint_info")
    defaults_referenced = sum(1 if is_default_fingerprint_var(d) else 0 for d in fingerprint)

    if config is None:
        config = load_default_grouping_config()
    context = GroupingContext(config)

    # At this point we need to calculate the default event values.  If the
    # fingerprint is salted we will wrap it.
    components = _get_calculated_grouping_variants_for_event(event, context)

    # If no defaults are referenced we produce a single completely custom
    # fingerprint and mark all other variants as non-contributing
    if defaults_referenced == 0:
        rv = {}
        for (key, component) in components.items():
            component.update(
                contributes=False,
                contributes_to_similarity=True,
                hint="custom fingerprint takes precedence",
            )
            rv[key] = ComponentVariant(component, context.config)

        fingerprint = resolve_fingerprint_values(fingerprint, event.data)
        rv["custom-fingerprint"] = CustomFingerprintVariant(fingerprint, fingerprint_info)

    # If the fingerprints are unsalted, we can return them right away.
    elif defaults_referenced == 1 and len(fingerprint) == 1:
        rv = {}
        for (key, component) in components.items():
            rv[key] = ComponentVariant(component, context.config)

    # Otherwise we need to salt each of the components.
    else:
        rv = {}
        fingerprint = resolve_fingerprint_values(fingerprint, event.data)
        for (key, component) in components.items():
            rv[key] = SaltedComponentVariant(
                fingerprint, component, context.config, fingerprint_info
            )

    # Ensure we have a fallback hash if nothing else works out
    if not any(x.contributes for x in rv.values()):
        rv["fallback"] = FallbackVariant()

    return rv