adminSettings.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import Feature from 'sentry/components/acl/feature';
  2. import {Form} from 'sentry/components/forms';
  3. import {Panel, PanelHeader} from 'sentry/components/panels';
  4. import {t} from 'sentry/locale';
  5. import AsyncView from 'sentry/views/asyncView';
  6. import {getOption, getOptionField} from './options';
  7. const optionsAvailable = [
  8. 'system.url-prefix',
  9. 'system.admin-email',
  10. 'system.support-email',
  11. 'system.security-email',
  12. 'system.rate-limit',
  13. 'auth.allow-registration',
  14. 'auth.ip-rate-limit',
  15. 'auth.user-rate-limit',
  16. 'api.rate-limit.org-create',
  17. 'beacon.anonymous',
  18. 'performance.issues.all.problem-detection',
  19. 'performance.issues.n_plus_one_db.problem-creation',
  20. 'performance.issues.n_plus_one_db_ext.problem-creation',
  21. 'performance.issues.n_plus_one_db.count_threshold',
  22. 'performance.issues.n_plus_one_db.duration_threshold',
  23. 'performance.issues.consecutive_db.problem-creation',
  24. 'performance.issues.consecutive_db.la-rollout',
  25. 'performance.issues.consecutive_db.ea-rollout',
  26. 'performance.issues.consecutive_db.ga-rollout',
  27. 'performance.issues.n_plus_one_api_calls.problem-creation',
  28. 'performance.issues.n_plus_one_api_calls.la-rollout',
  29. 'performance.issues.n_plus_one_api_calls.ea-rollout',
  30. 'performance.issues.n_plus_one_api_calls.ga-rollout',
  31. 'performance.issues.compressed_assets.problem-creation',
  32. 'performance.issues.compressed_assets.la-rollout',
  33. 'performance.issues.compressed_assets.ea-rollout',
  34. 'performance.issues.compressed_assets.ga-rollout',
  35. 'performance.issues.file_io_main_thread.problem-creation',
  36. 'performance.issues.slow_db_query.problem-creation',
  37. 'performance.issues.slow_db_query.la-rollout',
  38. 'performance.issues.slow_db_query.ea-rollout',
  39. 'performance.issues.slow_db_query.ga-rollout',
  40. 'performance.issues.render_blocking_assets.problem-creation',
  41. 'performance.issues.render_blocking_assets.la-rollout',
  42. 'performance.issues.render_blocking_assets.ea-rollout',
  43. 'performance.issues.render_blocking_assets.ga-rollout',
  44. 'performance.issues.m_n_plus_one_db.problem-creation',
  45. 'performance.issues.m_n_plus_one_db.la-rollout',
  46. 'performance.issues.m_n_plus_one_db.ea-rollout',
  47. 'performance.issues.m_n_plus_one_db.ga-rollout',
  48. 'profile.issues.blocked_main_thread-ingest.la-rollout',
  49. 'profile.issues.blocked_main_thread-ingest.ea-rollout',
  50. 'profile.issues.blocked_main_thread-ingest.ga-rollout',
  51. 'processing.view-hierarchies-deobfuscation-general-availability',
  52. ];
  53. type Field = ReturnType<typeof getOption>;
  54. type FieldDef = {
  55. field: Field;
  56. value: string | undefined;
  57. };
  58. type State = AsyncView['state'] & {
  59. data: Record<string, FieldDef>;
  60. };
  61. export default class AdminSettings extends AsyncView<{}, State> {
  62. get endpoint() {
  63. return '/internal/options/';
  64. }
  65. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  66. return [['data', this.endpoint]];
  67. }
  68. renderBody() {
  69. const {data} = this.state;
  70. const initialData = {};
  71. const fields = {};
  72. for (const key of optionsAvailable) {
  73. // TODO(dcramer): we should not be mutating options
  74. const option = data[key] ?? {field: {}, value: undefined};
  75. if (option.value === undefined || option.value === '') {
  76. const defn = getOption(key);
  77. initialData[key] = defn.defaultValue ? defn.defaultValue() : '';
  78. } else {
  79. initialData[key] = option.value;
  80. }
  81. fields[key] = getOptionField(key, option.field);
  82. }
  83. return (
  84. <div>
  85. <h3>{t('Settings')}</h3>
  86. <Form
  87. apiMethod="PUT"
  88. apiEndpoint={this.endpoint}
  89. initialData={initialData}
  90. saveOnBlur
  91. >
  92. <Panel>
  93. <PanelHeader>General</PanelHeader>
  94. {fields['system.url-prefix']}
  95. {fields['system.admin-email']}
  96. {fields['system.support-email']}
  97. {fields['system.security-email']}
  98. {fields['system.rate-limit']}
  99. </Panel>
  100. <Panel>
  101. <PanelHeader>Security & Abuse</PanelHeader>
  102. {fields['auth.allow-registration']}
  103. {fields['auth.ip-rate-limit']}
  104. {fields['auth.user-rate-limit']}
  105. {fields['api.rate-limit.org-create']}
  106. </Panel>
  107. <Panel>
  108. <PanelHeader>Beacon</PanelHeader>
  109. {fields['beacon.anonymous']}
  110. </Panel>
  111. <Feature features={['organizations:performance-issues-dev']}>
  112. <Panel>
  113. <PanelHeader>Performance Issues - All</PanelHeader>
  114. {fields['performance.issues.all.problem-detection']}
  115. </Panel>
  116. <Panel>
  117. <PanelHeader>Performance Issues - Detectors</PanelHeader>
  118. {fields['performance.issues.n_plus_one_db.problem-creation']}
  119. {fields['performance.issues.n_plus_one_db_ext.problem-creation']}
  120. {fields['performance.issues.n_plus_one_db.count_threshold']}
  121. {fields['performance.issues.n_plus_one_db.duration_threshold']}
  122. </Panel>
  123. <Panel>
  124. <PanelHeader>Performance Issues - Consecutive DB Detector</PanelHeader>
  125. {fields['performance.issues.consecutive_db.problem-creation']}
  126. {fields['performance.issues.consecutive_db.la-rollout']}
  127. {fields['performance.issues.consecutive_db.ea-rollout']}
  128. {fields['performance.issues.consecutive_db.ga-rollout']}
  129. </Panel>
  130. <Panel>
  131. <PanelHeader>Performance Issues - N+1 API Calls Detector</PanelHeader>
  132. {fields['performance.issues.n_plus_one_api_calls.problem-creation']}
  133. {fields['performance.issues.n_plus_one_api_calls.la-rollout']}
  134. {fields['performance.issues.n_plus_one_api_calls.ea-rollout']}
  135. {fields['performance.issues.n_plus_one_api_calls.ga-rollout']}
  136. </Panel>
  137. <Panel>
  138. <PanelHeader>Performance Issues - Compressed Assets Detector</PanelHeader>
  139. {fields['performance.issues.compressed_assets.problem-creation']}
  140. {fields['performance.issues.compressed_assets.la-rollout']}
  141. {fields['performance.issues.compressed_assets.ea-rollout']}
  142. {fields['performance.issues.compressed_assets.ga-rollout']}
  143. </Panel>
  144. <Panel>
  145. <PanelHeader>Performance Issues - File IO on Main Thread</PanelHeader>
  146. {fields['performance.issues.file_io_main_thread.problem-creation']}
  147. </Panel>
  148. <Panel>
  149. <PanelHeader>Performance Issues - Slow DB Span Detector</PanelHeader>
  150. {fields['performance.issues.slow_db_query.problem-creation']}
  151. {fields['performance.issues.slow_db_query.la-rollout']}
  152. {fields['performance.issues.slow_db_query.ea-rollout']}
  153. {fields['performance.issues.slow_db_query.ga-rollout']}
  154. </Panel>
  155. <Panel>
  156. <PanelHeader>
  157. Performance Issues - Large Render Blocking Asset Detector
  158. </PanelHeader>
  159. {fields['performance.issues.render_blocking_assets.problem-creation']}
  160. {fields['performance.issues.render_blocking_assets.la-rollout']}
  161. {fields['performance.issues.render_blocking_assets.ea-rollout']}
  162. {fields['performance.issues.render_blocking_assets.ga-rollout']}
  163. </Panel>
  164. <Panel>
  165. <PanelHeader>Performance Issues - MN+1 DB Detector</PanelHeader>
  166. {fields['performance.issues.m_n_plus_one_db.problem-creation']}
  167. {fields['performance.issues.m_n_plus_one_db.la-rollout']}
  168. {fields['performance.issues.m_n_plus_one_db.ea-rollout']}
  169. {fields['performance.issues.m_n_plus_one_db.ga-rollout']}
  170. </Panel>
  171. <Panel>
  172. <PanelHeader>Profiling Issues - Block Main Thread Detector</PanelHeader>
  173. {fields['profile.issues.blocked_main_thread-ingest.la-rollout']}
  174. {fields['profile.issues.blocked_main_thread-ingest.ea-rollout']}
  175. {fields['profile.issues.blocked_main_thread-ingest.ga-rollout']}
  176. </Panel>
  177. </Feature>
  178. </Form>
  179. </div>
  180. );
  181. }
  182. }