resourceInfo.tsx 3.6 KB

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