Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metrics): Tag the sample decision on count_per_root_project #1870

Merged
merged 4 commits into from
Feb 23, 2023

Conversation

jan-auer
Copy link
Member

@jan-auer jan-auer commented Feb 22, 2023

Adds a binary decision tag to c:transactions/count_per_root_project. This allows us to query the effective sample rate on projects.

Background

Dynamic sampling is based on a target sample rate, called the organization's "fidelity". On top of that, Sentry computes a set of priorities (formerly called "biases") to increase visibility in under-represented areas. For example, Sentry boosts releases during adoption or small projects.

The priorities currently apply on top of the fidelity rate and increase the sample rate for a subset of transactions. Overall, this increases the effective sample rate applied for a project. The extent of this is not deterministic, as it depends on the match rate of sample rules.

The final goal is to adjust the biases and base sample rate in such a way that the effective sample rate matches the target fidelity.

Follow Up

In Sentry, compute the effective sample rate ($e$) and compare it with the target sample rate ($t$). Use this to apply an adjustment to the base sample rate as: $b = t * t/e$.

Requires getsentry/sentry#45031
Fixes https://github.com/getsentry/team-ingest/issues/16

@jan-auer jan-auer requested a review from a team February 22, 2023 13:40
@jan-auer jan-auer self-assigned this Feb 22, 2023
Comment on lines +437 to +441
let decision = match sampling_result {
SamplingResult::Keep => "keep".to_owned(),
SamplingResult::Drop(_) => "drop".to_owned(),
};
root_counter_tags.insert("decision".to_owned(), decision);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to implement ToString in SamplingResult, and directly sampling_result.to_string()?

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case I would likely not use it, because if we look at SamplingResult in isolation we would also render the rule IDs from Drop (see the Display implementation of MatchedRuleIds).

Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

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

One comment about a test, apart from that this looks good to me!

let result = service.sample_envelope(&mut state);
assert_eq!(result.is_ok(), shouldkeep);

service.compute_sampling_decision(&mut state);
Copy link
Member

Choose a reason for hiding this comment

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

nit: compute_sampling_decision is now a very thin wrapper around should_keep_event(), so we might as well only test should_keep_event() here. Alternatively, if we want to test that sample_envelope() correctly converts a sampling result to a Result<...>, revert to calling sample_envelope() here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good observation. Instead of testing should_keep_event here, we can even remove this test, since there are unit tests for this function already.

I'd probably test an entire process run then, that asserts we wire everything up correctly. Will look into this.

@andriisoldatenko andriisoldatenko self-requested a review February 22, 2023 14:55
@jan-auer
Copy link
Member Author

jan-auer commented Feb 22, 2023

"decision" and "keep" already exist in the indexer. See getsentry/sentry#45031

* master:
  feat(protocol): Add sourcemap debug image type to protocol (#1869)
  ref(statsd): Revert back the adition of metric names as tag on Sentry errors (#1873)
  feat(profiling): Add PHP support (#1871)
  fix(panic): revert sentry-types to 0.20.1 (#1872)
@jan-auer jan-auer merged commit f077e38 into master Feb 23, 2023
@jan-auer jan-auer deleted the feat/tx-counter-decision branch February 23, 2023 09:59
jan-auer added a commit that referenced this pull request Feb 23, 2023
* master:
  feat(metrics): Tag the sample decision on count_per_root_project (#1870)
  feat(protocol): Add sourcemap debug image type to protocol (#1869)
  ref(statsd): Revert back the adition of metric names as tag on Sentry errors (#1873)
  feat(profiling): Add PHP support (#1871)
  fix(panic): revert sentry-types to 0.20.1 (#1872)
  ref(server): Use async/await in all endpoints (#1862)
  ref: Buffer envelopes for broken project states (#1856)
  meta: Remove accidentally added GeoIP file (#1866)
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