Skip to content

Commit

Permalink
removes unusued insights alerts components and logic
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardgou-sentry committed Nov 28, 2024
1 parent 2a850c1 commit 05c2958
Show file tree
Hide file tree
Showing 19 changed files with 17 additions and 639 deletions.
33 changes: 2 additions & 31 deletions static/app/components/metrics/metricSearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ import {SavedSearchType, type TagCollection} from 'sentry/types/group';
import type {MRI} from 'sentry/types/metrics';
import {hasMetricsNewInputs} from 'sentry/utils/metrics/features';
import {getUseCaseFromMRI} from 'sentry/utils/metrics/mri';
import type {MetricTag} from 'sentry/utils/metrics/types';
import {useMetricsTags} from 'sentry/utils/metrics/useMetricsTags';
import useApi from 'sentry/utils/useApi';
import useOrganization from 'sentry/utils/useOrganization';
import usePageFilters from 'sentry/utils/usePageFilters';
import {INSIGHTS_METRICS} from 'sentry/views/alerts/rules/metric/utils/isInsightsMetricAlert';
import {SpanMetricsField} from 'sentry/views/insights/types';
import {ensureQuotedTextFilters} from 'sentry/views/metrics/utils';
import {useSelectedProjects} from 'sentry/views/metrics/utils/useSelectedProjects';

Expand All @@ -34,23 +31,6 @@ export interface MetricSearchBarProps

const EMPTY_ARRAY = [];
const EMPTY_SET = new Set<never>();
const INSIGHTS_ADDITIONAL_TAG_FILTERS: MetricTag[] = [
{
key: 'has',
},
{
key: SpanMetricsField.SPAN_MODULE,
},
{
key: SpanMetricsField.FILE_EXTENSION,
},
{
key: SpanMetricsField.SPAN_SYSTEM,
},
{
key: SpanMetricsField.SPAN_GROUP,
},
];

