adminSettings.tsx 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. 'performance.issues.consecutive_http.lcp_ratio_threshold',
  49. 'performance.issues.consecutive_http.max_duration_between_spans',
  50. 'profile.issues.blocked_main_thread-ingest.la-rollout',
  51. 'profile.issues.blocked_main_thread-ingest.ea-rollout',
  52. 'profile.issues.blocked_main_thread-ingest.ga-rollout',
  53. 'profile.issues.blocked_main_thread-ppg.la-rollout',
  54. 'profile.issues.blocked_main_thread-ppg.ea-rollout',
  55. 'profile.issues.blocked_main_thread-ppg.ga-rollout',
  56. ];
  57. type Field = ReturnType<typeof getOption>;
  58. type FieldDef = {
  59. field: Field;
  60. value: string | undefined;
  61. };
  62. type State = AsyncView['state'] & {
  63. data: Record<string, FieldDef>;
  64. };
  65. export default class AdminSettings extends AsyncView<{}, State> {
  66. get endpoint() {
  67. return '/internal/options/';
  68. }
  69. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  70. return [['data', this.endpoint]];
  71. }
  72. renderBody() {
  73. const {data} = this.state;
  74. const initialData = {};
  75. const fields = {};
  76. for (const key of optionsAvailable) {
  77. // TODO(dcramer): we should not be mutating options
  78. const option = data[key] ?? {field: {}, value: undefined};
  79. if (option.value === undefined || option.value === '') {
  80. const defn = getOption(key);
  81. initialData[key] = defn.defaultValue ? defn.defaultValue() : '';
  82. } else {
  83. initialData[key] = option.value;
  84. }
  85. fields[key] = getOptionField(key, option.field);
  86. }
  87. return (
  88. <div>
  89. <h3>{t('Settings')}</h3>
  90. <Form
  91. apiMethod="PUT"
  92. apiEndpoint={this.endpoint}
  93. initialData={initialData}
  94. saveOnBlur
  95. >
  96. <Panel>
  97. <PanelHeader>General</PanelHeader>
  98. {fields['system.url-prefix']}
  99. {fields['system.admin-email']}
  100. {fields['system.support-email']}
  101. {fields['system.security-email']}
  102. {fields['system.rate-limit']}
  103. </Panel>
  104. <Panel>
  105. <PanelHeader>Security & Abuse</PanelHeader>
  106. {fields['auth.allow-registration']}
  107. {fields['auth.ip-rate-limit']}
  108. {fields['auth.user-rate-limit']}
  109. {fields['api.rate-limit.org-create']}
  110. </Panel>
  111. <Panel>
  112. <PanelHeader>Beacon</PanelHeader>
  113. {fields['beacon.anonymous']}
  114. </Panel>
  115. <Feature features={['organizations:performance-issues-dev']}>
  116. <Panel>
  117. <PanelHeader>Performance Issues - All</PanelHeader>
  118. {fields['performance.issues.all.problem-detection']}
  119. </Panel>
  120. <Panel>
  121. <PanelHeader>Performance Issues - Detectors</PanelHeader>
  122. {fields['performance.issues.n_plus_one_db.problem-creation']}
  123. {fields['performance.issues.n_plus_one_db_ext.problem-creation']}
  124. {fields['performance.issues.n_plus_one_db.count_threshold']}
  125. {fields['performance.issues.n_plus_one_db.duration_threshold']}
  126. </Panel>
  127. <Panel>
  128. <PanelHeader>Performance Issues - Consecutive DB Detector</PanelHeader>
  129. {fields['performance.issues.consecutive_db.problem-creation']}
  130. {fields['performance.issues.consecutive_db.la-rollout']}
  131. {fields['performance.issues.consecutive_db.ea-rollout']}
  132. {fields['performance.issues.consecutive_db.ga-rollout']}
  133. </Panel>
  134. <Panel>
  135. <PanelHeader>Performance Issues - N+1 API Calls Detector</PanelHeader>
  136. {fields['performance.issues.n_plus_one_api_calls.problem-creation']}
  137. {fields['performance.issues.n_plus_one_api_calls.la-rollout']}
  138. {fields['performance.issues.n_plus_one_api_calls.ea-rollout']}
  139. {fields['performance.issues.n_plus_one_api_calls.ga-rollout']}
  140. </Panel>
  141. <Panel>
  142. <PanelHeader>Performance Issues - Compressed Assets Detector</PanelHeader>
  143. {fields['performance.issues.compressed_assets.problem-creation']}
  144. {fields['performance.issues.compressed_assets.la-rollout']}
  145. {fields['performance.issues.compressed_assets.ea-rollout']}
  146. {fields['performance.issues.compressed_assets.ga-rollout']}
  147. </Panel>
  148. <Panel>
  149. <PanelHeader>Performance Issues - File IO on Main Thread</PanelHeader>
  150. {fields['performance.issues.file_io_main_thread.problem-creation']}
  151. </Panel>
  152. <Panel>
  153. <PanelHeader>Performance Issues - Slow DB Span Detector</PanelHeader>
  154. {fields['performance.issues.slow_db_query.problem-creation']}
  155. {fields['performance.issues.slow_db_query.la-rollout']}
  156. {fields['performance.issues.slow_db_query.ea-rollout']}
  157. {fields['performance.issues.slow_db_query.ga-rollout']}
  158. </Panel>
  159. <Panel>
  160. <PanelHeader>
  161. Performance Issues - Large Render Blocking Asset Detector
  162. </PanelHeader>
  163. {fields['performance.issues.render_blocking_assets.problem-creation']}
  164. {fields['performance.issues.render_blocking_assets.la-rollout']}
  165. {fields['performance.issues.render_blocking_assets.ea-rollout']}
  166. {fields['performance.issues.render_blocking_assets.ga-rollout']}
  167. </Panel>
  168. <Panel>
  169. <PanelHeader>Performance Issues - MN+1 DB Detector</PanelHeader>
  170. {fields['performance.issues.m_n_plus_one_db.problem-creation']}
  171. {fields['performance.issues.m_n_plus_one_db.la-rollout']}
  172. {fields['performance.issues.m_n_plus_one_db.ea-rollout']}
  173. {fields['performance.issues.m_n_plus_one_db.ga-rollout']}
  174. </Panel>
  175. <Panel>
  176. <PanelHeader>
  177. Performance Issues - Consecutive HTTP Span Detector
  178. </PanelHeader>
  179. {fields['performance.issues.consecutive_http.lcp_ratio_threshold']}
  180. {fields['performance.issues.consecutive_http.max_duration_between_spans']}
  181. </Panel>
  182. <Panel>
  183. <PanelHeader>
  184. Profiling Issues - Block Main Thread Detector Ingest
  185. </PanelHeader>
  186. {fields['profile.issues.blocked_main_thread-ingest.la-rollout']}
  187. {fields['profile.issues.blocked_main_thread-ingest.ea-rollout']}
  188. {fields['profile.issues.blocked_main_thread-ingest.ga-rollout']}
  189. </Panel>
  190. <Panel>
  191. <PanelHeader>
  192. Profiling Issues - Block Main Thread Detector Post Process Group
  193. </PanelHeader>
  194. {fields['profile.issues.blocked_main_thread-ppg.la-rollout']}
  195. {fields['profile.issues.blocked_main_thread-ppg.ea-rollout']}
  196. {fields['profile.issues.blocked_main_thread-ppg.ga-rollout']}
  197. </Panel>
  198. </Feature>
  199. <Feature features={['organizations:view-hierarchies-options-dev']}>
  200. <Panel>
  201. <PanelHeader>View Hierarchy</PanelHeader>
  202. </Panel>
  203. </Feature>
  204. </Form>
  205. </div>
  206. );
  207. }
  208. }