Exemplo n.º 1
0
def tsdb_increments_from_outcome(org_id, project_id, key_id, outcome, reason, category):
    category = category if category is not None else DataCategory.ERROR
    if category not in DataCategory.event_categories():
        return

    if outcome != Outcome.INVALID:
        # This simply preserves old behavior. We never counted invalid events
        # (too large, duplicate, CORS) toward regular `received` counts.
        if project_id is not None:
            yield (tsdb.models.project_total_received, project_id)
        if org_id is not None:
            yield (tsdb.models.organization_total_received, org_id)
        if key_id is not None:
            yield (tsdb.models.key_total_received, key_id)

    if outcome == Outcome.FILTERED:
        if project_id is not None:
            yield (tsdb.models.project_total_blacklisted, project_id)
        if org_id is not None:
            yield (tsdb.models.organization_total_blacklisted, org_id)
        if key_id is not None:
            yield (tsdb.models.key_total_blacklisted, key_id)

    elif outcome == Outcome.RATE_LIMITED:
        if project_id is not None:
            yield (tsdb.models.project_total_rejected, project_id)
        if org_id is not None:
            yield (tsdb.models.organization_total_rejected, org_id)
        if key_id is not None:
            yield (tsdb.models.key_total_rejected, key_id)

    if reason in FILTER_STAT_KEYS_TO_VALUES:
        if project_id is not None:
            yield (FILTER_STAT_KEYS_TO_VALUES[reason], project_id)
Exemplo n.º 2
0
    def get_quotas(self, project, key=None, keys=None):
        if key:
            key.project = project

        results = []

        if not features.has("organizations:releases-v2", project.organization):
            results.append(
                QuotaConfig(
                    limit=0,
                    scope=QuotaScope.ORGANIZATION,
                    categories=[DataCategory.SESSION],
                    reason_code="sessions_unavailable",
                ))

        pquota = self.get_project_quota(project)
        if pquota[0] is not None:
            results.append(
                QuotaConfig(
                    id="p",
                    scope=QuotaScope.PROJECT,
                    scope_id=project.id,
                    categories=DataCategory.event_categories(),
                    limit=pquota[0],
                    window=pquota[1],
                    reason_code="project_quota",
                ))

        oquota = self.get_organization_quota(project.organization)
        if oquota[0] is not None:
            results.append(
                QuotaConfig(
                    id="o",
                    scope=QuotaScope.ORGANIZATION,
                    scope_id=project.organization.id,
                    categories=DataCategory.event_categories(),
                    limit=oquota[0],
                    window=oquota[1],
                    reason_code="org_quota",
                ))

        if key and not keys:
            keys = [key]
        elif not keys:
            keys = []

        for key in keys:
            kquota = self.get_key_quota(key)
            if kquota[0] is not None:
                results.append(
                    QuotaConfig(
                        id="k",
                        scope=QuotaScope.KEY,
                        scope_id=key.id,
                        categories=DataCategory.event_categories(),
                        limit=kquota[0],
                        window=kquota[1],
                        reason_code="key_quota",
                    ))

        return results