resourceSummaryCharts.tsx 4.9 KB

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