adminSettings.tsx 9.8 KB

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