Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(alerts): on demand metric alert chart #52962

Merged
merged 5 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions static/app/actionCreators/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Options = {
start?: DateString;
team?: Readonly<string | string[]>;
topEvents?: number;
useOnDemandMetrics?: boolean;
withoutZerofill?: boolean;
yAxis?: string | string[];
};
Expand Down Expand Up @@ -105,6 +106,7 @@ export const doEventsRequest = <IncludeAllArgsType extends boolean = false>(
excludeOther,
includeAllArgs,
dataset,
useOnDemandMetrics,
}: {includeAllArgs?: IncludeAllArgsType} & Options
): IncludeAllArgsType extends true
? Promise<
Expand Down Expand Up @@ -133,6 +135,7 @@ export const doEventsRequest = <IncludeAllArgsType extends boolean = false>(
referrer: referrer ? referrer : 'api.organization-event-stats',
excludeOther: excludeOther ? '1' : undefined,
dataset,
useOnDemandMetrics,
}).filter(([, value]) => typeof value !== 'undefined')
);

Expand Down
5 changes: 5 additions & 0 deletions static/app/components/charts/eventsRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions static/app/views/alerts/rules/metric/create.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('Incident Rules Create', function () {
statsPeriod: '10000m',
yAxis: 'count()',
referrer: 'api.organization-event-stats',
useOnDemandMetrics: false,
},
})
);
Expand Down
2 changes: 2 additions & 0 deletions static/app/views/alerts/rules/metric/details/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -216,6 +217,7 @@ export default class DetailsBody extends Component<Props> {
interval={this.getInterval()}
query={isCrashFreeAlert(dataset) ? query : queryWithTypeFilter}
filter={this.getFilter()}
isOnDemandMetricAlert={isOnDemandMetricAlert(dataset, query)}
/>
<DetailWrapper>
<ActivityWrapper>
Expand Down
24 changes: 13 additions & 11 deletions static/app/views/alerts/rules/metric/details/metricChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -86,6 +85,7 @@ type Props = WithRouterProps & {
rule: MetricRule;
timePeriod: TimePeriodType;
incidents?: Incident[];
isOnDemandMetricAlert?: boolean;
selectedIncident?: Incident | null;
};

Expand Down Expand Up @@ -466,8 +466,17 @@ class MetricChart extends PureComponent<Props, State> {
}

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
Expand Down Expand Up @@ -503,14 +512,6 @@ class MetricChart extends PureComponent<Props, State> {
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) ? (
<SessionsRequest
api={api}
Expand Down Expand Up @@ -549,6 +550,7 @@ class MetricChart extends PureComponent<Props, State> {
partial={false}
queryExtras={queryExtras}
referrer="api.alerts.alert-rule-chart"
useOnDemandMetrics={isOnDemandMetricAlert}
>
{({loading, timeseriesData, comparisonTimeseriesData}) =>
this.renderChart(loading, timeseriesData, undefined, comparisonTimeseriesData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ class TriggersChart extends PureComponent<Props, State> {
partial={false}
queryExtras={queryExtras}
dataLoadedCallback={handleMEPAlertDataset}
useOnDemandMetrics={isOnDemandMetricAlert}
>
{({
loading,
Expand Down