Skip to content

feat(on-demand): conditionally show on-demand UI #58330

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

Merged
merged 1 commit into from
Oct 20, 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
6 changes: 2 additions & 4 deletions static/app/components/modals/widgetViewerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ import {
isEquation,
isEquationAlias,
} from 'sentry/utils/discover/fields';
import {
createOnDemandFilterWarning,
hasOnDemandMetricWidgetFeature,
} from 'sentry/utils/onDemandMetrics';
import {createOnDemandFilterWarning} from 'sentry/utils/onDemandMetrics';
import {hasOnDemandMetricWidgetFeature} from 'sentry/utils/onDemandMetrics/features';
import parseLinkHeader from 'sentry/utils/parseLinkHeader';
import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
Expand Down
20 changes: 20 additions & 0 deletions static/app/utils/onDemandMetrics/features.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Organization} from 'sentry/types';

export function hasOnDemandMetricAlertFeature(organization: Organization) {
return organization.features.includes('on-demand-metrics-extraction');
}

export function shouldShowOnDemandMetricAlertUI(organization: Organization) {
// we want to show the UI only for orgs that can create new on-demand metric alerts
return (
hasOnDemandMetricAlertFeature(organization) &&
organization.features.includes('on-demand-metrics-ui')
);
}

export function hasOnDemandMetricWidgetFeature(organization: Organization) {
return (
organization.features.includes('on-demand-metrics-extraction') &&
organization.features.includes('on-demand-metrics-extraction-experimental')
);
}
12 changes: 0 additions & 12 deletions static/app/utils/onDemandMetrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Token,
TokenResult,
} from 'sentry/components/searchSyntax/parser';
import {Organization} from 'sentry/types';
import {AggregationKey, FieldKey, getFieldDefinition} from 'sentry/utils/fields';
import {
ON_DEMAND_METRICS_UNSUPPORTED_TAGS,
Expand Down Expand Up @@ -102,14 +101,3 @@ export function getOnDemandKeys(query: string): string[] {
const searchFilterKeys = getSearchFilterKeys(query);
return searchFilterKeys.filter(isOnDemandSearchKey);
}

export function hasOnDemandMetricAlertFeature(organization: Organization) {
return organization.features.includes('on-demand-metrics-extraction');
}

export function hasOnDemandMetricWidgetFeature(organization: Organization) {
return (
organization.features.includes('on-demand-metrics-extraction') &&
organization.features.includes('on-demand-metrics-extraction-experimental')
);
}
13 changes: 10 additions & 3 deletions static/app/views/alerts/rules/metric/details/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {t, tct} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {Organization, Project} from 'sentry/types';
import {RuleActionsCategories} from 'sentry/types/alerts';
import {shouldShowOnDemandMetricAlertUI} from 'sentry/utils/onDemandMetrics/features';
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';
Expand Down Expand Up @@ -151,7 +152,10 @@ export default function MetricDetailsBody({
const isSnoozed = rule.snooze;
const ruleActionCategory = getAlertRuleActionCategory(rule);

const isOnDemandAlert = isOnDemandMetricAlert(dataset, aggregate, query);
const showOnDemandMetricAlertUI =
isOnDemandMetricAlert(dataset, aggregate, query) &&
shouldShowOnDemandMetricAlertUI(organization);

const showMigrationWarning =
hasMigrationFeatureFlag(organization) && ruleNeedsMigration(rule);

Expand Down Expand Up @@ -228,7 +232,7 @@ export default function MetricDetailsBody({
interval={getPeriodInterval()}
query={isCrashFreeAlert(dataset) ? query : queryWithTypeFilter}
filter={getFilter()}
isOnDemandAlert={isOnDemandAlert}
isOnDemandAlert={isOnDemandMetricAlert(dataset, aggregate, query)}
/>
<DetailWrapper>
<ActivityWrapper>
Expand Down Expand Up @@ -263,7 +267,10 @@ export default function MetricDetailsBody({
</DetailWrapper>
</Layout.Main>
<Layout.Side>
<MetricDetailsSidebar rule={rule} isOnDemandMetricAlert={isOnDemandAlert} />
<MetricDetailsSidebar
rule={rule}
showOnDemandMetricAlertUI={showOnDemandMetricAlertUI}
/>
</Layout.Side>
</Layout.Body>
</Fragment>
Expand Down
19 changes: 15 additions & 4 deletions static/app/views/alerts/rules/metric/details/metricChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {ReactEchartsRef, Series} from 'sentry/types/echarts';
import {getUtcDateString} from 'sentry/utils/dates';
import {getDuration} from 'sentry/utils/formatters';
import getDynamicText from 'sentry/utils/getDynamicText';
import {shouldShowOnDemandMetricAlertUI} from 'sentry/utils/onDemandMetrics/features';
import {MINUTES_THRESHOLD_TO_DISPLAY_SECONDS} from 'sentry/utils/sessions';
import theme from 'sentry/utils/theme';
import toArray from 'sentry/utils/toArray';
Expand Down Expand Up @@ -315,7 +316,8 @@ class MetricChart extends PureComponent<Props, State> {
rule,
incidents,
selectedIncident,
isOnDemandMetricAlert: this.props.isOnDemandAlert,
showWaitingForData:
shouldShowOnDemandMetricAlertUI(organization) && this.props.isOnDemandAlert,
handleIncidentClick,
});

Expand Down Expand Up @@ -496,8 +498,17 @@ class MetricChart extends PureComponent<Props, State> {
);
}

renderEmptyOnDemandAlert(timeseriesData: Series[] = [], loading?: boolean) {
if (loading || !this.props.isOnDemandAlert || !isEmptySeries(timeseriesData[0])) {
renderEmptyOnDemandAlert(
organization: Organization,
timeseriesData: Series[] = [],
loading?: boolean
) {
if (
loading ||
!this.props.isOnDemandAlert ||
!shouldShowOnDemandMetricAlertUI(organization) ||
!isEmptySeries(timeseriesData[0])
) {
return null;
}

Expand Down Expand Up @@ -610,7 +621,7 @@ class MetricChart extends PureComponent<Props, State> {
>
{({loading, timeseriesData, comparisonTimeseriesData}) => (
<Fragment>
{this.renderEmptyOnDemandAlert(timeseriesData, loading)}
{this.renderEmptyOnDemandAlert(organization, timeseriesData, loading)}
{this.renderChart(
loading,
timeseriesData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ export type MetricChartData = {
timeseriesData: Series[];
handleIncidentClick?: (incident: Incident) => void;
incidents?: Incident[];
isOnDemandMetricAlert?: boolean;
selectedIncident?: Incident | null;
showWaitingForData?: boolean;
};

type MetricChartOption = {
Expand All @@ -161,7 +161,7 @@ export function getMetricAlertChartOption({
incidents,
selectedIncident,
handleIncidentClick,
isOnDemandMetricAlert,
showWaitingForData,
}: MetricChartData): MetricChartOption {
const criticalTrigger = rule.triggers.find(
({label}) => label === AlertRuleTriggerType.CRITICAL
Expand Down Expand Up @@ -207,7 +207,7 @@ export function getMetricAlertChartOption({
createStatusAreaSeries(theme.green300, firstPoint, lastPoint, minChartValue)
);

if (isOnDemandMetricAlert) {
if (showWaitingForData) {
const {startIndex, endIndex} = getWaitingForDataRange(dataArr);
const startTime = new Date(dataArr[startIndex]?.name).getTime();
const endTime = new Date(dataArr[endIndex]?.name).getTime();
Expand Down
6 changes: 3 additions & 3 deletions static/app/views/alerts/rules/metric/details/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {AlertWizardAlertNames} from 'sentry/views/alerts/wizard/options';
import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils';

interface MetricDetailsSidebarProps {
isOnDemandMetricAlert: boolean;
rule: MetricRule;
showOnDemandMetricAlertUI: boolean;
}

function TriggerDescription({
Expand Down Expand Up @@ -123,7 +123,7 @@ function TriggerDescription({

export function MetricDetailsSidebar({
rule,
isOnDemandMetricAlert,
showOnDemandMetricAlertUI,
}: MetricDetailsSidebarProps) {
// get current status
const latestIncident = rule.latestIncident;
Expand Down Expand Up @@ -184,7 +184,7 @@ export function MetricDetailsSidebar({
/>
)}
</SidebarGroup>
{isOnDemandMetricAlert && (
{showOnDemandMetricAlertUI && (
<SidebarGroup>
<Heading>{t('Filters Used')}</Heading>
<KeyValueTable>
Expand Down
7 changes: 2 additions & 5 deletions static/app/views/alerts/rules/metric/ruleConditionsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ import {t, tct} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import {Environment, Organization, Project, SelectValue} from 'sentry/types';
import {getDisplayName} from 'sentry/utils/environment';
import {
getOnDemandKeys,
hasOnDemandMetricAlertFeature,
isOnDemandQueryString,
} from 'sentry/utils/onDemandMetrics';
import {getOnDemandKeys, isOnDemandQueryString} from 'sentry/utils/onDemandMetrics';
import {hasOnDemandMetricAlertFeature} from 'sentry/utils/onDemandMetrics/features';
import withApi from 'sentry/utils/withApi';
import withProjects from 'sentry/utils/withProjects';
import WizardField from 'sentry/views/alerts/rules/metric/wizardField';
Expand Down
11 changes: 7 additions & 4 deletions static/app/views/alerts/rules/metric/ruleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import {EventsStats, MultiSeriesEventsStats, Organization, Project} from 'sentry
import {defined} from 'sentry/utils';
import {metric, trackAnalytics} from 'sentry/utils/analytics';
import type EventView from 'sentry/utils/discover/eventView';
import {isOnDemandQueryString} from 'sentry/utils/onDemandMetrics';
import {
hasOnDemandMetricAlertFeature,
isOnDemandQueryString,
} from 'sentry/utils/onDemandMetrics';
shouldShowOnDemandMetricAlertUI,
} from 'sentry/utils/onDemandMetrics/features';
import {normalizeUrl} from 'sentry/utils/withDomainRequired';
import withProjects from 'sentry/utils/withProjects';
import {IncompatibleAlertQuery} from 'sentry/views/alerts/rules/metric/incompatibleAlertQuery';
Expand Down Expand Up @@ -798,7 +799,9 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
handleTimeSeriesDataFetched = (data: EventsStats | MultiSeriesEventsStats | null) => {
const {isExtrapolatedData} = data ?? {};

this.setState({isExtrapolatedChartData: Boolean(isExtrapolatedData)});
if (shouldShowOnDemandMetricAlertUI(this.props.organization)) {
this.setState({isExtrapolatedChartData: Boolean(isExtrapolatedData)});
}

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

const isCreatingRule = !ruleId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
} from 'sentry/types';
import type {Series} from 'sentry/types/echarts';
import type {DiscoverDatasets} from 'sentry/utils/discover/types';
import {shouldShowOnDemandMetricAlertUI} from 'sentry/utils/onDemandMetrics/features';
import {
getCrashFreeRateSeries,
MINUTES_THRESHOLD_TO_DISPLAY_SECONDS,
Expand Down Expand Up @@ -282,6 +283,7 @@ class TriggersChart extends PureComponent<Props, State> {
timeWindow,
aggregate,
comparisonType,
organization,
} = this.props;
const {statsPeriod, totalCount} = this.state;
const statsPeriodOptions = this.availableTimePeriods[timeWindow];
Expand All @@ -291,12 +293,13 @@ class TriggersChart extends PureComponent<Props, State> {
? errored || errorMessage
: errored || errorMessage || !isQueryValid;

const isExtrapolatedChartData =
const showExtrapolatedChartData =
shouldShowOnDemandMetricAlertUI(organization) &&
seriesAdditionalInfo?.[timeseriesData[0]?.seriesName]?.isExtrapolatedData;

const totalCountLabel = isSessionAggregate(aggregate)
? SESSION_AGGREGATE_TO_HEADING[aggregate]
: isExtrapolatedChartData
: showExtrapolatedChartData
? t('Estimated Transactions')
: t('Total Transactions');

Expand Down Expand Up @@ -327,7 +330,7 @@ class TriggersChart extends PureComponent<Props, State> {
thresholdType={thresholdType}
aggregate={aggregate}
minutesThresholdToDisplaySeconds={minutesThresholdToDisplaySeconds}
isExtrapolatedData={isExtrapolatedChartData}
isExtrapolatedData={showExtrapolatedChartData}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {space} from 'sentry/styles/space';
import {Organization, PageFilters} from 'sentry/types';
import {
createOnDemandFilterWarning,
hasOnDemandMetricWidgetFeature,
isOnDemandQueryString,
} from 'sentry/utils/onDemandMetrics';
import {hasOnDemandMetricWidgetFeature} from 'sentry/utils/onDemandMetrics/features';
import {decodeList} from 'sentry/utils/queryString';
import {ReleasesProvider} from 'sentry/utils/releases/releasesProvider';
import {getDatasetConfig} from 'sentry/views/dashboards/datasetConfig/base';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {Organization} from 'sentry/types';
import {AggregationKey} from 'sentry/utils/fields';
import {
hasOnDemandMetricWidgetFeature,
isOnDemandQueryString,
} from 'sentry/utils/onDemandMetrics';
import {isOnDemandQueryString} from 'sentry/utils/onDemandMetrics';
import {hasOnDemandMetricWidgetFeature} from 'sentry/utils/onDemandMetrics/features';
import {Widget, WidgetType} from 'sentry/views/dashboards/types';

/**
Expand Down