cardinalityLimit.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import styled from '@emotion/styled';
  2. import Access from 'sentry/components/acl/access';
  3. import NumberField from 'sentry/components/forms/fields/numberField';
  4. import Form from 'sentry/components/forms/form';
  5. import Panel from 'sentry/components/panels/panel';
  6. import PanelBody from 'sentry/components/panels/panelBody';
  7. import PanelHeader from 'sentry/components/panels/panelHeader';
  8. import {t} from 'sentry/locale';
  9. import type {Project} from 'sentry/types/project';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. type Props = {
  12. project: Project;
  13. };
  14. const DEFAULT_LIMIT = '5000';
  15. function transformData(data) {
  16. const limit = data.relayCustomMetricCardinalityLimit;
  17. return {
  18. relayCustomMetricCardinalityLimit:
  19. limit === '' || limit === DEFAULT_LIMIT ? null : limit,
  20. };
  21. }
  22. export function CardinalityLimit({project}: Props) {
  23. const organization = useOrganization();
  24. const endpoint = `/projects/${organization.slug}/${project.slug}/`;
  25. return (
  26. <Form
  27. apiEndpoint={endpoint}
  28. apiMethod="PUT"
  29. saveOnBlur
  30. initialData={{
  31. relayCustomMetricCardinalityLimit:
  32. project.relayCustomMetricCardinalityLimit ?? DEFAULT_LIMIT,
  33. }}
  34. >
  35. <Panel>
  36. <PanelHeader>{t('Limits')}</PanelHeader>
  37. <PanelBody>
  38. <Access access={['project:write']} project={project}>
  39. {({hasAccess}) => (
  40. <StyledNumberField
  41. disabledReason={
  42. !hasAccess
  43. ? t('You do not have permission to edit the cardinality limit')
  44. : undefined
  45. }
  46. disabled={!hasAccess}
  47. name="relayCustomMetricCardinalityLimit"
  48. label={t('Cardinality Limit')}
  49. help={t(
  50. 'The cardinality limit defines the maximum number of unique tag combinations allowed for a metric (measured per hour). If the cardinality limit is exceeded, the metric will be blocked.'
  51. )}
  52. saveOnBlur
  53. placeholder={t('Enter a value')}
  54. flexibleControlStateSize
  55. multiple
  56. getData={transformData}
  57. />
  58. )}
  59. </Access>
  60. </PanelBody>
  61. </Panel>
  62. </Form>
  63. );
  64. }
  65. const StyledNumberField = styled(NumberField)`
  66. ${p => p.disabled && `cursor: not-allowed`}
  67. `;