resourceSummaryCharts.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {t} from 'sentry/locale';
  2. import {Series} from 'sentry/types/echarts';
  3. import {formatBytesBase2} from 'sentry/utils';
  4. import getDynamicText from 'sentry/utils/getDynamicText';
  5. import {AVG_COLOR} from 'sentry/views/starfish/colours';
  6. import Chart from 'sentry/views/starfish/components/chart';
  7. import ChartPanel from 'sentry/views/starfish/components/chartPanel';
  8. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  9. import {SpanMetricsField} from 'sentry/views/starfish/types';
  10. import {getDurationChartTitle} from 'sentry/views/starfish/views/spans/types';
  11. import {Block, BlockContainer} from 'sentry/views/starfish/views/spanSummaryPage/block';
  12. const {SPAN_SELF_TIME, HTTP_RESPONSE_CONTENT_LENGTH} = SpanMetricsField;
  13. function ResourceSummaryCharts(props: {groupId: string}) {
  14. const {data: spanMetricsSeriesData, isLoading: areSpanMetricsSeriesLoading} =
  15. useSpanMetricsSeries(props.groupId, {}, [
  16. `avg(${SPAN_SELF_TIME})`,
  17. `avg(${HTTP_RESPONSE_CONTENT_LENGTH})`,
  18. ]);
  19. return (
  20. <BlockContainer>
  21. <Block>
  22. <ChartPanel title={getDurationChartTitle('http')}>
  23. <Chart
  24. height={160}
  25. data={[spanMetricsSeriesData?.[`avg(${SPAN_SELF_TIME})`]]}
  26. loading={areSpanMetricsSeriesLoading}
  27. utc={false}
  28. chartColors={[AVG_COLOR]}
  29. isLineChart
  30. definedAxisTicks={4}
  31. />
  32. </ChartPanel>
  33. </Block>
  34. <Block>
  35. <ChartPanel title={t('Resource Size')}>
  36. <Chart
  37. height={160}
  38. data={[spanMetricsSeriesData?.[`avg(${HTTP_RESPONSE_CONTENT_LENGTH})`]]}
  39. loading={areSpanMetricsSeriesLoading}
  40. utc={false}
  41. chartColors={[AVG_COLOR]}
  42. isLineChart
  43. definedAxisTicks={4}
  44. tooltipFormatterOptions={{
  45. valueFormatter: bytes =>
  46. getDynamicText({
  47. value: formatBytesBase2(bytes),
  48. fixed: 'xx KB',
  49. }),
  50. }}
  51. />
  52. </ChartPanel>
  53. </Block>
  54. </BlockContainer>
  55. );
  56. }
  57. /**
  58. * Ensures a series has no zeros between two non-zero datapoints. This is useful in
  59. * @param series the series to fill
  60. * @returns a reference to the initial series filled
  61. */
  62. export const fillSeries = (series: Series): Series => {
  63. if (!series.data.length) {
  64. return series;
  65. }
  66. let lastSeenValue = series.data[0].value;
  67. return {
  68. ...series,
  69. data: series.data.map(dataPoint => {
  70. const value = dataPoint.value;
  71. if (value !== lastSeenValue && value !== 0) {
  72. lastSeenValue = value;
  73. return {...dataPoint};
  74. }
  75. return {...dataPoint, value: lastSeenValue};
  76. }),
  77. };
  78. };
  79. export default ResourceSummaryCharts;