organizationRateLimits.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import {css} from '@emotion/react';
  2. import FieldGroup from 'sentry/components/forms/fieldGroup';
  3. import RangeField from 'sentry/components/forms/fields/rangeField';
  4. import Form from 'sentry/components/forms/form';
  5. import Panel from 'sentry/components/panels/panel';
  6. import PanelAlert from 'sentry/components/panels/panelAlert';
  7. import PanelBody from 'sentry/components/panels/panelBody';
  8. import PanelHeader from 'sentry/components/panels/panelHeader';
  9. import {t, tct} from 'sentry/locale';
  10. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  11. import type {Organization} from 'sentry/types/organization';
  12. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  13. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  14. export type OrganizationRateLimitProps = RouteComponentProps<{}, {}> & {
  15. organization: Organization;
  16. };
  17. const getRateLimitValues = () => {
  18. const steps: number[] = [];
  19. let i = 0;
  20. while (i <= 1_000_000) {
  21. steps.push(i);
  22. if (i < 10_000) {
  23. i += 1_000;
  24. } else if (i < 100_000) {
  25. i += 10_000;
  26. } else {
  27. i += 100_000;
  28. }
  29. }
  30. return steps;
  31. };
  32. // We can just generate this once
  33. const ACCOUNT_RATE_LIMIT_VALUES = getRateLimitValues();
  34. function OrganizationRateLimit({organization}: OrganizationRateLimitProps) {
  35. // TODO(billy): Update organization.quota in organizationStore with new values
  36. const {quota} = organization;
  37. const {maxRate, maxRateInterval, projectLimit, accountLimit} = quota;
  38. const initialData = {
  39. projectRateLimit: projectLimit || 100,
  40. accountRateLimit: accountLimit,
  41. };
  42. return (
  43. <div>
  44. <SettingsPageHeader title={t('Rate Limits')} />
  45. <Panel>
  46. <PanelHeader>{t('Adjust Limits')}</PanelHeader>
  47. <PanelBody>
  48. <PanelAlert type="info">
  49. {t(`Rate limits allow you to control how much data is stored for this
  50. organization. When a rate is exceeded the system will begin discarding
  51. data until the next interval.`)}
  52. </PanelAlert>
  53. <Form
  54. data-test-id="rate-limit-editor"
  55. saveOnBlur
  56. allowUndo
  57. apiMethod="PUT"
  58. apiEndpoint={`/organizations/${organization.slug}/`}
  59. initialData={initialData}
  60. >
  61. {!maxRate ? (
  62. <RangeField
  63. name="accountRateLimit"
  64. label={t('Account Limit')}
  65. min={0}
  66. max={1000000}
  67. allowedValues={ACCOUNT_RATE_LIMIT_VALUES}
  68. help={t(
  69. 'The maximum number of events to accept across this entire organization.'
  70. )}
  71. placeholder="e.g. 500"
  72. formatLabel={value =>
  73. !value
  74. ? t('No Limit')
  75. : tct('[number] per hour', {
  76. number: value.toLocaleString(),
  77. })
  78. }
  79. />
  80. ) : (
  81. <FieldGroup
  82. label={t('Account Limit')}
  83. help={t(
  84. 'The maximum number of events to accept across this entire organization.'
  85. )}
  86. >
  87. <TextBlock
  88. css={css`
  89. margin-bottom: 0;
  90. `}
  91. >
  92. {tct(
  93. 'Your account is limited to a maximum of [maxRate] events per [maxRateInterval] seconds.',
  94. {
  95. maxRate,
  96. maxRateInterval,
  97. }
  98. )}
  99. </TextBlock>
  100. </FieldGroup>
  101. )}
  102. <RangeField
  103. name="projectRateLimit"
  104. label={t('Per-Project Limit')}
  105. help={t(
  106. 'The maximum percentage of the account limit (set above) that an individual project can consume.'
  107. )}
  108. step={5}
  109. min={50}
  110. max={100}
  111. formatLabel={value =>
  112. value !== 100 ? `${value}%` : t('No Limit \u2014 100%')
  113. }
  114. />
  115. </Form>
  116. </PanelBody>
  117. </Panel>
  118. </div>
  119. );
  120. }
  121. export default OrganizationRateLimit;