Browse Source

fix(alerts): Fix display of invalid search key (#74059)

Priscila Oliveira 8 months ago
parent
commit
fb065995fa

+ 0 - 2
static/app/components/events/searchBar.spec.tsx

@@ -370,7 +370,6 @@ describe('Events > SearchBar', function () {
     render(
       <SearchBar
         {...props}
-        metricAlert
         supportedTags={datasetSupportedTags(Dataset.ERRORS, OrganizationIs)}
       />
     );
@@ -385,7 +384,6 @@ describe('Events > SearchBar', function () {
     render(
       <SearchBar
         {...props}
-        metricAlert
         supportedTags={datasetSupportedTags(Dataset.ERRORS, OrganizationIs)}
       />
     );

+ 13 - 56
static/app/components/events/searchBar.tsx

@@ -6,24 +6,13 @@ import {fetchSpanFieldValues, fetchTagValues} from 'sentry/actionCreators/tags';
 import type {SearchConfig} from 'sentry/components/searchSyntax/parser';
 import {defaultConfig} from 'sentry/components/searchSyntax/parser';
 import SmartSearchBar from 'sentry/components/smartSearchBar';
-import {NEGATION_OPERATOR, SEARCH_WILDCARD} from 'sentry/constants';
 import type {TagCollection} from 'sentry/types/group';
 import {SavedSearchType} from 'sentry/types/group';
 import type {Organization} from 'sentry/types/organization';
 import {defined} from 'sentry/utils';
 import type {CustomMeasurementCollection} from 'sentry/utils/customMeasurements/customMeasurements';
 import type {Field} from 'sentry/utils/discover/fields';
-import {
-  ERROR_ONLY_FIELDS,
-  FIELD_TAGS,
-  isAggregateField,
-  isEquation,
-  isMeasurement,
-  SEMVER_TAGS,
-  SPAN_OP_BREAKDOWN_FIELDS,
-  TRACING_FIELDS,
-  TRANSACTION_ONLY_FIELDS,
-} from 'sentry/utils/discover/fields';
+import {isAggregateField, isEquation, isMeasurement} from 'sentry/utils/discover/fields';
 import {DiscoverDatasets} from 'sentry/utils/discover/types';
 import {
   DEVICE_CLASS_TAG_VALUES,
@@ -36,12 +25,17 @@ import useApi from 'sentry/utils/useApi';
 import withTags from 'sentry/utils/withTags';
 import {isCustomMeasurement} from 'sentry/views/dashboards/utils';
 
-const SEARCH_SPECIAL_CHARS_REGEXP = new RegExp(
-  `^${NEGATION_OPERATOR}|\\${SEARCH_WILDCARD}`,
-  'g'
-);
+import {
+  SEARCH_SPECIAL_CHARS_REGEXP,
+  STATIC_FIELD_TAGS,
+  STATIC_FIELD_TAGS_SET,
+  STATIC_FIELD_TAGS_WITHOUT_ERROR_FIELDS,
+  STATIC_FIELD_TAGS_WITHOUT_TRACING,
+  STATIC_FIELD_TAGS_WITHOUT_TRANSACTION_FIELDS,
+  STATIC_SEMVER_TAGS,
+  STATIC_SPAN_TAGS,
+} from './searchBarFieldConstants';
 
-const STATIC_FIELD_TAGS_SET = new Set(Object.keys(FIELD_TAGS));
 const getFunctionTags = (fields: Readonly<Field[]> | undefined) => {
   if (!fields?.length) {
     return [];
@@ -125,34 +119,6 @@ const getSearchConfigFromCustomPerformanceMetrics = (
   return searchConfig;
 };
 
-const STATIC_FIELD_TAGS = Object.keys(FIELD_TAGS).reduce((tags, key) => {
-  tags[key] = {
-    ...FIELD_TAGS[key],
-    kind: FieldKind.FIELD,
-  };
-  return tags;
-}, {});
-
-const STATIC_FIELD_TAGS_WITHOUT_TRACING = omit(STATIC_FIELD_TAGS, TRACING_FIELDS);
-const STATIC_FIELD_TAGS_WITHOUT_ERROR_FIELDS = omit(STATIC_FIELD_TAGS, ERROR_ONLY_FIELDS);
-const STATIC_FIELD_TAGS_WITHOUT_TRANSACTION_FIELDS = omit(
-  STATIC_FIELD_TAGS,
-  TRANSACTION_ONLY_FIELDS
-);
-
-const STATIC_SPAN_TAGS = SPAN_OP_BREAKDOWN_FIELDS.reduce((tags, key) => {
-  tags[key] = {name: key, kind: FieldKind.METRICS};
-  return tags;
-}, {});
-
-const STATIC_SEMVER_TAGS = Object.keys(SEMVER_TAGS).reduce((tags, key) => {
-  tags[key] = {
-    ...SEMVER_TAGS[key],
-    kind: FieldKind.FIELD,
-  };
-  return tags;
-}, {});
-
 export const getHasTag = (tags: TagCollection) => ({
   key: FieldKey.HAS,
   name: 'Has property',
@@ -175,7 +141,6 @@ export type SearchBarProps = Omit<React.ComponentProps<typeof SmartSearchBar>, '
    */
   maxMenuHeight?: number;
   maxSearchItems?: React.ComponentProps<typeof SmartSearchBar>['maxSearchItems'];
-  metricAlert?: boolean;
   omitTags?: string[];
   projectIds?: number[] | Readonly<number[]>;
   savedSearchType?: SavedSearchType;
@@ -187,9 +152,7 @@ function SearchBar(props: SearchBarProps) {
     maxSearchItems,
     organization,
     tags,
-    metricAlert = false,
     omitTags,
-    supportedTags,
     fields,
     projectIds,
     includeSessionTagsValues,
@@ -277,12 +240,6 @@ function SearchBar(props: SearchBarProps) {
     const measurementsWithKind = getMeasurementTags(measurements, customMeasurements);
     const orgHasPerformanceView = organization.features.includes('performance-view');
 
-    // If it is not a metric alert search bar and supportedTags has a value, return supportedTags
-    // If it is a metric alert search bar, combine supportedTags with getTagList tags
-    if (metricAlert === false && supportedTags !== undefined) {
-      return supportedTags;
-    }
-
     const combinedTags: TagCollection =
       dataset === DiscoverDatasets.ERRORS
         ? Object.assign({}, functionTags, STATIC_FIELD_TAGS_WITHOUT_TRANSACTION_FIELDS)
@@ -304,7 +261,7 @@ function SearchBar(props: SearchBarProps) {
               )
             : Object.assign({}, STATIC_FIELD_TAGS_WITHOUT_TRACING);
 
-    Object.assign(combinedTags, tagsWithKind, STATIC_SEMVER_TAGS, supportedTags);
+    Object.assign(combinedTags, tagsWithKind, STATIC_SEMVER_TAGS);
 
     combinedTags.has = getHasTag(combinedTags);
 
@@ -326,6 +283,7 @@ function SearchBar(props: SearchBarProps) {
           savedSearchType={savedSearchType}
           projectIds={projectIds}
           onGetTagValues={getEventFieldValues}
+          supportedTags={getTagList(measurements)}
           prepareQuery={query => {
             // Prepare query string (e.g. strip special characters like negation operator)
             return query.replace(SEARCH_SPECIAL_CHARS_REGEXP, '');
@@ -335,7 +293,6 @@ function SearchBar(props: SearchBarProps) {
           maxMenuHeight={maxMenuHeight ?? 300}
           {...customPerformanceMetricsSearchConfig}
           {...props}
-          supportedTags={getTagList(measurements)}
         />
       )}
     </Measurements>

+ 50 - 0
static/app/components/events/searchBarFieldConstants.ts

@@ -0,0 +1,50 @@
+import omit from 'lodash/omit';
+
+import {NEGATION_OPERATOR, SEARCH_WILDCARD} from 'sentry/constants';
+import {
+  ERROR_ONLY_FIELDS,
+  FIELD_TAGS,
+  SEMVER_TAGS,
+  SPAN_OP_BREAKDOWN_FIELDS,
+  TRACING_FIELDS,
+  TRANSACTION_ONLY_FIELDS,
+} from 'sentry/utils/discover/fields';
+import {FieldKind} from 'sentry/utils/fields';
+
+export const SEARCH_SPECIAL_CHARS_REGEXP = new RegExp(
+  `^${NEGATION_OPERATOR}|\\${SEARCH_WILDCARD}`,
+  'g'
+);
+
+export const STATIC_FIELD_TAGS_SET = new Set(Object.keys(FIELD_TAGS));
+
+export const STATIC_FIELD_TAGS = Object.keys(FIELD_TAGS).reduce((tags, key) => {
+  tags[key] = {
+    ...FIELD_TAGS[key],
+    kind: FieldKind.FIELD,
+  };
+  return tags;
+}, {});
+
+export const STATIC_FIELD_TAGS_WITHOUT_TRACING = omit(STATIC_FIELD_TAGS, TRACING_FIELDS);
+export const STATIC_FIELD_TAGS_WITHOUT_ERROR_FIELDS = omit(
+  STATIC_FIELD_TAGS,
+  ERROR_ONLY_FIELDS
+);
+export const STATIC_FIELD_TAGS_WITHOUT_TRANSACTION_FIELDS = omit(
+  STATIC_FIELD_TAGS,
+  TRANSACTION_ONLY_FIELDS
+);
+
+export const STATIC_SPAN_TAGS = SPAN_OP_BREAKDOWN_FIELDS.reduce((tags, key) => {
+  tags[key] = {name: key, kind: FieldKind.METRICS};
+  return tags;
+}, {});
+
+export const STATIC_SEMVER_TAGS = Object.keys(SEMVER_TAGS).reduce((tags, key) => {
+  tags[key] = {
+    ...SEMVER_TAGS[key],
+    kind: FieldKind.FIELD,
+  };
+  return tags;
+}, {});

+ 0 - 1
static/app/views/alerts/rules/metric/ruleConditionsForm.tsx

@@ -650,7 +650,6 @@ class RuleConditionsForm extends PureComponent<Props, State> {
                         }}
                         searchSource="alert_builder"
                         defaultQuery={initialData?.query ?? ''}
-                        metricAlert
                         {...getSupportedAndOmittedTags(dataset, organization)}
                         includeSessionTagsValues={dataset === Dataset.SESSIONS}
                         disabled={disabled || isErrorMigration}

+ 9 - 1
static/app/views/alerts/wizard/options.tsx

@@ -1,5 +1,6 @@
 import mapValues from 'lodash/mapValues';
 
+import {STATIC_FIELD_TAGS_WITHOUT_TRANSACTION_FIELDS} from 'sentry/components/events/searchBarFieldConstants';
 import {t} from 'sentry/locale';
 import ConfigStore from 'sentry/stores/configStore';
 import type {TagCollection} from 'sentry/types/group';
@@ -273,6 +274,13 @@ const INDEXED_PERFORMANCE_ALERTS_OMITTED_TAGS = [
   ...Object.values(ReplayClickFieldKey),
 ];
 
+const ERROR_SUPPORTED_TAGS = [
+  FieldKey.IS,
+  ...Object.keys(STATIC_FIELD_TAGS_WITHOUT_TRANSACTION_FIELDS).map(
+    key => key as FieldKey
+  ),
+];
+
 // Some data sets support a very limited number of tags. For these cases,
 // define all supported tags explicitly
 export function datasetSupportedTags(
@@ -281,7 +289,7 @@ export function datasetSupportedTags(
 ): TagCollection | undefined {
   return mapValues(
     {
-      [Dataset.ERRORS]: [FieldKey.IS],
+      [Dataset.ERRORS]: ERROR_SUPPORTED_TAGS,
       [Dataset.TRANSACTIONS]: org.features.includes('alert-allow-indexed')
         ? undefined
         : transactionSupportedTags(org),

+ 0 - 1
static/app/views/insights/cache/components/samplePanel.tsx

@@ -404,7 +404,6 @@ export function CacheSamplePanel() {
                 onSearch={handleSearch}
                 placeholder={t('Search for span attributes')}
                 organization={organization}
-                metricAlert={false}
                 supportedTags={supportedTags}
                 dataset={DiscoverDatasets.SPANS_INDEXED}
                 projectIds={selection.projects}

+ 0 - 1
static/app/views/insights/common/views/spanSummaryPage/sampleList/index.tsx

@@ -226,7 +226,6 @@ export function SampleList({
             onSearch={handleSearch}
             placeholder={t('Search for span attributes')}
             organization={organization}
-            metricAlert={false}
             supportedTags={supportedTags}
             dataset={DiscoverDatasets.SPANS_INDEXED}
             projectIds={selection.projects}

+ 0 - 1
static/app/views/insights/http/components/httpSamplesPanel.tsx

@@ -489,7 +489,6 @@ export function HTTPSamplesPanel() {
                 onSearch={handleSearch}
                 placeholder={t('Search for span attributes')}
                 organization={organization}
-                metricAlert={false}
                 supportedTags={supportedTags}
                 dataset={DiscoverDatasets.SPANS_INDEXED}
                 projectIds={selection.projects}

+ 0 - 1
static/app/views/insights/mobile/common/components/spanSamplesPanelContainer.tsx

@@ -204,7 +204,6 @@ export function SpanSamplesContainer({
           onSearch={handleSearch}
           placeholder={t('Search for span attributes')}
           organization={organization}
-          metricAlert={false}
           supportedTags={supportedTags}
           dataset={DiscoverDatasets.SPANS_INDEXED}
           projectIds={selection.projects}

+ 0 - 1
static/app/views/insights/queues/components/messageSpanSamplesPanel.tsx

@@ -368,7 +368,6 @@ export function MessageSpanSamplesPanel() {
                 onSearch={handleSearch}
                 placeholder={t('Search for span attributes')}
                 organization={organization}
-                metricAlert={false}
                 supportedTags={supportedTags}
                 dataset={DiscoverDatasets.SPANS_INDEXED}
                 projectIds={selection.projects}

Some files were not shown because too many files changed in this diff