resourceInfo.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/bytes/formatBytesBase2';
  7. import {DurationUnit, SizeUnit} from 'sentry/utils/discover/fields';
  8. import getDynamicText from 'sentry/utils/getDynamicText';
  9. import {RESOURCE_THROUGHPUT_UNIT} from 'sentry/views/insights/browser/resources/settings';
  10. import {MetricReadout} from 'sentry/views/insights/common/components/metricReadout';
  11. import {getTimeSpentExplanation} from 'sentry/views/insights/common/components/tableCells/timeSpentCell';
  12. import {
  13. DataTitles,
  14. getThroughputTitle,
  15. } from 'sentry/views/insights/common/views/spans/types';
  16. type Props = {
  17. avgContentLength: number;
  18. avgDecodedContentLength: number;
  19. avgDuration: number;
  20. avgTransferSize: number;
  21. throughput: number;
  22. timeSpentPercentage: number;
  23. timeSpentTotal: number;
  24. };
  25. function ResourceInfo(props: Props) {
  26. const {
  27. avgContentLength,
  28. avgDecodedContentLength,
  29. avgDuration,
  30. avgTransferSize,
  31. throughput,
  32. timeSpentPercentage,
  33. timeSpentTotal,
  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. <MetricsRibbon>
  66. <MetricReadout
  67. align="left"
  68. title={getThroughputTitle('resource')}
  69. value={throughput}
  70. unit={RESOURCE_THROUGHPUT_UNIT}
  71. />
  72. <MetricReadout
  73. align="left"
  74. title={DataTitles['avg(http.response_content_length)']}
  75. tooltip={tooltips.avgContentLength}
  76. value={avgContentLength}
  77. unit={SizeUnit.BYTE}
  78. />
  79. <MetricReadout
  80. align="left"
  81. title={DataTitles['avg(http.decoded_response_content_length)']}
  82. value={avgDecodedContentLength}
  83. tooltip={tooltips.avgDecodedContentLength}
  84. unit={SizeUnit.BYTE}
  85. />
  86. <MetricReadout
  87. align="left"
  88. title={DataTitles['avg(http.response_transfer_size)']}
  89. value={avgTransferSize}
  90. tooltip={tooltips.avgTransferSize}
  91. unit={SizeUnit.BYTE}
  92. />
  93. <MetricReadout
  94. align="left"
  95. title={DataTitles.avg}
  96. value={avgDuration}
  97. unit={DurationUnit.MILLISECOND}
  98. />
  99. <MetricReadout
  100. align="left"
  101. title={DataTitles.timeSpent}
  102. value={timeSpentTotal}
  103. unit={DurationUnit.MILLISECOND}
  104. tooltip={getTimeSpentExplanation(timeSpentPercentage, 'resource')}
  105. />
  106. </MetricsRibbon>
  107. {hasNoData && (
  108. <Alert style={{width: '100%'}} type="warning" showIcon>
  109. {t(
  110. "We couldn't find any size information for this resource, this is likely because the `timing-allow-origin` header is not set."
  111. )}
  112. </Alert>
  113. )}
  114. </Fragment>
  115. );
  116. }
  117. const MetricsRibbon = styled('div')`
  118. display: flex;
  119. flex-wrap: wrap;
  120. gap: ${space(4)};
  121. `;
  122. export default ResourceInfo;