resourceSummaryCharts.tsx 4.4 KB

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