resourceInfo.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Alert from 'sentry/components/alert';
  4. import {t, tct} from 'sentry/locale';
  5. import {space} from 'sentry/styles/space';
  6. import {formatBytesBase2} from 'sentry/utils';
  7. import {DurationUnit, SizeUnit} from 'sentry/utils/discover/fields';
  8. import getDynamicText from 'sentry/utils/getDynamicText';
  9. import {RESOURCE_THROUGHPUT_UNIT} from 'sentry/views/performance/browser/resources';
  10. import {MetricReadout} from 'sentry/views/performance/metricReadout';
  11. import {getTimeSpentExplanation} from 'sentry/views/starfish/components/tableCells/timeSpentCell';
  12. import {DataTitles, getThroughputTitle} from 'sentry/views/starfish/views/spans/types';
  13. type Props = {
  14. avgContentLength: number;
  15. avgDecodedContentLength: number;
  16. avgDuration: number;
  17. avgTransferSize: number;
  18. throughput: number;
  19. timeSpentPercentage: number;
  20. timeSpentTotal: number;
  21. };
  22. function ResourceInfo(props: Props) {
  23. const {
  24. avgContentLength,
  25. avgDecodedContentLength,
  26. avgDuration,
  27. avgTransferSize,
  28. throughput,
  29. timeSpentPercentage,
  30. timeSpentTotal,
  31. } = props;
  32. const tooltips = {
  33. avgContentLength: tct(
  34. 'On average, this resource is [bytes] when encoded (for example when gzipped).',
  35. {
  36. bytes: getDynamicText({
  37. value: formatBytesBase2(avgContentLength),
  38. fixed: 'xx KiB',
  39. }),
  40. }
  41. ),
  42. avgDecodedContentLength: tct('On average, this resource is [bytes] when decoded.', {
  43. bytes: getDynamicText({
  44. value: formatBytesBase2(avgDecodedContentLength),
  45. fixed: 'xx KiB',
  46. }),
  47. }),
  48. avgTransferSize: tct(
  49. 'On average, the total bytes transferred over the network (body + headers) for this resource is [bytes].',
  50. {
  51. bytes: getDynamicText({
  52. value: formatBytesBase2(avgTransferSize),
  53. fixed: 'xx KiB',
  54. }),
  55. }
  56. ),
  57. };
  58. const hasNoData =
  59. avgContentLength === 0 && avgDecodedContentLength === 0 && avgTransferSize === 0;
  60. return (
  61. <Fragment>
  62. <MetricsRibbon>
  63. <MetricReadout
  64. align="left"
  65. title={getThroughputTitle('resource')}
  66. value={throughput}
  67. unit={RESOURCE_THROUGHPUT_UNIT}
  68. />
  69. <MetricReadout
  70. align="left"
  71. title={DataTitles['avg(http.response_content_length)']}
  72. tooltip={tooltips.avgContentLength}
  73. value={avgContentLength}
  74. unit={SizeUnit.BYTE}
  75. />
  76. <MetricReadout
  77. align="left"
  78. title={DataTitles['avg(http.decoded_response_content_length)']}
  79. value={avgDecodedContentLength}
  80. tooltip={tooltips.avgDecodedContentLength}
  81. unit={SizeUnit.BYTE}
  82. />
  83. <MetricReadout
  84. align="left"
  85. title={DataTitles['avg(http.response_transfer_size)']}
  86. value={avgTransferSize}
  87. tooltip={tooltips.avgTransferSize}
  88. unit={SizeUnit.BYTE}
  89. />
  90. <MetricReadout
  91. align="left"
  92. title={DataTitles.avg}
  93. value={avgDuration}
  94. unit={DurationUnit.MILLISECOND}
  95. />
  96. <MetricReadout
  97. align="left"
  98. title={DataTitles.timeSpent}
  99. value={timeSpentTotal}
  100. unit={DurationUnit.MILLISECOND}
  101. tooltip={getTimeSpentExplanation(timeSpentPercentage, 'resource')}
  102. />
  103. </MetricsRibbon>
  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. const MetricsRibbon = styled('div')`
  115. display: flex;
  116. flex-wrap: wrap;
  117. gap: ${space(4)};
  118. `;
  119. export default ResourceInfo;