resourceSummaryCharts.tsx 4.9 KB

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