adminEnvironment.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import moment from 'moment';
  4. import {Button} from 'sentry/components/button';
  5. import LoadingError from 'sentry/components/loadingError';
  6. import LoadingIndicator from 'sentry/components/loadingIndicator';
  7. import {IconUpgrade} from 'sentry/icons';
  8. import {t, tct} from 'sentry/locale';
  9. import ConfigStore from 'sentry/stores/configStore';
  10. import {space} from 'sentry/styles/space';
  11. import {useApiQuery} from 'sentry/utils/queryClient';
  12. type Data = {
  13. config: [key: string, value: string][];
  14. environment: {
  15. config: string;
  16. start_date: string;
  17. };
  18. pythonVersion: string;
  19. };
  20. export default function AdminEnvironment() {
  21. const {data, isLoading, isError} = useApiQuery<Data>(['/internal/environment/'], {
  22. staleTime: 0,
  23. });
  24. if (isError) {
  25. return <LoadingError />;
  26. }
  27. if (isLoading) {
  28. return <LoadingIndicator />;
  29. }
  30. const {version} = ConfigStore.getState();
  31. return (
  32. <div>
  33. <h3>{t('Environment')}</h3>
  34. {data?.environment ? (
  35. <dl className="vars">
  36. <VersionLabel>
  37. {t('Server Version')}
  38. {version.upgradeAvailable && (
  39. <Button
  40. href="https://github.com/getsentry/sentry/releases"
  41. icon={<IconUpgrade />}
  42. size="xs"
  43. external
  44. >
  45. {t('Upgrade to Sentry %s', version.latest)}
  46. </Button>
  47. )}
  48. </VersionLabel>
  49. <dd>
  50. <pre className="val">{version.current}</pre>
  51. </dd>
  52. <dt>{t('Python Version')}</dt>
  53. <dd>
  54. <pre className="val">{data?.pythonVersion}</pre>
  55. </dd>
  56. <dt>{t('Configuration File')}</dt>
  57. <dd>
  58. <pre className="val">{data.environment.config}</pre>
  59. </dd>
  60. <dt>{t('Uptime')}</dt>
  61. <dd>
  62. <pre className="val">
  63. {tct('[now] (since [start])', {
  64. now: moment(data.environment.start_date).toNow(true),
  65. start: data.environment.start_date,
  66. })}
  67. </pre>
  68. </dd>
  69. </dl>
  70. ) : (
  71. <p>{t('Environment not found (are you using the builtin Sentry webserver?).')}</p>
  72. )}
  73. <h3>
  74. {tct('Configuration [configPath]', {
  75. configPath: data?.environment.config && (
  76. <small>{data?.environment.config}</small>
  77. ),
  78. })}
  79. </h3>
  80. <dl className="vars">
  81. {data?.config.map(([key, value]) => (
  82. <Fragment key={key}>
  83. <dt>{key}</dt>
  84. <dd>
  85. <pre className="val">{value}</pre>
  86. </dd>
  87. </Fragment>
  88. ))}
  89. </dl>
  90. </div>
  91. );
  92. }
  93. const VersionLabel = styled('dt')`
  94. display: inline-grid;
  95. grid-auto-flow: column;
  96. gap: ${space(1)};
  97. align-items: center;
  98. `;