Esempio n. 1
0
    def encode_for_similarity(self):
        for x in ComponentVariant.encode_for_similarity(self):
            yield x

        for value in self.values:
            if not is_default_fingerprint_var(value):
                yield ("fingerprint", "ident-shingle"), [value]
Esempio n. 2
0
 def get_hash(self):
     if not self.component.contributes:
         return None
     final_values = []
     for value in self.values:
         if is_default_fingerprint_var(value):
             final_values.extend(self.component.iter_values())
         else:
             final_values.append(value)
     return hash_from_values(final_values)
Esempio n. 3
0
def expose_fingerprint_dict(values, info=None):
    rv = {
        "values": values,
    }
    if not info:
        return rv

    from sentry.grouping.fingerprinting import Rule

    client_values = info.get("client_fingerprint")
    if client_values and (len(client_values) != 1
                          or not is_default_fingerprint_var(client_values[0])):
        rv["client_values"] = client_values
    matched_rule = info.get("matched_rule")
    if matched_rule:
        rule = Rule.from_json(matched_rule)
        rv["matched_rule"] = rule.text

    return rv
Esempio n. 4
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 is_default_fingerprint_var(d) else 0 for d in 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)

    # 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 six.iteritems(components):
            component.update(
                contributes=False,
                contributes_to_similarity=True,
                hint="custom fingerprint takes precedence",
            )
            rv[key] = ComponentVariant(component, config)

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

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

    # Otherwise we need to salt each of the components.
    else:
        rv = {}
        fingerprint = resolve_fingerprint_values(fingerprint, event.data)
        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