Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/sentry/dynamic_sampling/rules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,12 @@ class RuleType(Enum):
REVERSE_RESERVED_IDS = {value: key for key, value in RESERVED_IDS.items()}


SamplingValueType = Literal["sampleRate", "factor", "reservoir", "minimumSampleRate"]
SamplingValueType = Literal["sampleRate", "factor", "minimumSampleRate"]
Comment thread
cursor[bot] marked this conversation as resolved.


# (RaduW) Maybe we can split in two types, one for reservoir and one for sampleRate and factor
# Wanted to do this but couldn't think of three good names for the types (SamplingValue, ReservoirSamplingValue and ?
# some type name for the old SamplingValue type)
Comment thread
cursor[bot] marked this conversation as resolved.
class SamplingValue(TypedDict):
type: SamplingValueType
value: NotRequired[float]
limit: NotRequired[int]
value: float


class TimeRange(TypedDict):
Expand Down
15 changes: 8 additions & 7 deletions static/gsAdmin/views/dynamicSamplingPanel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ describe('Dynamic Sampling Panel', () => {

const rule1 = {
samplingValue: {
type: 'reservoir',
limit: 100,
type: 'minimumSampleRate',
Comment thread
cursor[bot] marked this conversation as resolved.
value: 1,
Comment thread
cursor[bot] marked this conversation as resolved.
},
type: 'transaction',
id: 3005,
Expand All @@ -163,8 +163,8 @@ describe('Dynamic Sampling Panel', () => {

const rule2 = {
samplingValue: {
type: 'reservoir',
limit: 300,
type: 'minimumSampleRate',
value: 0.5,
},
type: 'transaction',
id: 3001,
Expand Down Expand Up @@ -290,8 +290,9 @@ describe('Dynamic Sampling Panel', () => {
expect(timeRanges[0]).toHaveTextContent('Start:Jun 19, 2024 9:03 AM');
expect(timeRanges[0]).toHaveTextContent('End:Jun 21, 2024 9:03 AM');

// Check that the limit is displayed if available
const limits = screen.queryAllByTestId('limit');
expect(limits[0]).toHaveTextContent('Limit:100');
// Check that minimum sample rate values are displayed.
expect(screen.getAllByText('Minimum Sample Rate')).toHaveLength(2);
expect(screen.getByText('50%')).toBeInTheDocument();
expect(screen.getAllByText('100%')).toHaveLength(3);
});
});
22 changes: 6 additions & 16 deletions static/gsAdmin/views/dynamicSamplingPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ type RuleV2 = {
};
id: number;
samplingValue: {
type: 'factor' | 'sampleRate' | 'reservoir';
type: 'factor' | 'sampleRate' | 'minimumSampleRate';
Comment thread
cursor[bot] marked this conversation as resolved.
value: number;
limit?: number;
};
type: 'trace' | 'transaction';
type: 'trace' | 'transaction' | 'project';
Comment on lines +53 to +56
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.

Drive by fix, to add new types which we added to Relay but never to the frontend here

timeRange?: {
end: string;
start: string;
Expand Down Expand Up @@ -335,22 +334,19 @@ function DynamicSamplingRulesTable({
) {
return `${round(samplingValue.value * 100)}%`;
}
if (samplingValue.type === 'reservoir') {
return '100%';
}
return `* ${round(samplingValue.value)}`;
};

const evaluateRuleImpact = (rule: RuleV2) => {
if (getRuleType(rule) === RuleType.BOOST_LOW_VOLUME_PROJECTS) {
return 0;
}
if (rule.samplingValue.type === 'sampleRate') {
if (
rule.samplingValue.type === 'sampleRate' ||
rule.samplingValue.type === 'minimumSampleRate'
) {
return round(rule.samplingValue.value - baseSampleRate);
}
if (rule.samplingValue.type === 'reservoir') {
Comment thread
cursor[bot] marked this conversation as resolved.
return 1;
}
return round(rule.samplingValue.value - 1);
};

Expand Down Expand Up @@ -380,12 +376,6 @@ function DynamicSamplingRulesTable({
<Fragment key={row.id}>
<Stack gap="xs">
{row.type}
{defined(row.samplingValue.limit) && (
<NameColumnDetail data-test-id="limit">
<strong>Limit:</strong>
<span>{row.samplingValue.limit}</span>
</NameColumnDetail>
)}
{defined(row.timeRange) && (
<div data-test-id="timerange">
<NameColumnDetail>
Expand Down
Loading