resourceSummaryCharts.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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, isLoading: 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. }),
  45. yAxis: [
  46. `spm()`,
  47. `avg(${SPAN_SELF_TIME})`,
  48. `avg(${HTTP_RESPONSE_CONTENT_LENGTH})`,
  49. `avg(${HTTP_DECODED_RESPONSE_CONTENT_LENGTH})`,
  50. `avg(${HTTP_RESPONSE_TRANSFER_SIZE})`,
  51. ],
  52. enabled: Boolean(props.groupId),
  53. },
  54. Referrer.RESOURCE_SUMMARY_CHARTS
  55. );
  56. if (spanMetricsSeriesData) {
  57. spanMetricsSeriesData[`avg(${HTTP_RESPONSE_TRANSFER_SIZE})`].lineStyle = {
  58. type: 'dashed',
  59. };
  60. spanMetricsSeriesData[`avg(${HTTP_DECODED_RESPONSE_CONTENT_LENGTH})`].lineStyle = {
  61. type: 'dashed',
  62. };
  63. }
  64. return (
  65. <Fragment>
  66. <ModuleLayout.Third>
  67. <ChartPanel title={getThroughputChartTitle('http', RESOURCE_THROUGHPUT_UNIT)}>
  68. <Chart
  69. height={160}
  70. data={[spanMetricsSeriesData?.[`spm()`]]}
  71. loading={areSpanMetricsSeriesLoading}
  72. type={ChartType.LINE}
  73. definedAxisTicks={4}
  74. aggregateOutputFormat="rate"
  75. rateUnit={RESOURCE_THROUGHPUT_UNIT}
  76. stacked
  77. chartColors={[THROUGHPUT_COLOR]}
  78. tooltipFormatterOptions={{
  79. valueFormatter: value => formatRate(value, RESOURCE_THROUGHPUT_UNIT),
  80. nameFormatter: () => t('Requests'),
  81. }}
  82. />
  83. </ChartPanel>
  84. </ModuleLayout.Third>
  85. <ModuleLayout.Third>
  86. <ChartPanel title={getDurationChartTitle('http')}>
  87. <Chart
  88. height={160}
  89. data={[spanMetricsSeriesData?.[`avg(${SPAN_SELF_TIME})`]]}
  90. loading={areSpanMetricsSeriesLoading}
  91. chartColors={[AVG_COLOR]}
  92. type={ChartType.LINE}
  93. definedAxisTicks={4}
  94. />
  95. </ChartPanel>
  96. </ModuleLayout.Third>
  97. <ModuleLayout.Third>
  98. <ChartPanel title={tct('Average [dataType] Size', {dataType: DATA_TYPE})}>
  99. <Chart
  100. height={160}
  101. aggregateOutputFormat="size"
  102. data={[
  103. spanMetricsSeriesData?.[`avg(${HTTP_DECODED_RESPONSE_CONTENT_LENGTH})`],
  104. spanMetricsSeriesData?.[`avg(${HTTP_RESPONSE_TRANSFER_SIZE})`],
  105. spanMetricsSeriesData?.[`avg(${HTTP_RESPONSE_CONTENT_LENGTH})`],
  106. ]}
  107. loading={areSpanMetricsSeriesLoading}
  108. chartColors={[AVG_COLOR]}
  109. type={ChartType.LINE}
  110. definedAxisTicks={4}
  111. tooltipFormatterOptions={{
  112. valueFormatter: bytes =>
  113. getDynamicText({
  114. value: formatBytesBase2(bytes),
  115. fixed: 'xx KiB',
  116. }),
  117. nameFormatter: name => DataTitles[name],
  118. }}
  119. />
  120. </ChartPanel>
  121. </ModuleLayout.Third>
  122. </Fragment>
  123. );
  124. }
  125. export default ResourceSummaryCharts;