resourceInfo.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. spanOp: string;
  20. throughput: number;
  21. timeSpentPercentage: number;
  22. timeSpentTotal: number;
  23. };
  24. function ResourceInfo(props: Props) {
  25. const {
  26. avgContentLength,
  27. avgDecodedContentLength,
  28. avgDuration,
  29. avgTransferSize,
  30. throughput,
  31. timeSpentPercentage,
  32. timeSpentTotal,
  33. spanOp,
  34. } = props;
  35. const tooltips = {
  36. avgContentLength: tct(
  37. 'On average, this resource is [bytes] when encoded (for example when gzipped).',
  38. {
  39. bytes: getDynamicText({
  40. value: formatBytesBase2(avgContentLength),
  41. fixed: 'xx KiB',
  42. }),
  43. }
  44. ),
  45. avgDecodedContentLength: tct('On average, this resource is [bytes] when decoded.', {
  46. bytes: getDynamicText({
  47. value: formatBytesBase2(avgDecodedContentLength),
  48. fixed: 'xx KiB',
  49. }),
  50. }),
  51. avgTransferSize: tct(
  52. 'On average, the total bytes transferred over the network (body + headers) for this resource is [bytes].',
  53. {
  54. bytes: getDynamicText({
  55. value: formatBytesBase2(avgTransferSize),
  56. fixed: 'xx KiB',
  57. }),
  58. }
  59. ),
  60. };
  61. const hasNoData =
  62. avgContentLength === 0 && avgDecodedContentLength === 0 && avgTransferSize === 0;
  63. return (
  64. <Fragment>
  65. <BlockContainer>
  66. <Block title={getThroughputTitle('http')}>
  67. <ThroughputCell rate={throughput} unit={RESOURCE_THROUGHPUT_UNIT} />
  68. </Block>
  69. <Block title={DataTitles['avg(http.response_content_length)']}>
  70. <Tooltip
  71. isHoverable
  72. title={tooltips.avgContentLength}
  73. showUnderline
  74. disabled={!avgContentLength}
  75. >
  76. <ResourceSize bytes={avgContentLength} />
  77. </Tooltip>
  78. </Block>
  79. <Block title={DataTitles['avg(http.decoded_response_content_length)']}>
  80. <Tooltip
  81. isHoverable
  82. title={tooltips.avgDecodedContentLength}
  83. showUnderline
  84. disabled={!avgDecodedContentLength}
  85. >
  86. <ResourceSize bytes={avgDecodedContentLength} />
  87. </Tooltip>
  88. </Block>
  89. <Block title={DataTitles['avg(http.response_transfer_size)']}>
  90. <Tooltip
  91. isHoverable
  92. title={tooltips.avgTransferSize}
  93. showUnderline
  94. disabled={!avgTransferSize}
  95. >
  96. <ResourceSize bytes={avgTransferSize} />
  97. </Tooltip>
  98. </Block>
  99. <Block title={DataTitles.avg}>
  100. <DurationCell milliseconds={avgDuration} />
  101. </Block>
  102. <Block title={DataTitles.timeSpent}>
  103. <TimeSpentCell
  104. percentage={timeSpentPercentage}
  105. total={timeSpentTotal}
  106. op={spanOp}
  107. />
  108. </Block>
  109. </BlockContainer>
  110. {hasNoData && (
  111. <Alert style={{width: '100%'}} type="warning" showIcon>
  112. {t(
  113. "We couldn't find any size information for this resource, this is likely because the `timing-allow-origin` header is not set."
  114. )}
  115. </Alert>
  116. )}
  117. </Fragment>
  118. );
  119. }
  120. export default ResourceInfo;