resourceInfo.tsx 3.9 KB

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