options.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. import keyBy from 'lodash/keyBy';
  2. import {
  3. BooleanField,
  4. EmailField,
  5. NumberField,
  6. RadioField,
  7. TextField,
  8. } from 'sentry/components/forms';
  9. import ExternalLink from 'sentry/components/links/externalLink';
  10. import {t, tct} from 'sentry/locale';
  11. import ConfigStore from 'sentry/stores/configStore';
  12. type Section = {
  13. key: string;
  14. heading?: string;
  15. };
  16. // TODO(epurkhiser): This should really use the types from the form system, but
  17. // they're still pretty bad so that's difficult I guess?
  18. type Field = {
  19. key: string;
  20. label: React.ReactNode;
  21. allowEmpty?: boolean;
  22. choices?: [value: string, label: string][];
  23. component?: React.ComponentType<any>;
  24. defaultValue?: () => string | number | false;
  25. disabled?: boolean;
  26. disabledReason?: string;
  27. help?: React.ReactNode;
  28. max?: number;
  29. min?: number;
  30. placeholder?: string;
  31. required?: boolean;
  32. step?: number;
  33. };
  34. // This are ordered based on their display order visually
  35. const sections: Section[] = [
  36. {
  37. key: 'system',
  38. },
  39. {
  40. key: 'mail',
  41. heading: t('Outbound email'),
  42. },
  43. {
  44. key: 'auth',
  45. heading: t('Authentication'),
  46. },
  47. {
  48. key: 'beacon',
  49. heading: t('Beacon'),
  50. },
  51. ];
  52. const HIGH_THROUGHPUT_RATE_OPTION = {
  53. defaultValue: () => '0',
  54. component: NumberField,
  55. min: 0.0,
  56. max: 1.0,
  57. step: 0.0001,
  58. };
  59. const performanceOptionDefinitions: Field[] = [
  60. {
  61. key: 'performance.issues.all.problem-detection',
  62. label: t('Performance problem detection rate'),
  63. help: t(
  64. 'Controls the rate at which performance problems are detected across the entire system. A value of 0 will disable performance issue detection, and a value of 1.0 turns on detection for every ingested transaction.'
  65. ),
  66. ...HIGH_THROUGHPUT_RATE_OPTION,
  67. },
  68. {
  69. key: 'performance.issues.all.problem-creation',
  70. label: t('Performance problem creation rate'),
  71. help: t(
  72. 'Controls the rate at which performance issues are created across the entire system. A value of 0 will disable performance issue detection, and a value of 1.0 turns on creation for every detected performance problem.'
  73. ),
  74. ...HIGH_THROUGHPUT_RATE_OPTION,
  75. },
  76. {
  77. key: 'performance.issues.all.early-adopter-rollout',
  78. label: t('Performance issues creation EA Rollout'),
  79. help: t(
  80. 'Controls the rate at which performance issues are created for EA organizations.'
  81. ),
  82. ...HIGH_THROUGHPUT_RATE_OPTION,
  83. },
  84. {
  85. key: 'performance.issues.all.general-availability-rollout',
  86. label: t('Performance issues creation GA Rollout'),
  87. help: t(
  88. 'Controls the rate at which performance issues are created for all organizations.'
  89. ),
  90. ...HIGH_THROUGHPUT_RATE_OPTION,
  91. },
  92. {
  93. key: 'performance.issues.all.post-process-group-early-adopter-rollout',
  94. label: t('Performance issues post process group EA Rollout'),
  95. help: t(
  96. 'Controls the rate at which performance issues sent through post process group for EA organizations.'
  97. ),
  98. ...HIGH_THROUGHPUT_RATE_OPTION,
  99. },
  100. {
  101. key: 'performance.issues.all.post-process-group-ga-rollout',
  102. label: t('Performance issues post process group GA Rollout'),
  103. help: t(
  104. 'Controls the rate at which performance issues sent through post process group for all organizations.'
  105. ),
  106. ...HIGH_THROUGHPUT_RATE_OPTION,
  107. },
  108. {
  109. key: 'performance.issues.n_plus_one.problem-detection',
  110. label: t('N+1 detection rate'),
  111. help: t(
  112. 'Controls the rate at which performance problems are detected specifically for N+1 detection. Value of 0 will disable detection, a value of 1.0 fully enables it.'
  113. ),
  114. ...HIGH_THROUGHPUT_RATE_OPTION,
  115. },
  116. {
  117. key: 'performance.issues.n_plus_one.problem-creation',
  118. label: t('N+1 creation rate'),
  119. help: t(
  120. 'Controls the rate at which performance issues are created specifically for N+1 detection. Value of 0 will disable creation, a value of 1.0 fully enables it.'
  121. ),
  122. ...HIGH_THROUGHPUT_RATE_OPTION,
  123. },
  124. {
  125. key: 'performance.issues.n_plus_one_db.problem-detection',
  126. label: t('N+1 (DB) detection rate'),
  127. help: t(
  128. 'Controls the rate at which performance problems are detected specifically for N+1 detection. Value of 0 will disable detection, a value of 1.0 fully enables it.'
  129. ),
  130. ...HIGH_THROUGHPUT_RATE_OPTION,
  131. },
  132. {
  133. key: 'performance.issues.n_plus_one_db.problem-creation',
  134. label: t('N+1 (DB) creation rate'),
  135. help: t(
  136. 'Controls the rate at which performance issues are created specifically for N+1 detection. Value of 0 will disable creation, a value of 1.0 fully enables it.'
  137. ),
  138. ...HIGH_THROUGHPUT_RATE_OPTION,
  139. },
  140. {
  141. key: 'performance.issues.n_plus_one_db_ext.problem-creation',
  142. label: t('N+1 (DB) (Extended) creation rate'),
  143. help: t(
  144. 'Controls the rate at which performance issues are created specifically for N+1 detection (extended). Value of 0 will disable creation, a value of 1.0 fully enables it.'
  145. ),
  146. ...HIGH_THROUGHPUT_RATE_OPTION,
  147. },
  148. {
  149. key: 'performance.issues.n_plus_one_db.count_threshold',
  150. label: t('N+1 (DB) count threshold'),
  151. help: t(
  152. 'Detector threshold. Controls the number of spans required to trigger performance issues. This affects all organizations system-wide.'
  153. ),
  154. defaultValue: () => '5',
  155. component: NumberField,
  156. min: 0,
  157. max: Number.MAX_SAFE_INTEGER,
  158. step: 1,
  159. },
  160. {
  161. key: 'performance.issues.n_plus_one_db.duration_threshold', // TODO: For fixing typo later.
  162. label: t('N+1 (DB) duration threshold'),
  163. help: t(
  164. 'Detector threshold. Controls the threshold for the cumulative duration of involved spans required to trigger performance issues. This affects all organizations system-wide.'
  165. ),
  166. defaultValue: () => '100',
  167. component: NumberField,
  168. min: 0,
  169. max: Number.MAX_SAFE_INTEGER,
  170. step: 1,
  171. },
  172. {
  173. key: 'performance.issues.consecutive_db.problem-creation',
  174. label: t('Problem Creation Rate'),
  175. help: t(
  176. 'Controls the overall rate at which performance problems are detected by the Consecutive DB detector.'
  177. ),
  178. ...HIGH_THROUGHPUT_RATE_OPTION,
  179. },
  180. {
  181. key: 'performance.issues.consecutive_db.la-rollout',
  182. label: t('Limited Availability Detection Rate'),
  183. help: t(
  184. 'Controls the rate at which performance problems are detected by the Consecutive DB detector for LA organizations.'
  185. ),
  186. ...HIGH_THROUGHPUT_RATE_OPTION,
  187. },
  188. {
  189. key: 'performance.issues.consecutive_db.ea-rollout',
  190. label: t('Early Adopter Detection Rate'),
  191. help: t(
  192. 'Controls the rate at which performance problems are detected by the Consecutive DB detector for EA organizations.'
  193. ),
  194. ...HIGH_THROUGHPUT_RATE_OPTION,
  195. },
  196. {
  197. key: 'performance.issues.consecutive_db.ga-rollout',
  198. label: t('General Availability Detection Rate'),
  199. help: t(
  200. 'Controls the rate at which performance problems are detected by the Consecutive DB detector for GA organizations.'
  201. ),
  202. ...HIGH_THROUGHPUT_RATE_OPTION,
  203. },
  204. {
  205. key: 'performance.issues.n_plus_one_api_calls.problem-creation',
  206. label: t('Problem Creation Rate'),
  207. help: t(
  208. 'Controls the overall rate at which performance problems are detected by the N+1 API Calls detector.'
  209. ),
  210. ...HIGH_THROUGHPUT_RATE_OPTION,
  211. },
  212. {
  213. key: 'performance.issues.n_plus_one_api_calls.la-rollout',
  214. label: t('Limited Availability Detection Rate'),
  215. help: t(
  216. 'Controls the rate at which performance problems are detected by the N+1 API Calls detector for LA organizations.'
  217. ),
  218. ...HIGH_THROUGHPUT_RATE_OPTION,
  219. },
  220. {
  221. key: 'performance.issues.n_plus_one_api_calls.ea-rollout',
  222. label: t('Early Adopter Detection Rate'),
  223. help: t(
  224. 'Controls the rate at which performance problems are detected by the N+1 API Calls detector for EA organizations.'
  225. ),
  226. ...HIGH_THROUGHPUT_RATE_OPTION,
  227. },
  228. {
  229. key: 'performance.issues.n_plus_one_api_calls.ga-rollout',
  230. label: t('General Availability Detection Rate'),
  231. help: t(
  232. 'Controls the rate at which performance problems are detected by the for N+1 API Calls detector for GA organizations.'
  233. ),
  234. ...HIGH_THROUGHPUT_RATE_OPTION,
  235. },
  236. {
  237. key: 'performance.issues.compressed_assets.problem-creation',
  238. label: t('Problem Creation Rate'),
  239. help: t(
  240. 'Controls the overall rate at which performance problems are detected by the compressed assets detector.'
  241. ),
  242. ...HIGH_THROUGHPUT_RATE_OPTION,
  243. },
  244. {
  245. key: 'performance.issues.compressed_assets.la-rollout',
  246. label: t('Limited Availability Detection Rate'),
  247. help: t(
  248. 'Controls the rate at which performance problems are detected by the compressed assets detector for LA organizations.'
  249. ),
  250. ...HIGH_THROUGHPUT_RATE_OPTION,
  251. },
  252. {
  253. key: 'performance.issues.compressed_assets.ea-rollout',
  254. label: t('Early Adopter Detection Rate'),
  255. help: t(
  256. 'Controls the rate at which performance problems are detected by the compressed assets detector for EA organizations.'
  257. ),
  258. ...HIGH_THROUGHPUT_RATE_OPTION,
  259. },
  260. {
  261. key: 'performance.issues.compressed_assets.ga-rollout',
  262. label: t('General Availability Detection Rate'),
  263. help: t(
  264. 'Controls the rate at which performance problems are detected by the compressed assets detector for GA organizations.'
  265. ),
  266. ...HIGH_THROUGHPUT_RATE_OPTION,
  267. },
  268. {
  269. key: 'performance.issues.file_io_main_thread.problem-creation',
  270. label: t('File IO Problem Creation Rate'),
  271. help: t(
  272. 'Controls the overall rate at which performance problems are detected by the File IO Detector'
  273. ),
  274. ...HIGH_THROUGHPUT_RATE_OPTION,
  275. },
  276. {
  277. key: 'performance.issues.slow_db_query.problem-creation',
  278. label: t('Problem Creation Rate'),
  279. help: t(
  280. 'Controls the overall rate at which performance problems are detected by the slow DB span detector.'
  281. ),
  282. ...HIGH_THROUGHPUT_RATE_OPTION,
  283. },
  284. {
  285. key: 'performance.issues.slow_db_query.la-rollout',
  286. label: t('Limited Availability Detection Rate'),
  287. help: t(
  288. 'Controls the rate at which performance problems are detected by the slow DB span detector for LA organizations.'
  289. ),
  290. ...HIGH_THROUGHPUT_RATE_OPTION,
  291. },
  292. {
  293. key: 'performance.issues.slow_db_query.ea-rollout',
  294. label: t('Early Adopter Detection Rate'),
  295. help: t(
  296. 'Controls the rate at which performance problems are detected by the slow DB span detector for EA organizations.'
  297. ),
  298. ...HIGH_THROUGHPUT_RATE_OPTION,
  299. },
  300. {
  301. key: 'performance.issues.slow_db_query.ga-rollout',
  302. label: t('General Availability Detection Rate'),
  303. help: t(
  304. 'Controls the rate at which performance problems are detected by the slow DB span detector for GA organizations.'
  305. ),
  306. ...HIGH_THROUGHPUT_RATE_OPTION,
  307. },
  308. ];
  309. // This are ordered based on their display order visually
  310. const definitions: Field[] = [
  311. {
  312. key: 'system.url-prefix',
  313. label: t('Root URL'),
  314. placeholder: 'https://sentry.example.com',
  315. help: t('The root web address which is used to communicate with the Sentry backend.'),
  316. defaultValue: () => `${document.location.protocol}//${document.location.host}`,
  317. },
  318. {
  319. key: 'system.admin-email',
  320. label: t('Admin Email'),
  321. placeholder: 'admin@example.com',
  322. help: t('The technical contact for this Sentry installation.'),
  323. // TODO(dcramer): this should not be hardcoded to a component
  324. component: EmailField,
  325. defaultValue: () => ConfigStore.get('user').email,
  326. },
  327. {
  328. key: 'system.support-email',
  329. label: t('Support Email'),
  330. placeholder: 'support@example.com',
  331. help: t('The support contact for this Sentry installation.'),
  332. // TODO(dcramer): this should not be hardcoded to a component
  333. component: EmailField,
  334. defaultValue: () => ConfigStore.get('user').email,
  335. },
  336. {
  337. key: 'system.security-email',
  338. label: t('Security Email'),
  339. placeholder: 'security@example.com',
  340. help: t('The security contact for this Sentry installation.'),
  341. // TODO(dcramer): this should not be hardcoded to a component
  342. component: EmailField,
  343. defaultValue: () => ConfigStore.get('user').email,
  344. },
  345. {
  346. key: 'system.rate-limit',
  347. label: t('Rate Limit'),
  348. placeholder: 'e.g. 500',
  349. help: t(
  350. 'The maximum number of events the system should accept per minute. A value of 0 will disable the default rate limit.'
  351. ),
  352. },
  353. {
  354. key: 'auth.allow-registration',
  355. label: t('Allow Registration'),
  356. help: t('Allow anyone to create an account and access this Sentry installation.'),
  357. component: BooleanField,
  358. defaultValue: () => false,
  359. },
  360. {
  361. key: 'auth.ip-rate-limit',
  362. label: t('IP Rate Limit'),
  363. placeholder: 'e.g. 10',
  364. help: t(
  365. 'The maximum number of times an authentication attempt may be made by a single IP address in a 60 second window.'
  366. ),
  367. },
  368. {
  369. key: 'auth.user-rate-limit',
  370. label: t('User Rate Limit'),
  371. placeholder: 'e.g. 10',
  372. help: t(
  373. 'The maximum number of times an authentication attempt may be made against a single account in a 60 second window.'
  374. ),
  375. },
  376. {
  377. key: 'api.rate-limit.org-create',
  378. label: 'Organization Creation Rate Limit',
  379. placeholder: 'e.g. 5',
  380. help: t(
  381. 'The maximum number of organizations which may be created by a single account in a one hour window.'
  382. ),
  383. },
  384. {
  385. key: 'beacon.anonymous',
  386. label: 'Usage Statistics',
  387. component: RadioField,
  388. // yes and no are inverted here due to the nature of this configuration
  389. choices: [
  390. ['false', 'Send my contact information along with usage statistics'],
  391. ['true', 'Please keep my usage information anonymous'],
  392. ],
  393. help: tct(
  394. 'If enabled, any stats reported to sentry.io will exclude identifying information (such as your administrative email address). By anonymizing your installation the Sentry team will be unable to contact you about security updates. For more information on what data is sent to Sentry, see the [link:documentation]. Note: This is separate from error-reporting for the self-hosted installer. The data reported to the beacon only includes usage stats from your running self-hosted instance.',
  395. {
  396. link: <ExternalLink href="https://develop.sentry.dev/self-hosted/" />,
  397. }
  398. ),
  399. },
  400. {
  401. key: 'mail.from',
  402. label: t('Email From'),
  403. component: EmailField,
  404. defaultValue: () => `sentry@${document.location.hostname}`,
  405. help: t('Email address to be used in From for all outbound email.'),
  406. },
  407. {
  408. key: 'mail.host',
  409. label: t('SMTP Host'),
  410. placeholder: 'localhost',
  411. defaultValue: () => 'localhost',
  412. },
  413. {
  414. key: 'mail.port',
  415. label: t('SMTP Port'),
  416. placeholder: '25',
  417. defaultValue: () => '25',
  418. },
  419. {
  420. key: 'mail.username',
  421. label: t('SMTP Username'),
  422. defaultValue: () => '',
  423. },
  424. {
  425. key: 'mail.password',
  426. label: t('SMTP Password'),
  427. // TODO(mattrobenolt): We don't want to use a real password field unless
  428. // there's a way to reveal it. Without being able to see the password, it's
  429. // impossible to confirm if it's right.
  430. // component: PasswordField,
  431. defaultValue: () => '',
  432. },
  433. {
  434. key: 'mail.use-tls',
  435. label: t('Use STARTTLS? (exclusive with SSL)'),
  436. component: BooleanField,
  437. defaultValue: () => false,
  438. },
  439. {
  440. key: 'mail.use-ssl',
  441. label: t('Use SSL? (exclusive with STARTTLS)'),
  442. component: BooleanField,
  443. defaultValue: () => false,
  444. },
  445. ...performanceOptionDefinitions,
  446. ];
  447. const definitionsMap = keyBy(definitions, def => def.key);
  448. const disabledReasons = {
  449. diskPriority:
  450. 'This setting is defined in config.yml and may not be changed via the web UI.',
  451. smtpDisabled: 'SMTP mail has been disabled, so this option is unavailable',
  452. };
  453. export function getOption(option: string): Field {
  454. return definitionsMap[option];
  455. }
  456. export function getOptionDefault(option: string): string | number | false | undefined {
  457. const meta = getOption(option);
  458. return meta.defaultValue ? meta.defaultValue() : undefined;
  459. }
  460. function optionsForSection(section: Section) {
  461. return definitions.filter(option => option.key.split('.')[0] === section.key);
  462. }
  463. export function getOptionField(option: string, field: Field) {
  464. const meta = {...getOption(option), ...field};
  465. const Field = meta.component || TextField;
  466. return (
  467. <Field
  468. {...meta}
  469. name={option}
  470. key={option}
  471. defaultValue={getOptionDefault(option)}
  472. required={meta.required && !meta.allowEmpty}
  473. disabledReason={meta.disabledReason && disabledReasons[meta.disabledReason]}
  474. />
  475. );
  476. }
  477. function getSectionFieldSet(section: Section, fields: Field[]) {
  478. return (
  479. <fieldset key={section.key}>
  480. {section.heading && <legend>{section.heading}</legend>}
  481. {fields}
  482. </fieldset>
  483. );
  484. }
  485. export function getForm(fieldMap: Record<string, Field>) {
  486. const sets: React.ReactNode[] = [];
  487. for (const section of sections) {
  488. const set: Field[] = [];
  489. for (const option of optionsForSection(section)) {
  490. if (fieldMap[option.key]) {
  491. set.push(fieldMap[option.key]);
  492. }
  493. }
  494. if (set.length) {
  495. sets.push(getSectionFieldSet(section, set));
  496. }
  497. }
  498. return sets;
  499. }