resourceSummaryCharts.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import {t, tct} from 'sentry/locale';
  2. import {formatBytesBase2} from 'sentry/utils/bytes/formatBytesBase2';
  3. import {formatRate} from 'sentry/utils/formatters';
  4. import getDynamicText from 'sentry/utils/getDynamicText';
  5. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  6. import {Referrer} from 'sentry/views/insights/browser/resources/referrer';
  7. import {
  8. DATA_TYPE,
  9. RESOURCE_THROUGHPUT_UNIT,
  10. } from 'sentry/views/insights/browser/resources/settings';
  11. import {useResourceModuleFilters} from 'sentry/views/insights/browser/resources/utils/useResourceFilters';
  12. import {AVG_COLOR, THROUGHPUT_COLOR} from 'sentry/views/insights/colors';
  13. import Chart, {ChartType} from 'sentry/views/insights/common/components/chart';
  14. import ChartPanel from 'sentry/views/insights/common/components/chartPanel';
  15. import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
  16. import {
  17. DataTitles,
  18. getDurationChartTitle,
  19. getThroughputChartTitle,
  20. } from 'sentry/views/insights/common/views/spans/types';
  21. import {
  22. Block,
  23. BlockContainer,
  24. } from 'sentry/views/insights/common/views/spanSummaryPage/block';
  25. import {SpanMetricsField} from 'sentry/views/insights/types';
  26. const {
  27. SPAN_SELF_TIME,
  28. HTTP_RESPONSE_CONTENT_LENGTH,
  29. HTTP_DECODED_RESPONSE_CONTENT_LENGTH,
  30. HTTP_RESPONSE_TRANSFER_SIZE,
  31. RESOURCE_RENDER_BLOCKING_STATUS,
  32. } = SpanMetricsField;
  33. function ResourceSummaryCharts(props: {groupId: string}) {
  34. const filters = useResourceModuleFilters();
  35. const {data: spanMetricsSeriesData, isLoading: areSpanMetricsSeriesLoading} =
  36. useSpanMetricsSeries(
  37. {
  38. search: MutableSearch.fromQueryObject({
  39. 'span.group': props.groupId,
  40. ...(filters[RESOURCE_RENDER_BLOCKING_STATUS]
  41. ? {
  42. [RESOURCE_RENDER_BLOCKING_STATUS]:
  43. filters[RESOURCE_RENDER_BLOCKING_STATUS],
  44. }
  45. : {}),
  46. }),
  47. yAxis: [
  48. `spm()`,
  49. `avg(${SPAN_SELF_TIME})`,
  50. `avg(${HTTP_RESPONSE_CONTENT_LENGTH})`,
  51. `avg(${HTTP_DECODED_RESPONSE_CONTENT_LENGTH})`,
  52. `avg(${HTTP_RESPONSE_TRANSFER_SIZE})`,
  53. ],
  54. enabled: Boolean(props.groupId),
  55. },
  56. Referrer.RESOURCE_SUMMARY_CHARTS
  57. );
  58. if (spanMetricsSeriesData) {
  59. spanMetricsSeriesData[`avg(${HTTP_RESPONSE_TRANSFER_SIZE})`].lineStyle = {
  60. type: 'dashed',
  61. };
  62. spanMetricsSeriesData[`avg(${HTTP_DECODED_RESPONSE_CONTENT_LENGTH})`].lineStyle = {
  63. type: 'dashed',
  64. };
  65. }
  66. return (
  67. <BlockContainer>
  68. <Block>
  69. <ChartPanel title={getThroughputChartTitle('http', RESOURCE_THROUGHPUT_UNIT)}>
  70. <Chart
  71. height={160}
  72. data={[spanMetricsSeriesData?.[`spm()`]]}
  73. loading={areSpanMetricsSeriesLoading}
  74. type={ChartType.LINE}
  75. definedAxisTicks={4}
  76. aggregateOutputFormat="rate"
  77. rateUnit={RESOURCE_THROUGHPUT_UNIT}
  78. stacked
  79. chartColors={[THROUGHPUT_COLOR]}
  80. tooltipFormatterOptions={{
  81. valueFormatter: value => formatRate(value, RESOURCE_THROUGHPUT_UNIT),
  82. nameFormatter: () => t('Requests'),
  83. }}
  84. />
  85. </ChartPanel>
  86. </Block>
  87. <Block>
  88. <ChartPanel title={getDurationChartTitle('http')}>
  89. <Chart
  90. height={160}
  91. data={[spanMetricsSeriesData?.[`avg(${SPAN_SELF_TIME})`]]}
  92. loading={areSpanMetricsSeriesLoading}
  93. chartColors={[AVG_COLOR]}
  94. type={ChartType.LINE}
  95. definedAxisTicks={4}
  96. />
  97. </ChartPanel>
  98. </Block>
  99. <Block>
  100. <ChartPanel title={tct('Average [dataType] Size', {dataType: DATA_TYPE})}>
  101. <Chart
  102. height={160}
  103. aggregateOutputFormat="size"
  104. data={[
  105. spanMetricsSeriesData?.[`avg(${HTTP_DECODED_RESPONSE_CONTENT_LENGTH})`],
  106. spanMetricsSeriesData?.[`avg(${HTTP_RESPONSE_TRANSFER_SIZE})`],
  107. spanMetricsSeriesData?.[`avg(${HTTP_RESPONSE_CONTENT_LENGTH})`],
  108. ]}
  109. loading={areSpanMetricsSeriesLoading}
  110. chartColors={[AVG_COLOR]}
  111. type={ChartType.LINE}
  112. definedAxisTicks={4}
  113. tooltipFormatterOptions={{
  114. valueFormatter: bytes =>
  115. getDynamicText({
  116. value: formatBytesBase2(bytes),
  117. fixed: 'xx KiB',
  118. }),
  119. nameFormatter: name => DataTitles[name],
  120. }}
  121. />
  122. </ChartPanel>
  123. </Block>
  124. </BlockContainer>
  125. );
  126. }
  127. export default ResourceSummaryCharts;