export function MetricSearchBar({
mri,
Expand Down Expand Up @@ -80,18 +60,9 @@ export function MetricSearchBar({
blockedTags
);

const additionalTags: MetricTag[] = useMemo(
() =>
// Insights metrics allow the `has` filter.
// `span.module` is a discover field alias that does not appear in the metrics meta endpoint.
INSIGHTS_METRICS.includes(mri as string) ? INSIGHTS_ADDITIONAL_TAG_FILTERS : [],
[mri]
);

const supportedTags: TagCollection = useMemo(
() =>
[...tags, ...additionalTags].reduce((acc, tag) => ({...acc, [tag.key]: tag}), {}),
[tags, additionalTags]
() => tags.reduce((acc, tag) => ({...acc, [tag.key]: tag}), {}),
[tags]
);

const searchConfig = useMemo(
Expand Down
8 changes: 2 additions & 6 deletions static/app/utils/metrics/features.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {Organization} from 'sentry/types/organization';
import {Dataset} from 'sentry/views/alerts/rules/metric/types';
import type {AlertType} from 'sentry/views/alerts/wizard/options';

export function hasMetricsExperimentalFeature(organization: Organization) {
return organization.features.includes('custom-metrics-experimental');
Expand All @@ -26,12 +25,9 @@ export function hasMetricsNewInputs(organization: Organization) {
*/
export function getForceMetricsLayerQueryExtras(
organization: Organization,
alertDataset: Dataset,
alertType: AlertType
alertDataset: Dataset
): {forceMetricsLayer: 'true'} | Record<string, never> {
return hasCustomMetrics(organization) &&
alertDataset === Dataset.GENERIC_METRICS &&
alertType !== 'insights_metrics'
return hasCustomMetrics(organization) && alertDataset === Dataset.GENERIC_METRICS
? {forceMetricsLayer: 'true'}
: {};
}
17 changes: 0 additions & 17 deletions static/app/utils/metrics/mri.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import type {
UseCase,
} from 'sentry/types/metrics';
import {parseFunction} from 'sentry/utils/discover/fields';
import {SPAN_DURATION_MRI} from 'sentry/utils/metrics/constants';
import {INSIGHTS_METRICS_OPERATIONS} from 'sentry/views/alerts/rules/metric/utils/isInsightsMetricAlert';

export const DEFAULT_MRI: MRI = 'c:custom/sentry_metric@none';
export const DEFAULT_SPAN_MRI: MRI = 'c:custom/span_attribute_0@none';
export const DEFAULT_INSIGHTS_MRI: MRI = 'd:spans/duration@millisecond';
// This is a workaround as the alert builder requires a valid aggregate to be set
export const DEFAULT_METRIC_ALERT_FIELD = `sum(${DEFAULT_MRI})`;
export const DEFAULT_INSIGHTS_METRICS_ALERT_FIELD = `sum(${DEFAULT_INSIGHTS_MRI})`;

export const DEFAULT_EAP_FIELD = 'span.duration';
export const DEFAULT_EAP_METRICS_ALERT_FIELD = `count(${DEFAULT_EAP_FIELD})`;
Expand Down Expand Up @@ -122,19 +118,6 @@ export function isMRIField(field: string): boolean {
// convenience function to get the MRI from a field, returns defaut MRI if it fails
export function getMRI(field: string): MRI {
const parsed = parseField(field);
// Insights functions don't always take an MRI as an argument.
// In these cases, we need to default to a specific MRI.
if (parsed?.aggregation) {
const operation = INSIGHTS_METRICS_OPERATIONS.find(({value}) => {
return value === parsed?.aggregation;
});
if (operation) {
if (operation.mri) {
return operation.mri as MRI;
}
return SPAN_DURATION_MRI;
}
}
return parsed?.mri ?? DEFAULT_MRI;
}

Expand Down
3 changes: 1 addition & 2 deletions static/app/views/alerts/rules/metric/details/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
TimePeriod,
} from 'sentry/views/alerts/rules/metric/types';
import {extractEventTypeFilterFromRule} from 'sentry/views/alerts/rules/metric/utils/getEventTypeFilter';
import {isInsightsMetricAlert} from 'sentry/views/alerts/rules/metric/utils/isInsightsMetricAlert';
import {isOnDemandMetricAlert} from 'sentry/views/alerts/rules/metric/utils/onDemandMetricAlert';
import {getAlertRuleActionCategory} from 'sentry/views/alerts/rules/utils';
import type {Anomaly, Incident} from 'sentry/views/alerts/types';
Expand Down Expand Up @@ -179,7 +178,7 @@ export default function MetricDetailsBody({

return (
<Fragment>
{isCustomMetricAlert(rule.aggregate) && !isInsightsMetricAlert(rule.aggregate) && (
{isCustomMetricAlert(rule.aggregate) && (
<StyledLayoutBody>
<MetricsBetaEndAlert style={{marginBottom: 0}} organization={organization} />
</StyledLayoutBody>
Expand Down
3 changes: 1 addition & 2 deletions static/app/views/alerts/rules/metric/details/metricChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ class MetricChart extends PureComponent<Props, State> {
}
}

const alertType = getAlertTypeFromAggregateDataset(rule);
const queryExtras: Record<string, string> = {
...getMetricDatasetQueryExtras({
organization,
Expand All @@ -588,7 +587,7 @@ class MetricChart extends PureComponent<Props, State> {
newAlertOrQuery: false,
useOnDemandMetrics: isOnDemandAlert,
}),
...getForceMetricsLayerQueryExtras(organization, dataset, alertType),
...getForceMetricsLayerQueryExtras(organization, dataset),
};

if (shouldUseErrorsDataset(dataset, query)) {
Expand Down
111 changes: 0 additions & 111 deletions static/app/views/alerts/rules/metric/insightsMetricField.spec.tsx

This file was deleted.

Loading

0 comments on commit 05c2958

Please sign in to comment.