metricChart.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. import {Fragment, PureComponent} from 'react';
  2. import styled from '@emotion/styled';
  3. import color from 'color';
  4. import type {LineSeriesOption} from 'echarts';
  5. import moment from 'moment-timezone';
  6. import type {Client} from 'sentry/api';
  7. import Feature from 'sentry/components/acl/feature';
  8. import {OnDemandMetricAlert} from 'sentry/components/alerts/onDemandMetricAlert';
  9. import {Button} from 'sentry/components/button';
  10. import type {AreaChartSeries} from 'sentry/components/charts/areaChart';
  11. import {AreaChart} from 'sentry/components/charts/areaChart';
  12. import ChartZoom from 'sentry/components/charts/chartZoom';
  13. import MarkArea from 'sentry/components/charts/components/markArea';
  14. import MarkLine from 'sentry/components/charts/components/markLine';
  15. import EventsRequest from 'sentry/components/charts/eventsRequest';
  16. import LineSeries from 'sentry/components/charts/series/lineSeries';
  17. import SessionsRequest from 'sentry/components/charts/sessionsRequest';
  18. import {
  19. ChartControls,
  20. HeaderTitleLegend,
  21. InlineContainer,
  22. SectionHeading,
  23. SectionValue,
  24. } from 'sentry/components/charts/styles';
  25. import {isEmptySeries} from 'sentry/components/charts/utils';
  26. import CircleIndicator from 'sentry/components/circleIndicator';
  27. import type {StatsPeriodType} from 'sentry/components/organizations/pageFilters/parse';
  28. import {parseStatsPeriod} from 'sentry/components/organizations/pageFilters/parse';
  29. import Panel from 'sentry/components/panels/panel';
  30. import PanelBody from 'sentry/components/panels/panelBody';
  31. import Placeholder from 'sentry/components/placeholder';
  32. import {Tooltip} from 'sentry/components/tooltip';
  33. import {IconCheckmark, IconClock, IconFire, IconWarning} from 'sentry/icons';
  34. import {t} from 'sentry/locale';
  35. import ConfigStore from 'sentry/stores/configStore';
  36. import {space} from 'sentry/styles/space';
  37. import {ActivationConditionType, MonitorType} from 'sentry/types/alerts';
  38. import type {DateString} from 'sentry/types/core';
  39. import type {ReactEchartsRef, Series} from 'sentry/types/echarts';
  40. import type {WithRouterProps} from 'sentry/types/legacyReactRouter';
  41. import type {Organization} from 'sentry/types/organization';
  42. import type {Project} from 'sentry/types/project';
  43. import toArray from 'sentry/utils/array/toArray';
  44. import {browserHistory} from 'sentry/utils/browserHistory';
  45. import {getUtcDateString} from 'sentry/utils/dates';
  46. import {DiscoverDatasets, SavedQueryDatasets} from 'sentry/utils/discover/types';
  47. import getDuration from 'sentry/utils/duration/getDuration';
  48. import getDynamicText from 'sentry/utils/getDynamicText';
  49. import {getForceMetricsLayerQueryExtras} from 'sentry/utils/metrics/features';
  50. import {shouldShowOnDemandMetricAlertUI} from 'sentry/utils/onDemandMetrics/features';
  51. import {MINUTES_THRESHOLD_TO_DISPLAY_SECONDS} from 'sentry/utils/sessions';
  52. import {capitalize} from 'sentry/utils/string/capitalize';
  53. import theme from 'sentry/utils/theme';
  54. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  55. // eslint-disable-next-line no-restricted-imports
  56. import withSentryRouter from 'sentry/utils/withSentryRouter';
  57. import {COMPARISON_DELTA_OPTIONS} from 'sentry/views/alerts/rules/metric/constants';
  58. import {makeDefaultCta} from 'sentry/views/alerts/rules/metric/metricRulePresets';
  59. import type {MetricRule} from 'sentry/views/alerts/rules/metric/types';
  60. import {
  61. AlertRuleTriggerType,
  62. Dataset,
  63. TimePeriod,
  64. } from 'sentry/views/alerts/rules/metric/types';
  65. import {getChangeStatus} from 'sentry/views/alerts/utils/getChangeStatus';
  66. import {AlertWizardAlertNames} from 'sentry/views/alerts/wizard/options';
  67. import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils';
  68. import {hasDatasetSelector} from 'sentry/views/dashboards/utils';
  69. import type {Anomaly, Incident} from '../../../types';
  70. import {
  71. alertDetailsLink,
  72. alertTooltipValueFormatter,
  73. isSessionAggregate,
  74. SESSION_AGGREGATE_TO_FIELD,
  75. } from '../../../utils';
  76. import {getMetricDatasetQueryExtras} from '../utils/getMetricDatasetQueryExtras';
  77. import {isCrashFreeAlert} from '../utils/isCrashFreeAlert';
  78. import type {TimePeriodType} from './constants';
  79. import {
  80. getMetricAlertChartOption,
  81. transformSessionResponseToSeries,
  82. } from './metricChartOption';
  83. type Props = WithRouterProps & {
  84. api: Client;
  85. filter: string[] | null;
  86. interval: string;
  87. organization: Organization;
  88. project: Project;
  89. query: string;
  90. rule: MetricRule;
  91. timePeriod: TimePeriodType;
  92. anomalies?: Anomaly[];
  93. formattedAggregate?: string;
  94. incidents?: Incident[];
  95. isOnDemandAlert?: boolean;
  96. selectedIncident?: Incident | null;
  97. };
  98. type State = Record<string, never>;
  99. function formatTooltipDate(date: moment.MomentInput, format: string): string {
  100. const {
  101. options: {timezone},
  102. } = ConfigStore.get('user');
  103. return moment.tz(date, timezone).format(format);
  104. }
  105. function getRuleChangeSeries(
  106. rule: MetricRule,
  107. data: AreaChartSeries[]
  108. ): LineSeriesOption[] {
  109. const {dateModified} = rule;
  110. if (!data.length || !data[0]!.data.length || !dateModified) {
  111. return [];
  112. }
  113. const seriesData = data[0]!.data;
  114. const seriesStart = new Date(seriesData[0]!.name).getTime();
  115. const ruleChanged = new Date(dateModified).getTime();
  116. if (ruleChanged < seriesStart) {
  117. return [];
  118. }
  119. return [
  120. {
  121. type: 'line',
  122. markLine: MarkLine({
  123. silent: true,
  124. animation: false,
  125. lineStyle: {color: theme.gray200, type: 'solid', width: 1},
  126. data: [{xAxis: ruleChanged}],
  127. label: {
  128. show: false,
  129. },
  130. }),
  131. markArea: MarkArea({
  132. silent: true,
  133. itemStyle: {
  134. color: color(theme.gray100).alpha(0.42).rgb().string(),
  135. },
  136. data: [[{xAxis: seriesStart}, {xAxis: ruleChanged}]],
  137. }),
  138. data: [],
  139. },
  140. ];
  141. }
  142. function shouldUseErrorsDataset(dataset: Dataset, query: string): boolean {
  143. return dataset === Dataset.ERRORS && /\bis:unresolved\b/.test(query);
  144. }
  145. class MetricChart extends PureComponent<Props, State> {
  146. ref: null | ReactEchartsRef = null;
  147. handleZoom = (start: DateString, end: DateString) => {
  148. const {location} = this.props;
  149. browserHistory.push({
  150. pathname: location.pathname,
  151. query: {
  152. start,
  153. end,
  154. },
  155. });
  156. };
  157. renderChartActions(
  158. totalDuration: number,
  159. criticalDuration: number,
  160. warningDuration: number,
  161. waitingForDataDuration: number
  162. ) {
  163. const {rule, organization, project, timePeriod, query} = this.props;
  164. let dataset: DiscoverDatasets | undefined = undefined;
  165. if (shouldUseErrorsDataset(rule.dataset, query)) {
  166. dataset = DiscoverDatasets.ERRORS;
  167. }
  168. let openInDiscoverDataset: SavedQueryDatasets | undefined = undefined;
  169. if (hasDatasetSelector(organization)) {
  170. if (rule.dataset === Dataset.ERRORS) {
  171. openInDiscoverDataset = SavedQueryDatasets.ERRORS;
  172. } else if (
  173. rule.dataset === Dataset.TRANSACTIONS ||
  174. rule.dataset === Dataset.GENERIC_METRICS
  175. ) {
  176. openInDiscoverDataset = SavedQueryDatasets.TRANSACTIONS;
  177. }
  178. }
  179. const {buttonText, ...props} = makeDefaultCta({
  180. organization,
  181. projects: [project],
  182. rule,
  183. timePeriod,
  184. query,
  185. dataset,
  186. openInDiscoverDataset,
  187. });
  188. const resolvedPercent =
  189. (100 *
  190. Math.max(
  191. totalDuration - waitingForDataDuration - criticalDuration - warningDuration,
  192. 0
  193. )) /
  194. totalDuration;
  195. const criticalPercent = 100 * Math.min(criticalDuration / totalDuration, 1);
  196. const warningPercent = 100 * Math.min(warningDuration / totalDuration, 1);
  197. const waitingForDataPercent =
  198. 100 *
  199. Math.min(
  200. (waitingForDataDuration - criticalDuration - warningDuration) / totalDuration,
  201. 1
  202. );
  203. return (
  204. <StyledChartControls>
  205. <StyledInlineContainer>
  206. <Fragment>
  207. <SectionHeading>{t('Summary')}</SectionHeading>
  208. <StyledSectionValue>
  209. <ValueItem>
  210. <IconCheckmark color="successText" isCircled />
  211. {resolvedPercent ? resolvedPercent.toFixed(2) : 0}%
  212. </ValueItem>
  213. <ValueItem>
  214. <IconWarning color="warningText" />
  215. {warningPercent ? warningPercent.toFixed(2) : 0}%
  216. </ValueItem>
  217. <ValueItem>
  218. <IconFire color="errorText" />
  219. {criticalPercent ? criticalPercent.toFixed(2) : 0}%
  220. </ValueItem>
  221. {waitingForDataPercent > 0 && (
  222. <StyledTooltip
  223. underlineColor="gray200"
  224. showUnderline
  225. title={t(
  226. 'The time spent waiting for metrics matching the filters used.'
  227. )}
  228. >
  229. <ValueItem>
  230. <IconClock />
  231. {waitingForDataPercent.toFixed(2)}%
  232. </ValueItem>
  233. </StyledTooltip>
  234. )}
  235. </StyledSectionValue>
  236. </Fragment>
  237. </StyledInlineContainer>
  238. {!isSessionAggregate(rule.aggregate) &&
  239. (getAlertTypeFromAggregateDataset(rule) === 'eap_metrics' ? (
  240. <Feature features="visibility-explore-view">
  241. <Button size="sm" {...props}>
  242. {buttonText}
  243. </Button>
  244. </Feature>
  245. ) : (
  246. <Feature features="discover-basic">
  247. <Button size="sm" {...props}>
  248. {buttonText}
  249. </Button>
  250. </Feature>
  251. ))}
  252. </StyledChartControls>
  253. );
  254. }
  255. renderChart(
  256. loading: boolean,
  257. timeseriesData?: Series[],
  258. minutesThresholdToDisplaySeconds?: number,
  259. comparisonTimeseriesData?: Series[]
  260. ) {
  261. const {
  262. anomalies,
  263. router,
  264. selectedIncident,
  265. interval,
  266. filter,
  267. incidents,
  268. rule,
  269. organization,
  270. timePeriod: {start, end},
  271. formattedAggregate,
  272. } = this.props;
  273. const {dateModified, timeWindow} = rule;
  274. if (loading || !timeseriesData) {
  275. return this.renderEmpty();
  276. }
  277. const handleIncidentClick = (incident: Incident) => {
  278. router.push(
  279. normalizeUrl({
  280. pathname: alertDetailsLink(organization, incident),
  281. query: {alert: incident.identifier},
  282. })
  283. );
  284. };
  285. const {
  286. criticalDuration,
  287. warningDuration,
  288. totalDuration,
  289. waitingForDataDuration,
  290. chartOption,
  291. } = getMetricAlertChartOption({
  292. timeseriesData,
  293. rule,
  294. seriesName: formattedAggregate,
  295. incidents,
  296. anomalies,
  297. selectedIncident,
  298. showWaitingForData:
  299. shouldShowOnDemandMetricAlertUI(organization) && this.props.isOnDemandAlert,
  300. handleIncidentClick,
  301. });
  302. const comparisonSeriesName = capitalize(
  303. COMPARISON_DELTA_OPTIONS.find(({value}) => value === rule.comparisonDelta)?.label ||
  304. ''
  305. );
  306. const additionalSeries: LineSeriesOption[] = [
  307. ...(comparisonTimeseriesData || []).map(({data: _data, ...otherSeriesProps}) =>
  308. LineSeries({
  309. name: comparisonSeriesName,
  310. data: _data.map(({name, value}) => [name, value]),
  311. lineStyle: {color: theme.gray200, type: 'dashed', width: 1},
  312. itemStyle: {color: theme.gray200},
  313. animation: false,
  314. animationThreshold: 1,
  315. animationDuration: 0,
  316. ...otherSeriesProps,
  317. })
  318. ),
  319. ...getRuleChangeSeries(rule, timeseriesData),
  320. ];
  321. const queryFilter =
  322. filter?.join(' ') + t(' over ') + getDuration(rule.timeWindow * 60);
  323. return (
  324. <ChartPanel>
  325. <StyledPanelBody withPadding>
  326. <ChartHeader>
  327. <HeaderTitleLegend>
  328. {AlertWizardAlertNames[getAlertTypeFromAggregateDataset(rule)]}
  329. </HeaderTitleLegend>
  330. </ChartHeader>
  331. <ChartFilters>
  332. <StyledCircleIndicator size={8} />
  333. <Filters>{formattedAggregate ?? rule.aggregate}</Filters>
  334. <Tooltip
  335. title={queryFilter}
  336. isHoverable
  337. skipWrapper
  338. overlayStyle={{maxWidth: '90vw', lineBreak: 'anywhere', textAlign: 'left'}}
  339. showOnlyOnOverflow
  340. >
  341. <QueryFilters>{queryFilter}</QueryFilters>
  342. </Tooltip>
  343. </ChartFilters>
  344. {getDynamicText({
  345. value: (
  346. <ChartZoom
  347. start={start}
  348. end={end}
  349. onZoom={zoomArgs => this.handleZoom(zoomArgs.start, zoomArgs.end)}
  350. >
  351. {zoomRenderProps => (
  352. <AreaChart
  353. {...zoomRenderProps}
  354. {...chartOption}
  355. showTimeInTooltip
  356. minutesThresholdToDisplaySeconds={minutesThresholdToDisplaySeconds}
  357. additionalSeries={additionalSeries}
  358. tooltip={{
  359. formatter: seriesParams => {
  360. // seriesParams can be object instead of array
  361. const pointSeries = toArray(seriesParams);
  362. const {marker, data: pointData} = pointSeries[0];
  363. const seriesName =
  364. formattedAggregate ?? pointSeries[0].seriesName ?? '';
  365. const [pointX, pointY] = pointData as [number, number];
  366. const pointYFormatted = alertTooltipValueFormatter(
  367. pointY,
  368. seriesName,
  369. rule.aggregate
  370. );
  371. const isModified =
  372. dateModified && pointX <= new Date(dateModified).getTime();
  373. const startTime = formatTooltipDate(moment(pointX), 'MMM D LT');
  374. const {period, periodLength} = parseStatsPeriod(interval) ?? {
  375. periodLength: 'm',
  376. period: `${timeWindow}`,
  377. };
  378. const endTime = formatTooltipDate(
  379. moment(pointX).add(
  380. parseInt(period!, 10),
  381. periodLength as StatsPeriodType
  382. ),
  383. 'MMM D LT'
  384. );
  385. const comparisonSeries =
  386. pointSeries.length > 1
  387. ? pointSeries.find(
  388. ({seriesName: _sn}) => _sn === comparisonSeriesName
  389. )
  390. : undefined;
  391. const comparisonPointY = comparisonSeries?.data[1] as
  392. | number
  393. | undefined;
  394. const comparisonPointYFormatted =
  395. comparisonPointY !== undefined
  396. ? alertTooltipValueFormatter(
  397. comparisonPointY,
  398. seriesName,
  399. rule.aggregate
  400. )
  401. : undefined;
  402. const changePercentage =
  403. comparisonPointY === undefined
  404. ? NaN
  405. : ((pointY - comparisonPointY) * 100) / comparisonPointY;
  406. const changeStatus = getChangeStatus(
  407. changePercentage,
  408. rule.thresholdType,
  409. rule.triggers
  410. );
  411. const changeStatusColor =
  412. changeStatus === AlertRuleTriggerType.CRITICAL
  413. ? theme.red300
  414. : changeStatus === AlertRuleTriggerType.WARNING
  415. ? theme.yellow300
  416. : theme.green300;
  417. return [
  418. `<div class="tooltip-series">`,
  419. isModified &&
  420. `<div><span class="tooltip-label"><strong>${t(
  421. 'Alert Rule Modified'
  422. )}</strong></span></div>`,
  423. `<div><span class="tooltip-label">${marker} <strong>${seriesName}</strong></span>${pointYFormatted}</div>`,
  424. comparisonSeries &&
  425. `<div><span class="tooltip-label">${comparisonSeries.marker} <strong>${comparisonSeriesName}</strong></span>${comparisonPointYFormatted}</div>`,
  426. `</div>`,
  427. `<div class="tooltip-footer">`,
  428. `<span>${startTime} &mdash; ${endTime}</span>`,
  429. comparisonPointY !== undefined &&
  430. Math.abs(changePercentage) !== Infinity &&
  431. !isNaN(changePercentage) &&
  432. `<span style="color:${changeStatusColor};margin-left:10px;">${
  433. Math.sign(changePercentage) === 1 ? '+' : '-'
  434. }${Math.abs(changePercentage).toFixed(2)}%</span>`,
  435. `</div>`,
  436. '<div class="tooltip-arrow"></div>',
  437. ]
  438. .filter(e => e)
  439. .join('');
  440. },
  441. }}
  442. />
  443. )}
  444. </ChartZoom>
  445. ),
  446. fixed: <Placeholder height="200px" testId="skeleton-ui" />,
  447. })}
  448. </StyledPanelBody>
  449. {this.renderChartActions(
  450. totalDuration,
  451. criticalDuration,
  452. warningDuration,
  453. waitingForDataDuration
  454. )}
  455. </ChartPanel>
  456. );
  457. }
  458. renderEmptyOnDemandAlert(
  459. organization: Organization,
  460. timeseriesData: Series[] = [],
  461. loading?: boolean
  462. ) {
  463. if (
  464. loading ||
  465. !this.props.isOnDemandAlert ||
  466. !shouldShowOnDemandMetricAlertUI(organization) ||
  467. !isEmptySeries(timeseriesData[0]!)
  468. ) {
  469. return null;
  470. }
  471. return (
  472. <OnDemandMetricAlert
  473. dismissable
  474. message={t(
  475. 'This alert lacks historical data due to filters for which we don’t routinely extract metrics.'
  476. )}
  477. />
  478. );
  479. }
  480. renderEmpty(placeholderText = '') {
  481. return (
  482. <ChartPanel>
  483. <PanelBody withPadding>
  484. <TriggerChartPlaceholder>{placeholderText}</TriggerChartPlaceholder>
  485. </PanelBody>
  486. </ChartPanel>
  487. );
  488. }
  489. render() {
  490. const {
  491. api,
  492. rule,
  493. organization,
  494. timePeriod,
  495. project,
  496. interval,
  497. query,
  498. location,
  499. isOnDemandAlert,
  500. selectedIncident,
  501. } = this.props;
  502. const {aggregate, timeWindow, environment, dataset} = rule;
  503. // Fix for 7 days * 1m interval being over the max number of results from events api
  504. // 10k events is the current max
  505. if (
  506. timePeriod.usingPeriod &&
  507. timePeriod.period === TimePeriod.SEVEN_DAYS &&
  508. interval === '1m'
  509. ) {
  510. timePeriod.start = getUtcDateString(
  511. // -5 minutes provides a small cushion for rounding up minutes. This might be able to be smaller
  512. moment(moment.utc(timePeriod.end).subtract(10000 - 5, 'minutes'))
  513. );
  514. }
  515. // If the chart duration isn't as long as the rollup duration the events-stats
  516. // endpoint will return an invalid timeseriesData dataset
  517. const viableStartDate = getUtcDateString(
  518. moment.min(
  519. moment.utc(timePeriod.start),
  520. moment.utc(timePeriod.end).subtract(timeWindow, 'minutes')
  521. )
  522. );
  523. const viableEndDate = getUtcDateString(
  524. moment.utc(timePeriod.end).add(timeWindow, 'minutes')
  525. );
  526. let activationFilter = '';
  527. if (
  528. rule.monitorType === MonitorType.ACTIVATED &&
  529. selectedIncident &&
  530. selectedIncident.activation
  531. ) {
  532. const {activation} = selectedIncident;
  533. const {activator, conditionType} = activation;
  534. switch (conditionType) {
  535. case String(ActivationConditionType.RELEASE_CREATION):
  536. activationFilter = ` AND (release:${activator})`;
  537. break;
  538. case String(ActivationConditionType.DEPLOY_CREATION):
  539. activationFilter = ` AND (deploy:${activator})`;
  540. break;
  541. default:
  542. break;
  543. }
  544. }
  545. const queryExtras: Record<string, string> = {
  546. ...getMetricDatasetQueryExtras({
  547. organization,
  548. location,
  549. dataset,
  550. newAlertOrQuery: false,
  551. useOnDemandMetrics: isOnDemandAlert,
  552. }),
  553. ...getForceMetricsLayerQueryExtras(organization, dataset),
  554. };
  555. if (shouldUseErrorsDataset(dataset, query)) {
  556. queryExtras.dataset = 'errors';
  557. }
  558. return isCrashFreeAlert(dataset) ? (
  559. <SessionsRequest
  560. api={api}
  561. organization={organization}
  562. project={project.id ? [Number(project.id)] : []}
  563. environment={environment ? [environment] : undefined}
  564. start={viableStartDate}
  565. end={viableEndDate}
  566. query={query + activationFilter}
  567. interval={interval}
  568. field={SESSION_AGGREGATE_TO_FIELD[aggregate]}
  569. groupBy={['session.status']}
  570. >
  571. {({loading, response}) =>
  572. this.renderChart(
  573. loading,
  574. transformSessionResponseToSeries(response, rule),
  575. MINUTES_THRESHOLD_TO_DISPLAY_SECONDS
  576. )
  577. }
  578. </SessionsRequest>
  579. ) : (
  580. <EventsRequest
  581. api={api}
  582. organization={organization}
  583. query={query + activationFilter}
  584. environment={environment ? [environment] : undefined}
  585. project={project.id ? [Number(project.id)] : []}
  586. interval={interval}
  587. comparisonDelta={rule.comparisonDelta ? rule.comparisonDelta * 60 : undefined}
  588. start={viableStartDate}
  589. end={viableEndDate}
  590. yAxis={aggregate}
  591. includePrevious={false}
  592. currentSeriesNames={[aggregate]}
  593. partial={false}
  594. queryExtras={queryExtras}
  595. referrer="api.alerts.alert-rule-chart"
  596. useRpc={dataset === Dataset.EVENTS_ANALYTICS_PLATFORM}
  597. useOnDemandMetrics
  598. >
  599. {({loading, timeseriesData, comparisonTimeseriesData}) => (
  600. <Fragment>
  601. {this.renderEmptyOnDemandAlert(organization, timeseriesData, loading)}
  602. {this.renderChart(
  603. loading,
  604. timeseriesData,
  605. undefined,
  606. comparisonTimeseriesData
  607. )}
  608. </Fragment>
  609. )}
  610. </EventsRequest>
  611. );
  612. }
  613. }
  614. export default withSentryRouter(MetricChart);
  615. const ChartPanel = styled(Panel)`
  616. margin-top: ${space(2)};
  617. `;
  618. const ChartHeader = styled('div')`
  619. margin-bottom: ${space(3)};
  620. `;
  621. const StyledChartControls = styled(ChartControls)`
  622. display: flex;
  623. justify-content: space-between;
  624. flex-wrap: wrap;
  625. `;
  626. const StyledInlineContainer = styled(InlineContainer)`
  627. grid-auto-flow: column;
  628. grid-column-gap: ${space(1)};
  629. `;
  630. const StyledCircleIndicator = styled(CircleIndicator)`
  631. background: ${p => p.theme.formText};
  632. height: ${space(1)};
  633. margin-right: ${space(0.5)};
  634. `;
  635. const ChartFilters = styled('div')`
  636. font-size: ${p => p.theme.fontSizeSmall};
  637. font-family: ${p => p.theme.text.family};
  638. color: ${p => p.theme.textColor};
  639. display: inline-grid;
  640. grid-template-columns: max-content max-content auto;
  641. align-items: center;
  642. `;
  643. const Filters = styled('span')`
  644. margin-right: ${space(1)};
  645. `;
  646. const QueryFilters = styled('span')`
  647. min-width: 0px;
  648. ${p => p.theme.overflowEllipsis}
  649. `;
  650. const StyledSectionValue = styled(SectionValue)`
  651. display: grid;
  652. grid-template-columns: repeat(4, auto);
  653. gap: ${space(1.5)};
  654. margin: 0 0 0 ${space(1.5)};
  655. `;
  656. const ValueItem = styled('div')`
  657. display: grid;
  658. grid-template-columns: repeat(2, auto);
  659. gap: ${space(0.5)};
  660. align-items: center;
  661. font-variant-numeric: tabular-nums;
  662. text-underline-offset: ${space(4)};
  663. `;
  664. /* Override padding to make chart appear centered */
  665. const StyledPanelBody = styled(PanelBody)`
  666. padding-right: 6px;
  667. `;
  668. const TriggerChartPlaceholder = styled(Placeholder)`
  669. height: 200px;
  670. text-align: center;
  671. padding: ${space(3)};
  672. `;
  673. const StyledTooltip = styled(Tooltip)`
  674. text-underline-offset: ${space(0.5)} !important;
  675. `;