resourceInfo.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import {Fragment} from 'react';
  2. import Alert from 'sentry/components/alert';
  3. import {t, tct} from 'sentry/locale';
  4. import {formatBytesBase2} from 'sentry/utils/bytes/formatBytesBase2';
  5. import {DurationUnit, SizeUnit} from 'sentry/utils/discover/fields';
  6. import getDynamicText from 'sentry/utils/getDynamicText';
  7. import {RESOURCE_THROUGHPUT_UNIT} from 'sentry/views/insights/browser/resources/settings';
  8. import {MetricReadout} from 'sentry/views/insights/common/components/metricReadout';
  9. import {ReadoutRibbon} from 'sentry/views/insights/common/components/ribbon';
  10. import {getTimeSpentExplanation} from 'sentry/views/insights/common/components/tableCells/timeSpentCell';
  11. import {
  12. DataTitles,
  13. getThroughputTitle,
  14. } from 'sentry/views/insights/common/views/spans/types';
  15. type Props = {
  16. avgContentLength: number;
  17. avgDecodedContentLength: number;
  18. avgDuration: number;
  19. avgTransferSize: number;
  20. isLoading: boolean;
  21. throughput: number;
  22. timeSpentPercentage: number;
  23. timeSpentTotal: number;
  24. };
  25. function ResourceInfo(props: Props) {
  26. const {
  27. isLoading,
  28. avgContentLength,
  29. avgDecodedContentLength,
  30. avgDuration,
  31. avgTransferSize,
  32. throughput,
  33. timeSpentPercentage,
  34. timeSpentTotal,
  35. } = props;
  36. const tooltips = {
  37. avgContentLength: tct(
  38. 'On average, this resource is [bytes] when encoded (for example when gzipped).',
  39. {
  40. bytes: getDynamicText({
  41. value: formatBytesBase2(avgContentLength),
  42. fixed: 'xx KiB',
  43. }),
  44. }
  45. ),
  46. avgDecodedContentLength: tct('On average, this resource is [bytes] when decoded.', {
  47. bytes: getDynamicText({
  48. value: formatBytesBase2(avgDecodedContentLength),
  49. fixed: 'xx KiB',
  50. }),
  51. }),
  52. avgTransferSize: tct(
  53. 'On average, the total bytes transferred over the network (body + headers) for this resource is [bytes].',
  54. {
  55. bytes: getDynamicText({
  56. value: formatBytesBase2(avgTransferSize),
  57. fixed: 'xx KiB',
  58. }),
  59. }
  60. ),
  61. };
  62. const hasNoData =
  63. avgContentLength === 0 && avgDecodedContentLength === 0 && avgTransferSize === 0;
  64. return (
  65. <Fragment>
  66. <ReadoutRibbon>
  67. <MetricReadout
  68. title={getThroughputTitle('resource')}
  69. value={throughput}
  70. unit={RESOURCE_THROUGHPUT_UNIT}
  71. isLoading={isLoading}
  72. />
  73. <MetricReadout
  74. title={DataTitles['avg(http.response_content_length)']}
  75. tooltip={tooltips.avgContentLength}
  76. value={avgContentLength}
  77. unit={SizeUnit.BYTE}
  78. isLoading={isLoading}
  79. />
  80. <MetricReadout
  81. title={DataTitles['avg(http.decoded_response_content_length)']}
  82. value={avgDecodedContentLength}
  83. tooltip={tooltips.avgDecodedContentLength}
  84. unit={SizeUnit.BYTE}
  85. isLoading={isLoading}
  86. />
  87. <MetricReadout
  88. title={DataTitles['avg(http.response_transfer_size)']}
  89. value={avgTransferSize}
  90. tooltip={tooltips.avgTransferSize}
  91. unit={SizeUnit.BYTE}
  92. isLoading={isLoading}
  93. />
  94. <MetricReadout
  95. title={DataTitles.avg}
  96. value={avgDuration}
  97. unit={DurationUnit.MILLISECOND}
  98. isLoading={isLoading}
  99. />
  100. <MetricReadout
  101. title={DataTitles.timeSpent}
  102. value={timeSpentTotal}
  103. unit={DurationUnit.MILLISECOND}
  104. tooltip={getTimeSpentExplanation(timeSpentPercentage, 'resource')}
  105. isLoading={isLoading}
  106. />
  107. </ReadoutRibbon>
  108. {hasNoData && (
  109. <Alert style={{width: '100%'}} type="warning" showIcon>
  110. {t(
  111. "We couldn't find any size information for this resource, this is likely because the `timing-allow-origin` header is not set."
  112. )}
  113. </Alert>
  114. )}
  115. </Fragment>
  116. );
  117. }
  118. export default ResourceInfo;