Skip to content

feat(quotas): Separate processing and indexing quotas - #1537

Merged
jan-auer merged 9 commits into
masterfrom
feat/indexed-transactions-limiting
Oct 27, 2022
Merged

jan-auer merged 9 commits into
masterfrom
feat/indexed-transactions-limiting

Conversation

@jan-auer

@jan-auer jan-auer commented Oct 20, 2022 •

Copy link
Copy Markdown
Member

Once metrics have been extracted, transaction events need to have the
new DataCategory::TransactionIndexed quota available to ingest and
store the payload.

The new indexing quota replaces the previous DataCategory::Transaction
for transaction payloads. Transaction quotas now cover all ingested
transactions that have metrics extracted. Transaction quota however is
only counted in the metrics part and not in event ingestion.

Background

Rate limiting and quota enforcement has to apply to legacy plans that
did not have processed transaction functionality, and to new plans
that introduce them.

Organization on Legacy Plan

There is a single quota for total transactions. We need to extract
metrics for indexed transactions so that there is backfilled history at
the time the customer switches to the new plan. This requires to extract
metrics for all accepted transactions.

Organization on New Plan

This plan has a dedicated additional quota for indexed transactions.

  • Validation and inbound data filters do not consume any quota.
    There are no metrics extracted for such dropped events.
  • If there is transaction quota available, extract and ingest metrics for
    this transaction. Otherwise, drop the transaction event and any
    transaction metrics bucket.
  • Dynamic sampling may drop (previously processed) transaction events.
    Extracted metrics and the transaction quotas are not
    impacted by this.
  • If there is additional indexing quota available, store the
    sampled transaction event payload. Otherwise, drop the transaction event.

Algorithm

Flow:

  1. Check if metrics transaction is enabled.
    1. If disabled, rate limit the transaction item with the transaction data category and exit.
    2. Otherwise, continue with step 2.
  2. Check for transaction quota but do not increment it.
    1. If quota is exceeded, drop the item and all metrics.
    2. Otherwise, continue with step 3.
  3. Check if metrics have been extracted for this transaction yet.
    1. If not, skip to step X
    2. Otherwise, keep the item. Metrics can be extracted now.
  4. Metrics have been extracted. Check for indexing quota.
    1. If quota is exceeded, drop the item but keep metrics.
    2. Otherwise, keep the item. The transaction should be stored.

Transaction quota is incremented by the extracted metrics.

References

@jan-auer jan-auer self-assigned this Oct 20, 2022
@jan-auer
jan-auer marked this pull request as ready for review October 21, 2022 10:05
@jan-auer
jan-auer requested a review from a team October 21, 2022 10:05
Comment thread relay-server/src/utils/rate_limits.rs Resolved
Comment thread relay-server/src/utils/rate_limits.rs Resolved
Comment thread relay-server/src/utils/rate_limits.rs Resolved
Comment thread relay-server/src/utils/rate_limits.rs Resolved
Comment thread relay-cabi/include/relay.h Resolved
Comment thread relay-common/src/constants.rs Resolved
Comment thread relay-server/src/utils/rate_limits.rs Resolved
Comment thread relay-server/src/utils/rate_limits.rs Resolved
Comment thread relay-server/src/utils/rate_limits.rs Resolved
Comment thread relay-server/src/utils/rate_limits.rs Resolved
let mut mock = MockLimiter::default().deny(DataCategory::Transaction);
let limiter = EnvelopeLimiter::new(Some(&config), |s, q| mock.check(s, q));

let (enforcement, _limits) = limiter.enforce(&mut envelope, &scoping()).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we check the limits in this test and in the one below?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is mostly about asserting correct calls to the inner rate limiter and there are already tests that then check the response behavior. We can keep this test to a single concern with fewer assertions.

Comment thread tests/integration/test_store.py Resolved
Comment thread tests/integration/test_store.py Resolved
@jan-auer
jan-auer force-pushed the feat/indexed-transactions-limiting branch from 3f2ef61 to 14810e9 Compare October 24, 2022 09:54

@olksdr olksdr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still lgtm

