Skip to content

Commit 302cb8e

Browse files
committed
feat(on-demand): conditionally show on-demand UI
1 parent 64d488f commit 302cb8e

File tree

12 files changed

+71
-46
lines changed

12 files changed

+71
-46
lines changed

Diff for: static/app/components/modals/widgetViewerModal.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ import {
4242
isEquation,
4343
isEquationAlias,
4444
} from 'sentry/utils/discover/fields';
45-
import {
46-
createOnDemandFilterWarning,
47-
hasOnDemandMetricWidgetFeature,
48-
} from 'sentry/utils/onDemandMetrics';
45+
import {createOnDemandFilterWarning} from 'sentry/utils/onDemandMetrics';
46+
import {hasOnDemandMetricWidgetFeature} from 'sentry/utils/onDemandMetrics/features';
4947
import parseLinkHeader from 'sentry/utils/parseLinkHeader';
5048
import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
5149
import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';

Diff for: static/app/utils/onDemandMetrics/features.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {Organization} from 'sentry/types';
2+
3+
export function hasOnDemandMetricAlertFeature(organization: Organization) {
4+
return organization.features.includes('on-demand-metrics-extraction');
5+
}
6+
7+
export function shouldShowOnDemandMetricAlertUI(organization: Organization) {
8+
// we want to show the UI only for orgs that can create new on-demand metric alerts
9+
return (
10+
hasOnDemandMetricAlertFeature(organization) &&
11+
organization.features.includes('on-demand-metrics-ui')
12+
);
13+
}
14+
15+
export function hasOnDemandMetricWidgetFeature(organization: Organization) {
16+
return (
17+
organization.features.includes('on-demand-metrics-extraction') &&
18+
organization.features.includes('on-demand-metrics-extraction-experimental')
19+
);
20+
}

Diff for: static/app/utils/onDemandMetrics/index.tsx

