From 17d09c7d1c21f732292b0b5020b977f5b89e9de9 Mon Sep 17 00:00:00 2001 From: Ogi <86684834+obostjancic@users.noreply.github.com> Date: Fri, 21 Jul 2023 10:49:24 +0200 Subject: [PATCH] feat(alerts): on demand metric alert chart (#52962) --- static/app/actionCreators/events.tsx | 3 +++ .../app/components/charts/eventsRequest.tsx | 5 ++++ .../views/alerts/rules/metric/create.spec.tsx | 1 + .../alerts/rules/metric/details/body.tsx | 2 ++ .../rules/metric/details/metricChart.tsx | 24 ++++++++++--------- .../rules/metric/triggers/chart/index.tsx | 1 + 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/static/app/actionCreators/events.tsx b/static/app/actionCreators/events.tsx index ee790bdd5db21f..bfb40d59a7fde7 100644 --- a/static/app/actionCreators/events.tsx +++ b/static/app/actionCreators/events.tsx @@ -54,6 +54,7 @@ type Options = { start?: DateString; team?: Readonly; topEvents?: number; + useOnDemandMetrics?: boolean; withoutZerofill?: boolean; yAxis?: string | string[]; }; @@ -105,6 +106,7 @@ export const doEventsRequest = ( excludeOther, includeAllArgs, dataset, + useOnDemandMetrics, }: {includeAllArgs?: IncludeAllArgsType} & Options ): IncludeAllArgsType extends true ? Promise< @@ -133,6 +135,7 @@ export const doEventsRequest = ( referrer: referrer ? referrer : 'api.organization-event-stats', excludeOther: excludeOther ? '1' : undefined, dataset, + useOnDemandMetrics, }).filter(([, value]) => typeof value !== 'undefined') ); diff --git a/static/app/components/charts/eventsRequest.tsx b/static/app/components/charts/eventsRequest.tsx index 66afeb60cfaa83..6843c65bb59893 100644 --- a/static/app/components/charts/eventsRequest.tsx +++ b/static/app/components/charts/eventsRequest.tsx @@ -209,6 +209,11 @@ type EventsRequestPartialProps = { * in the `results` child render function. */ topEvents?: number; + /** + * Whether or not to use on demand metrics + * This is a temporary flag to allow us to test on demand metrics + */ + useOnDemandMetrics?: boolean; /** * Whether or not to zerofill results */ diff --git a/static/app/views/alerts/rules/metric/create.spec.tsx b/static/app/views/alerts/rules/metric/create.spec.tsx index 067674f40f1a9c..17ddb480d10b80 100644 --- a/static/app/views/alerts/rules/metric/create.spec.tsx +++ b/static/app/views/alerts/rules/metric/create.spec.tsx @@ -66,6 +66,7 @@ describe('Incident Rules Create', function () { statsPeriod: '10000m', yAxis: 'count()', referrer: 'api.organization-event-stats', + useOnDemandMetrics: false, }, }) ); diff --git a/static/app/views/alerts/rules/metric/details/body.tsx b/static/app/views/alerts/rules/metric/details/body.tsx index 451f00e53a0860..dfec3f7d8a2cb7 100644 --- a/static/app/views/alerts/rules/metric/details/body.tsx +++ b/static/app/views/alerts/rules/metric/details/body.tsx @@ -21,6 +21,7 @@ import {RuleActionsCategories} from 'sentry/types/alerts'; import MetricHistory from 'sentry/views/alerts/rules/metric/details/metricHistory'; import {Dataset, MetricRule, TimePeriod} from 'sentry/views/alerts/rules/metric/types'; import {extractEventTypeFilterFromRule} from 'sentry/views/alerts/rules/metric/utils/getEventTypeFilter'; +import {isOnDemandMetricAlert} from 'sentry/views/alerts/rules/metric/utils/onDemandMetricAlert'; import {getAlertRuleActionCategory} from 'sentry/views/alerts/rules/utils'; import {AlertRuleStatus, Incident} from '../../../types'; @@ -216,6 +217,7 @@ export default class DetailsBody extends Component { interval={this.getInterval()} query={isCrashFreeAlert(dataset) ? query : queryWithTypeFilter} filter={this.getFilter()} + isOnDemandMetricAlert={isOnDemandMetricAlert(dataset, query)} /> diff --git a/static/app/views/alerts/rules/metric/details/metricChart.tsx b/static/app/views/alerts/rules/metric/details/metricChart.tsx index 0c0227e96d5175..fe1cfd5c4d782c 100644 --- a/static/app/views/alerts/rules/metric/details/metricChart.tsx +++ b/static/app/views/alerts/rules/metric/details/metricChart.tsx @@ -55,7 +55,6 @@ import { MetricRule, TimePeriod, } from 'sentry/views/alerts/rules/metric/types'; -import {isOnDemandMetricAlert} from 'sentry/views/alerts/rules/metric/utils/onDemandMetricAlert'; import {getChangeStatus} from 'sentry/views/alerts/utils/getChangeStatus'; import {AlertWizardAlertNames} from 'sentry/views/alerts/wizard/options'; import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils'; @@ -86,6 +85,7 @@ type Props = WithRouterProps & { rule: MetricRule; timePeriod: TimePeriodType; incidents?: Incident[]; + isOnDemandMetricAlert?: boolean; selectedIncident?: Incident | null; }; @@ -466,8 +466,17 @@ class MetricChart extends PureComponent { } render() { - const {api, rule, organization, timePeriod, project, interval, query, location} = - this.props; + const { + api, + rule, + organization, + timePeriod, + project, + interval, + query, + location, + isOnDemandMetricAlert, + } = this.props; const {aggregate, timeWindow, environment, dataset} = rule; // Fix for 7 days * 1m interval being over the max number of results from events api @@ -503,14 +512,6 @@ class MetricChart extends PureComponent { newAlertOrQuery: false, }); - if (isOnDemandMetricAlert(rule.dataset, rule.query)) { - return this.renderEmpty( - t( - 'This alert includes advanced conditions, which is a feature that is currently in early access. Charts are not yet supported at this time.' - ) - ); - } - return isCrashFreeAlert(dataset) ? ( { partial={false} queryExtras={queryExtras} referrer="api.alerts.alert-rule-chart" + useOnDemandMetrics={isOnDemandMetricAlert} > {({loading, timeseriesData, comparisonTimeseriesData}) => this.renderChart(loading, timeseriesData, undefined, comparisonTimeseriesData) diff --git a/static/app/views/alerts/rules/metric/triggers/chart/index.tsx b/static/app/views/alerts/rules/metric/triggers/chart/index.tsx index 1149ff263ab48d..8266279f3ea4a5 100644 --- a/static/app/views/alerts/rules/metric/triggers/chart/index.tsx +++ b/static/app/views/alerts/rules/metric/triggers/chart/index.tsx @@ -448,6 +448,7 @@ class TriggersChart extends PureComponent { partial={false} queryExtras={queryExtras} dataLoadedCallback={handleMEPAlertDataset} + useOnDemandMetrics={isOnDemandMetricAlert} > {({ loading,