### Background

In #1515 we implemented rate
limiting functionality for metrics buckets, which are applied after
flushing them from the metrics aggregator by checking redis.

### This PR

When a quota is already exhausted, and that information has already been
cached on the project state, there is no need to go through the
aggregator at all. Instead, we apply the rate limiting logic _before_
sending metrics or buckets into the aggregator.

### Implementation details

The utility type `BucketLimiter` was converted to a generic
`MetricsLimiter<T>`, where `T` can be either `Metric` or `Bucket`.

### Notes

Will be merged into #1537 &
deployed together.
jjbayer and others added 2 commits October 25, 2022 09:59
* master:
  fix(gha): Skip Sentry integration tests on library release builds (#1550)
  ref: Use wildcard re-exports where applicable (#1526)
  ci(gha): Skip Sentry integration tests on library release builds (#1549)
  release: 0.8.15
  fix(py): Respect the renormalize flag (#1548)
  (fix)e2e: Use report self hosted issues env variable (#1539)
  meta(vscode): Enable all features in Rust-Analyzer (#1542)
  release: 0.8.14
  build(craft): Fix manylinux artifact name (#1547)
@jan-auer
jan-auer merged commit a9355f5 into master Oct 27, 2022
@jan-auer
jan-auer deleted the feat/indexed-transactions-limiting branch October 27, 2022 09:14
jan-auer added a commit that referenced this pull request Oct 27, 2022
* master:
  feat(quotas): Separate processing and indexing quotas (#1537)
  feat(replays): Adjust replay parser to be less strict and allow for larger segment-ids (#1551)
  fix(gha): Skip Sentry integration tests on library release builds (#1550)
  ref: Use wildcard re-exports where applicable (#1526)
  ci(gha): Skip Sentry integration tests on library release builds (#1549)
  release: 0.8.15
  fix(py): Respect the renormalize flag (#1548)
  (fix)e2e: Use report self hosted issues env variable (#1539)
  meta(vscode): Enable all features in Rust-Analyzer (#1542)
jan-auer added a commit that referenced this pull request Oct 27, 2022
With #1537 Relay started to under-report outcomes for rate limited
transactions. The root cause is that `Enforcement` was not updated to
emit outcomes for metrics.

This reveals that enforcements for metrics should be recorded only if
metrics have not been extracted from a transaction item yet. In this
case, metrics can still be considered part of the transaction item and
as such an outcome is needed. In contrast, once metrics have been
extracted, responsibility for recording outcomes is moved to the
recipient of metrics.
jan-auer added a commit to getsentry/sentry that referenced this pull request Nov 22, 2022
…#41607)

In #40507 we started to count transaction metrics in the `transaction`
data category and transaction events in the `transaction_indexed` data
category. That PR missed that metrics extraction can be disabled, in
which case the old behavior of counting events as `transaction` should
remain. Relay already implemented this logic since getsentry/relay#1537
based on the metrics extraction flag.

This PR adds a feature check to the
`organizations:transaction-metrics-extraction` feature, which is the
same feature flag used to control Relay's behavior. We also remove the
previously used option to sample a percentage of organizations into
metrics extraction.

The default for this feature remains off (`false`) until metrics
components have been added to all deployment targets including
self-hosted.

Co-authored-by: Matej Minar <[email protected]>
naterator pushed a commit to getsentry/sentry that referenced this pull request Nov 22, 2022
…#41607)

In #40507 we started to count transaction metrics in the `transaction`
data category and transaction events in the `transaction_indexed` data
category. That PR missed that metrics extraction can be disabled, in
which case the old behavior of counting events as `transaction` should
remain. Relay already implemented this logic since getsentry/relay#1537
based on the metrics extraction flag.

This PR adds a feature check to the
`organizations:transaction-metrics-extraction` feature, which is the
same feature flag used to control Relay's behavior. We also remove the
previously used option to sample a percentage of organizations into
metrics extraction.

The default for this feature remains off (`false`) until metrics
components have been added to all deployment targets including
self-hosted.

Co-authored-by: Matej Minar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants