Skip to content

Commit a3115d3

Browse files
committed
add conditon to util
1 parent b80dec5 commit a3115d3

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

static/app/views/alerts/rules/metric/details/body.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ import type {Anomaly, Incident} from 'sentry/views/alerts/types';
3939
import {AlertRuleStatus} from 'sentry/views/alerts/types';
4040
import {alertDetailsLink} from 'sentry/views/alerts/utils';
4141
import {DEPRECATED_TRANSACTION_ALERTS} from 'sentry/views/alerts/wizard/options';
42-
import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils';
42+
import {
43+
getAlertTypeFromAggregateDataset,
44+
getTraceItemTypeForDatasetAndEventType,
45+
} from 'sentry/views/alerts/wizard/utils';
4346

4447
import type {TimePeriodType} from './constants';
4548
import {SELECTOR_RELATIVE_PERIODS} from './constants';
@@ -110,7 +113,7 @@ export default function MetricDetailsBody({
110113
);
111114
}
112115

113-
const {dataset, aggregate, query} = rule;
116+
const {dataset, aggregate, query, eventTypes, extrapolationMode} = rule;
114117

115118
const eventType = extractEventTypeFilterFromRule(rule);
116119
const queryWithTypeFilter =
@@ -143,9 +146,12 @@ export default function MetricDetailsBody({
143146
const deprecateTransactionsAlertsWarning =
144147
ruleType && DEPRECATED_TRANSACTION_ALERTS.includes(ruleType);
145148

149+
const traceItemType = getTraceItemTypeForDatasetAndEventType(dataset, eventTypes);
150+
146151
const showExtrapolationModeWarning = getIsMigratedExtrapolationMode(
147-
rule.extrapolationMode,
148-
rule.dataset
152+
extrapolationMode,
153+
dataset,
154+
traceItemType
149155
);
150156

151157
return (

static/app/views/alerts/rules/metric/details/utils.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import {extractEventTypeFilterFromRule} from 'sentry/views/alerts/rules/metric/utils/getEventTypeFilter';
1818
import {isCrashFreeAlert} from 'sentry/views/alerts/rules/metric/utils/isCrashFreeAlert';
1919
import type {Incident} from 'sentry/views/alerts/types';
20+
import {TraceItemDataset} from 'sentry/views/explore/types';
2021

2122
/**
2223
* Retrieve start/end date of a metric alert incident for the events graph
@@ -130,10 +131,12 @@ export function getViableDateRange({
130131

131132
export function getIsMigratedExtrapolationMode(
132133
extrapolationMode: ExtrapolationMode | undefined,
133-
dataset: Dataset
134+
dataset: Dataset,
135+
traceItemType: TraceItemDataset | undefined | null
134136
) {
135137
return !!(
136138
dataset === Dataset.EVENTS_ANALYTICS_PLATFORM &&
139+
traceItemType === TraceItemDataset.SPANS &&
137140
extrapolationMode &&
138141
(extrapolationMode === ExtrapolationMode.SERVER_WEIGHTED ||
139142
extrapolationMode === ExtrapolationMode.NONE)

static/app/views/alerts/rules/metric/ruleForm.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
792792
const detectionType = detectionTypes.get(comparisonType) ?? '';
793793
const dataset = this.determinePerformanceDataset();
794794
this.setState({loading: true});
795+
const traceItemType = getTraceItemTypeForDatasetAndEventType(dataset, eventTypes);
795796
// Add or update is just the PUT/POST to the org alert-rules api
796797
// we're splatting the full rule in, then overwriting all the data?
797798
const [data, , resp] = await addOrUpdateRule(
@@ -820,7 +821,12 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
820821
sensitivity: sensitivity ?? null,
821822
seasonality: seasonality ?? null,
822823
detectionType,
823-
extrapolationMode: this.isDuplicateRule ? undefined : extrapolationMode,
824+
// We want to change the extrapolation mode to unknown once a migrated alert rule is edited
825+
extrapolationMode: this.isDuplicateRule
826+
? undefined
827+
: getIsMigratedExtrapolationMode(extrapolationMode, dataset, traceItemType)
828+
? ExtrapolationMode.UNKNOWN
829+
: extrapolationMode,
824830
},
825831
{
826832
duplicateRule: this.isDuplicateRule ? 'true' : 'false',
@@ -1378,9 +1384,12 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
13781384
const showErrorMigrationWarning =
13791385
!!ruleId && isMigration && ruleNeedsErrorMigration(rule);
13801386

1387+
const traceItemType = getTraceItemTypeForDatasetAndEventType(dataset, eventTypes);
1388+
13811389
const showExtrapolationModeChangeWarning = getIsMigratedExtrapolationMode(
13821390
extrapolationMode,
1383-
dataset
1391+
dataset,
1392+
traceItemType
13841393
);
13851394

13861395
// Rendering the main form body

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
import {capitalize} from 'sentry/utils/string/capitalize';
4747
import withApi from 'sentry/utils/withApi';
4848
import {COMPARISON_DELTA_OPTIONS} from 'sentry/views/alerts/rules/metric/constants';
49+
import {getIsMigratedExtrapolationMode} from 'sentry/views/alerts/rules/metric/details/utils';
4950
import {
5051
AlertRuleComparisonType,
5152
Dataset,
@@ -603,14 +604,20 @@ class TriggersChart extends PureComponent<Props, State> {
603604
partial: false,
604605
sampling:
605606
dataset === Dataset.EVENTS_ANALYTICS_PLATFORM &&
606-
this.props.traceItemType === TraceItemDataset.SPANS
607-
? extrapolationMode === ExtrapolationMode.NONE
608-
? SAMPLING_MODE.HIGH_ACCURACY
609-
: SAMPLING_MODE.NORMAL
607+
traceItemType === TraceItemDataset.SPANS
608+
? getIsMigratedExtrapolationMode(extrapolationMode, dataset, traceItemType)
609+
? SAMPLING_MODE.NORMAL
610+
: extrapolationMode === ExtrapolationMode.NONE
611+
? SAMPLING_MODE.HIGH_ACCURACY
612+
: SAMPLING_MODE.NORMAL
610613
: undefined,
611614

615+
// we want to show the regular extrapolated chart as we are changing the extrapolation to this
616+
// once a migrated alert is saved
612617
extrapolationMode: extrapolationMode
613-
? EAP_EXTRAPOLATION_MODE_MAP[extrapolationMode]
618+
? getIsMigratedExtrapolationMode(extrapolationMode, dataset, traceItemType)
619+
? EAP_EXTRAPOLATION_MODE_MAP[ExtrapolationMode.UNKNOWN]
620+
: EAP_EXTRAPOLATION_MODE_MAP[extrapolationMode]
614621
: undefined,
615622
};
616623

0 commit comments

Comments
 (0)