adminSettings.tsx 9.7 KB

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