({
baseSampleRate,
searchQuery,
rules = [],
}: DynamicSamplingRulesTableProps)
| 321 | }; |
| 322 | |
| 323 | function DynamicSamplingRulesTable({ |
| 324 | baseSampleRate, |
| 325 | searchQuery, |
| 326 | rules = [], |
| 327 | }: DynamicSamplingRulesTableProps) { |
| 328 | const round = (value: number) => Math.round(value * 10000) / 10000; |
| 329 | |
| 330 | const formatSamplingRateValue = (samplingValue: any) => { |
| 331 | if ( |
| 332 | samplingValue.type === 'sampleRate' || |
| 333 | samplingValue.type === 'minimumSampleRate' |
| 334 | ) { |
| 335 | return `${round(samplingValue.value * 100)}%`; |
| 336 | } |
| 337 | return `* ${round(samplingValue.value)}`; |
| 338 | }; |
| 339 | |
| 340 | const evaluateRuleImpact = (rule: RuleV2) => { |
| 341 | if (getRuleType(rule) === RuleType.BOOST_LOW_VOLUME_PROJECTS) { |
| 342 | return 0; |
| 343 | } |
| 344 | if ( |
| 345 | rule.samplingValue.type === 'sampleRate' || |
| 346 | rule.samplingValue.type === 'minimumSampleRate' |
| 347 | ) { |
| 348 | return round(rule.samplingValue.value - baseSampleRate); |
| 349 | } |
| 350 | return round(rule.samplingValue.value - 1); |
| 351 | }; |
| 352 | |
| 353 | const dynamicSamplingRules = rules |
| 354 | .map(rule => { |
| 355 | return { |
| 356 | ...rule, |
| 357 | formattedRateValue: formatSamplingRateValue(rule.samplingValue), |
| 358 | formattedRateType: startCase(rule.samplingValue.type), |
| 359 | type: getRuleType(rule), |
| 360 | target: getStringifiedCondition(rule.condition), |
| 361 | impact: evaluateRuleImpact(rule), |
| 362 | }; |
| 363 | }) |
| 364 | |
| 365 | // eslint-disable-next-line @typescript-eslint/no-base-to-string |
| 366 | .filter(row => Object.values(row).join().toLowerCase().includes(searchQuery)); |
| 367 | |
| 368 | return ( |
| 369 | <Fragment> |
| 370 | <DSRulesTable |
| 371 | headers={['Name', 'Type', 'Value', 'Target']} |
| 372 | isEmpty={!dynamicSamplingRules.length} |
| 373 | emptyMessage="No dynamic sampling rules to display" |
| 374 | > |
| 375 | {dynamicSamplingRules.map(row => ( |
| 376 | <Fragment key={row.id}> |
| 377 | <Stack gap="xs"> |
| 378 | {row.type} |
| 379 | {defined(row.timeRange) && ( |
| 380 | <div data-test-id="timerange"> |
nothing calls this directly
no test coverage detected