-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Token,
77
TokenResult,
88
} from 'sentry/components/searchSyntax/parser';
9-
import {Organization} from 'sentry/types';
109
import {AggregationKey, FieldKey, getFieldDefinition} from 'sentry/utils/fields';
1110
import {
1211
ON_DEMAND_METRICS_UNSUPPORTED_TAGS,
@@ -102,14 +101,3 @@ export function getOnDemandKeys(query: string): string[] {
102101
const searchFilterKeys = getSearchFilterKeys(query);
103102
return searchFilterKeys.filter(isOnDemandSearchKey);
104103
}
105-
106-
export function hasOnDemandMetricAlertFeature(organization: Organization) {
107-
return organization.features.includes('on-demand-metrics-extraction');
108-
}
109-
110-
export function hasOnDemandMetricWidgetFeature(organization: Organization) {
111-
return (
112-
organization.features.includes('on-demand-metrics-extraction') &&
113-
organization.features.includes('on-demand-metrics-extraction-experimental')
114-
);
115-
}

Diff for: static/app/views/alerts/rules/metric/details/body.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {t, tct} from 'sentry/locale';
1919
import {space} from 'sentry/styles/space';
2020
import type {Organization, Project} from 'sentry/types';
2121
import {RuleActionsCategories} from 'sentry/types/alerts';
22+
import {shouldShowOnDemandMetricAlertUI} from 'sentry/utils/onDemandMetrics/features';
2223
import MetricHistory from 'sentry/views/alerts/rules/metric/details/metricHistory';
2324
import {Dataset, MetricRule, TimePeriod} from 'sentry/views/alerts/rules/metric/types';
2425
import {extractEventTypeFilterFromRule} from 'sentry/views/alerts/rules/metric/utils/getEventTypeFilter';
@@ -151,7 +152,10 @@ export default function MetricDetailsBody({
151152
const isSnoozed = rule.snooze;
152153
const ruleActionCategory = getAlertRuleActionCategory(rule);
153154

154-
const isOnDemandAlert = isOnDemandMetricAlert(dataset, aggregate, query);
155+
const showOnDemandMetricAlertUI =
156+
isOnDemandMetricAlert(dataset, aggregate, query) &&
157+
shouldShowOnDemandMetricAlertUI(organization);
158+
155159
const showMigrationWarning =
156160
hasMigrationFeatureFlag(organization) && ruleNeedsMigration(rule);
157161

@@ -228,7 +232,7 @@ export default function MetricDetailsBody({
228232
interval={getPeriodInterval()}
229233
query={isCrashFreeAlert(dataset) ? query : queryWithTypeFilter}
230234
filter={getFilter()}
231-
isOnDemandAlert={isOnDemandAlert}
235+
isOnDemandAlert={isOnDemandMetricAlert(dataset, aggregate, query)}
232236
/>
233237
<DetailWrapper>
234238
<ActivityWrapper>
@@ -263,7 +267,10 @@ export default function MetricDetailsBody({
263267
</DetailWrapper>
264268
</Layout.Main>
265269
<Layout.Side>
266-
<MetricDetailsSidebar rule={rule} isOnDemandMetricAlert={isOnDemandAlert} />
270+
<MetricDetailsSidebar
271+
rule={rule}
272+
showOnDemandMetricAlertUI={showOnDemandMetricAlertUI}
273+
/>
267274
</Layout.Side>
268275
</Layout.Body>
269276
</Fragment>

Diff for: static/app/views/alerts/rules/metric/details/metricChart.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {ReactEchartsRef, Series} from 'sentry/types/echarts';
4545
import {getUtcDateString} from 'sentry/utils/dates';
4646
import {getDuration} from 'sentry/utils/formatters';
4747
import getDynamicText from 'sentry/utils/getDynamicText';
48+
import {shouldShowOnDemandMetricAlertUI} from 'sentry/utils/onDemandMetrics/features';
4849
import {MINUTES_THRESHOLD_TO_DISPLAY_SECONDS} from 'sentry/utils/sessions';
4950
import theme from 'sentry/utils/theme';
5051
import toArray from 'sentry/utils/toArray';
@@ -315,7 +316,8 @@ class MetricChart extends PureComponent<Props, State> {
315316
rule,
316317
incidents,
317318
selectedIncident,
318-
isOnDemandMetricAlert: this.props.isOnDemandAlert,
319+
showWaitingForData:
320+
shouldShowOnDemandMetricAlertUI(organization) && this.props.isOnDemandAlert,
319321
handleIncidentClick,
320322
});
321323

@@ -496,8 +498,17 @@ class MetricChart extends PureComponent<Props, State> {
496498
);
497499
}
498500

499-
renderEmptyOnDemandAlert(timeseriesData: Series[] = [], loading?: boolean) {
500-
if (loading || !this.props.isOnDemandAlert || !isEmptySeries(timeseriesData[0])) {
501+
renderEmptyOnDemandAlert(
502+
organization: Organization,
503+
timeseriesData: Series[] = [],
504+
loading?: boolean
505+
) {
506+
if (
507+
loading ||
508+
!this.props.isOnDemandAlert ||
509+
!shouldShowOnDemandMetricAlertUI(organization) ||
510+
!isEmptySeries(timeseriesData[0])
511+
) {
501512
return null;
502513
}
503514

@@ -610,7 +621,7 @@ class MetricChart extends PureComponent<Props, State> {
610621
>
611622
{({loading, timeseriesData, comparisonTimeseriesData}) => (
612623
<Fragment>
613-
{this.renderEmptyOnDemandAlert(timeseriesData, loading)}
624+
{this.renderEmptyOnDemandAlert(organization, timeseriesData, loading)}
614625
{this.renderChart(
615626
loading,
616627
timeseriesData,

Diff for: static/app/views/alerts/rules/metric/details/metricChartOption.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ export type MetricChartData = {
143143
timeseriesData: Series[];
144144
handleIncidentClick?: (incident: Incident) => void;
145145
incidents?: Incident[];
146-
isOnDemandMetricAlert?: boolean;
147146
selectedIncident?: Incident | null;
147+
showWaitingForData?: boolean;
148148
};
149149

150150
type MetricChartOption = {
@@ -161,7 +161,7 @@ export function getMetricAlertChartOption({
161161
incidents,
162162
selectedIncident,
163163
handleIncidentClick,
164-
isOnDemandMetricAlert,
164+
showWaitingForData,
165165
}: MetricChartData): MetricChartOption {
166166
const criticalTrigger = rule.triggers.find(
167167
({label}) => label === AlertRuleTriggerType.CRITICAL
@@ -207,7 +207,7 @@ export function getMetricAlertChartOption({
207207
createStatusAreaSeries(theme.green300, firstPoint, lastPoint, minChartValue)
208208
);
209209

210-
if (isOnDemandMetricAlert) {
210+
if (showWaitingForData) {
211211
const {startIndex, endIndex} = getWaitingForDataRange(dataArr);
212212
const startTime = new Date(dataArr[startIndex]?.name).getTime();
213213
const endTime = new Date(dataArr[endIndex]?.name).getTime();

Diff for: static/app/views/alerts/rules/metric/details/sidebar.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import {AlertWizardAlertNames} from 'sentry/views/alerts/wizard/options';
2828
import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils';
2929

3030
interface MetricDetailsSidebarProps {
31-
isOnDemandMetricAlert: boolean;
3231
rule: MetricRule;
32+
showOnDemandMetricAlertUI: boolean;
3333
}
3434

3535
function TriggerDescription({
@@ -123,7 +123,7 @@ function TriggerDescription({
123123

124124
export function MetricDetailsSidebar({
125125
rule,
126-
isOnDemandMetricAlert,
126+
showOnDemandMetricAlertUI,
127127
}: MetricDetailsSidebarProps) {
128128
// get current status
129129
const latestIncident = rule.latestIncident;
@@ -184,7 +184,7 @@ export function MetricDetailsSidebar({
184184
/>
185185
)}
186186
</SidebarGroup>
187-
{isOnDemandMetricAlert && (
187+
{showOnDemandMetricAlertUI && (
188188
<SidebarGroup>
189189
<Heading>{t('Filters Used')}</Heading>
190190
<KeyValueTable>

Diff for: static/app/views/alerts/rules/metric/ruleConditionsForm.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ import {t, tct} from 'sentry/locale';
2525
import {space} from 'sentry/styles/space';
2626
import {Environment, Organization, Project, SelectValue} from 'sentry/types';
2727
import {getDisplayName} from 'sentry/utils/environment';
28-
import {
29-
getOnDemandKeys,
30-
hasOnDemandMetricAlertFeature,
31-
isOnDemandQueryString,
32-
} from 'sentry/utils/onDemandMetrics';
28+
import {getOnDemandKeys, isOnDemandQueryString} from 'sentry/utils/onDemandMetrics';
29+
import {hasOnDemandMetricAlertFeature} from 'sentry/utils/onDemandMetrics/features';
3330
import withApi from 'sentry/utils/withApi';
3431
import withProjects from 'sentry/utils/withProjects';
3532
import WizardField from 'sentry/views/alerts/rules/metric/wizardField';

Diff for: static/app/views/alerts/rules/metric/ruleForm.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ import {EventsStats, MultiSeriesEventsStats, Organization, Project} from 'sentry
3030
import {defined} from 'sentry/utils';
3131
import {metric, trackAnalytics} from 'sentry/utils/analytics';
3232
import type EventView from 'sentry/utils/discover/eventView';
33+
import {isOnDemandQueryString} from 'sentry/utils/onDemandMetrics';
3334
import {
3435
hasOnDemandMetricAlertFeature,
35-
isOnDemandQueryString,
36-
} from 'sentry/utils/onDemandMetrics';
36+
shouldShowOnDemandMetricAlertUI,
37+
} from 'sentry/utils/onDemandMetrics/features';
3738
import {normalizeUrl} from 'sentry/utils/withDomainRequired';
3839
import withProjects from 'sentry/utils/withProjects';
3940
import {IncompatibleAlertQuery} from 'sentry/views/alerts/rules/metric/incompatibleAlertQuery';
@@ -798,7 +799,9 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
798799
handleTimeSeriesDataFetched = (data: EventsStats | MultiSeriesEventsStats | null) => {
799800
const {isExtrapolatedData} = data ?? {};
800801

801-
this.setState({isExtrapolatedChartData: Boolean(isExtrapolatedData)});
802+
if (shouldShowOnDemandMetricAlertUI(this.props.organization)) {
803+
this.setState({isExtrapolatedChartData: Boolean(isExtrapolatedData)});
804+
}
802805

803806
const {dataset, aggregate, query} = this.state;
804807
if (!isOnDemandMetricAlert(dataset, aggregate, query)) {
@@ -826,7 +829,7 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
826829
const {ruleId, organization} = this.props;
827830
const hasMetricsFeatureFlags =
828831
organization.features.includes('mep-rollout-flag') ||
829-
organization.features.includes('on-demand-metrics-extraction');
832+
hasOnDemandMetricAlertFeature(organization);
830833

831834
const isCreatingRule = !ruleId;
832835

Diff for: static/app/views/alerts/rules/metric/triggers/chart/index.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import type {
3434
} from 'sentry/types';
3535
import type {Series} from 'sentry/types/echarts';
3636
import type {DiscoverDatasets} from 'sentry/utils/discover/types';
37+
import {shouldShowOnDemandMetricAlertUI} from 'sentry/utils/onDemandMetrics/features';
3738
import {
3839
getCrashFreeRateSeries,
3940
MINUTES_THRESHOLD_TO_DISPLAY_SECONDS,
@@ -282,6 +283,7 @@ class TriggersChart extends PureComponent<Props, State> {
282283
timeWindow,
283284
aggregate,
284285
comparisonType,
286+
organization,
285287
} = this.props;
286288
const {statsPeriod, totalCount} = this.state;
287289
const statsPeriodOptions = this.availableTimePeriods[timeWindow];
@@ -291,12 +293,13 @@ class TriggersChart extends PureComponent<Props, State> {
291293
? errored || errorMessage
292294
: errored || errorMessage || !isQueryValid;
293295

294-
const isExtrapolatedChartData =
296+
const showExtrapolatedChartData =
297+
shouldShowOnDemandMetricAlertUI(organization) &&
295298
seriesAdditionalInfo?.[timeseriesData[0]?.seriesName]?.isExtrapolatedData;
296299

297300
const totalCountLabel = isSessionAggregate(aggregate)
298301
? SESSION_AGGREGATE_TO_HEADING[aggregate]
299-
: isExtrapolatedChartData
302+
: showExtrapolatedChartData
300303
? t('Estimated Transactions')
301304
: t('Total Transactions');
302305

@@ -327,7 +330,7 @@ class TriggersChart extends PureComponent<Props, State> {
327330
thresholdType={thresholdType}
328331
aggregate={aggregate}
329332
minutesThresholdToDisplaySeconds={minutesThresholdToDisplaySeconds}
330-
isExtrapolatedData={isExtrapolatedChartData}
333+
isExtrapolatedData={showExtrapolatedChartData}
331334
/>
332335
)}
333336

Diff for: static/app/views/dashboards/widgetBuilder/buildSteps/filterResultsStep/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {space} from 'sentry/styles/space';
1616
import {Organization, PageFilters} from 'sentry/types';
1717
import {
1818
createOnDemandFilterWarning,
19-
hasOnDemandMetricWidgetFeature,
2019
isOnDemandQueryString,
2120
} from 'sentry/utils/onDemandMetrics';
21+
import {hasOnDemandMetricWidgetFeature} from 'sentry/utils/onDemandMetrics/features';
2222
import {decodeList} from 'sentry/utils/queryString';
2323
import {ReleasesProvider} from 'sentry/utils/releases/releasesProvider';
2424
import {getDatasetConfig} from 'sentry/views/dashboards/datasetConfig/base';

Diff for: static/app/views/dashboards/widgetBuilder/onDemandMetricWidget/utils.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import {Organization} from 'sentry/types';
22
import {AggregationKey} from 'sentry/utils/fields';
3-
import {
4-
hasOnDemandMetricWidgetFeature,
5-
isOnDemandQueryString,
6-
} from 'sentry/utils/onDemandMetrics';
3+
import {isOnDemandQueryString} from 'sentry/utils/onDemandMetrics';
4+
import {hasOnDemandMetricWidgetFeature} from 'sentry/utils/onDemandMetrics/features';
75
import {Widget, WidgetType} from 'sentry/views/dashboards/types';
86

97
/**

0 commit comments

Comments
 (0)