Browse Source

feat(dashboards): removes dashboards-mep flag check from frontend (#56330)

removes dashboards-mep flag check from frontend
edwardgou-sentry 1 year ago
parent
commit
3d05631eec

+ 27 - 33
static/app/utils/customMeasurements/customMeasurementsProvider.tsx

@@ -58,42 +58,36 @@ export function CustomMeasurementsProvider({
 
   useEffect(() => {
     let shouldCancelRequest = false;
+    fetchCustomMeasurements(api, organization, selection)
+      .then(response => {
+        if (shouldCancelRequest) {
+          return;
+        }
 
-    if (
-      organization.features.includes('dashboards-mep') ||
-      organization.features.includes('mep-rollout-flag')
-    ) {
-      fetchCustomMeasurements(api, organization, selection)
-        .then(response => {
-          if (shouldCancelRequest) {
-            return;
-          }
+        const newCustomMeasurements = Object.keys(
+          response
+        ).reduce<CustomMeasurementCollection>((acc, customMeasurement) => {
+          acc[customMeasurement] = {
+            key: customMeasurement,
+            name: customMeasurement,
+            functions: response[customMeasurement].functions,
+            unit: response[customMeasurement].unit,
+            fieldType: getFieldTypeFromUnit(response[customMeasurement].unit),
+          };
+          return acc;
+        }, {});
 
-          const newCustomMeasurements = Object.keys(
-            response
-          ).reduce<CustomMeasurementCollection>((acc, customMeasurement) => {
-            acc[customMeasurement] = {
-              key: customMeasurement,
-              name: customMeasurement,
-              functions: response[customMeasurement].functions,
-              unit: response[customMeasurement].unit,
-              fieldType: getFieldTypeFromUnit(response[customMeasurement].unit),
-            };
-            return acc;
-          }, {});
+        setState({customMeasurements: newCustomMeasurements});
+      })
+      .catch((e: RequestError) => {
+        if (shouldCancelRequest) {
+          return;
+        }
 
-          setState({customMeasurements: newCustomMeasurements});
-        })
-        .catch((e: RequestError) => {
-          if (shouldCancelRequest) {
-            return;
-          }
-
-          const errorResponse = t('Unable to fetch custom performance metrics');
-          addErrorMessage(errorResponse);
-          handleXhrErrorResponse(errorResponse, e);
-        });
-    }
+        const errorResponse = t('Unable to fetch custom performance metrics');
+        addErrorMessage(errorResponse);
+        handleXhrErrorResponse(errorResponse, e);
+      });
 
     return () => {
       shouldCancelRequest = true;

+ 9 - 19
static/app/views/dashboards/datasetConfig/errorsAndTransactions.tsx

@@ -232,14 +232,12 @@ function getEventsTableFieldOptions(
     tagKeys: Object.values(tags ?? {}).map(({key}) => key),
     measurementKeys: Object.values(measurements).map(({key}) => key),
     spanOperationBreakdownKeys: SPAN_OP_BREAKDOWN_FIELDS,
-    customMeasurements:
-      organization.features.includes('dashboards-mep') ||
-      organization.features.includes('mep-rollout-flag')
-        ? Object.values(customMeasurements ?? {}).map(({key, functions}) => ({
-            key,
-            functions,
-          }))
-        : undefined,
+    customMeasurements: Object.values(customMeasurements ?? {}).map(
+      ({key, functions}) => ({
+        key,
+        functions,
+      })
+    ),
   });
 }
 
@@ -457,18 +455,14 @@ function getEventsRequest(
   url: string,
   api: Client,
   query: WidgetQuery,
-  organization: Organization,
+  _organization: Organization,
   pageFilters: PageFilters,
   limit?: number,
   cursor?: string,
   referrer?: string,
   mepSetting?: MEPState | null
 ) {
-  const isMEPEnabled =
-    (organization.features.includes('dashboards-mep') ||
-      organization.features.includes('mep-rollout-flag')) &&
-    defined(mepSetting) &&
-    mepSetting !== MEPState.TRANSACTIONS_ONLY;
+  const isMEPEnabled = defined(mepSetting) && mepSetting !== MEPState.TRANSACTIONS_ONLY;
 
   const eventView = eventViewFromWidget('', query, pageFilters);
 
@@ -515,11 +509,7 @@ function getEventsSeriesRequest(
   const {environments, projects} = pageFilters;
   const {start, end, period: statsPeriod} = pageFilters.datetime;
   const interval = getWidgetInterval(displayType, {start, end, period: statsPeriod});
-  const isMEPEnabled =
-    (organization.features.includes('dashboards-mep') ||
-      organization.features.includes('mep-rollout-flag')) &&
-    defined(mepSetting) &&
-    mepSetting !== MEPState.TRANSACTIONS_ONLY;
+  const isMEPEnabled = defined(mepSetting) && mepSetting !== MEPState.TRANSACTIONS_ONLY;
 
   let requestData;
   if (displayType === DisplayType.TOP_N) {

+ 35 - 37
static/app/views/dashboards/widgetCard/index.tsx

@@ -382,44 +382,42 @@ class WidgetCard extends Component<Props, State> {
                 {this.renderToolbar()}
               </WidgetCardPanel>
             </VisuallyCompleteWithData>
-            {!organization.features.includes('performance-mep-bannerless-ui') &&
-              (organization.features.includes('dashboards-mep') ||
-                organization.features.includes('mep-rollout-flag')) && (
-                <MEPConsumer>
-                  {metricSettingContext => {
-                    return (
-                      <DashboardsMEPConsumer>
-                        {({isMetricsData}) => {
-                          if (
-                            showStoredAlert &&
-                            isMetricsData === false &&
-                            widget.widgetType === WidgetType.DISCOVER &&
-                            metricSettingContext &&
-                            metricSettingContext.metricSettingState !==
-                              MEPState.TRANSACTIONS_ONLY
-                          ) {
-                            if (!widgetContainsErrorFields) {
-                              return (
-                                <StoredDataAlert showIcon>
-                                  {tct(
-                                    "Your selection is only applicable to [indexedData: indexed event data]. We've automatically adjusted your results.",
-                                    {
-                                      indexedData: (
-                                        <ExternalLink href="https://docs.sentry.io/product/dashboards/widget-builder/#errors--transactions" />
-                                      ),
-                                    }
-                                  )}
-                                </StoredDataAlert>
-                              );
-                            }
+            {!organization.features.includes('performance-mep-bannerless-ui') && (
+              <MEPConsumer>
+                {metricSettingContext => {
+                  return (
+                    <DashboardsMEPConsumer>
+                      {({isMetricsData}) => {
+                        if (
+                          showStoredAlert &&
+                          isMetricsData === false &&
+                          widget.widgetType === WidgetType.DISCOVER &&
+                          metricSettingContext &&
+                          metricSettingContext.metricSettingState !==
+                            MEPState.TRANSACTIONS_ONLY
+                        ) {
+                          if (!widgetContainsErrorFields) {
+                            return (
+                              <StoredDataAlert showIcon>
+                                {tct(
+                                  "Your selection is only applicable to [indexedData: indexed event data]. We've automatically adjusted your results.",
+                                  {
+                                    indexedData: (
+                                      <ExternalLink href="https://docs.sentry.io/product/dashboards/widget-builder/#errors--transactions" />
+                                    ),
+                                  }
+                                )}
+                              </StoredDataAlert>
+                            );
                           }
-                          return null;
-                        }}
-                      </DashboardsMEPConsumer>
-                    );
-                  }}
-                </MEPConsumer>
-              )}
+                        }
+                        return null;
+                      }}
+                    </DashboardsMEPConsumer>
+                  );
+                }}
+              </MEPConsumer>
+            )}
           </Fragment>
         )}
       </ErrorBoundary>

+ 0 - 4
static/app/views/dashboards/widgetCard/widgetCardContextMenu.tsx

@@ -93,8 +93,6 @@ function WidgetCardContextMenu({
             {metricSettingContext => (
               <ContextWrapper>
                 {!organization.features.includes('performance-mep-bannerless-ui') &&
-                  (organization.features.includes('dashboards-mep') ||
-                    organization.features.includes('mep-rollout-flag')) &&
                   isMetricsData === false &&
                   metricSettingContext &&
                   metricSettingContext.metricSettingState !==
@@ -234,8 +232,6 @@ function WidgetCardContextMenu({
           {metricSettingContext => (
             <ContextWrapper>
               {!organization.features.includes('performance-mep-bannerless-ui') &&
-                (organization.features.includes('dashboards-mep') ||
-                  organization.features.includes('mep-rollout-flag')) &&
                 isMetricsData === false &&
                 metricSettingContext &&
                 metricSettingContext.metricSettingState !==

+ 6 - 9
static/app/views/discover/eventDetails/content.tsx

@@ -289,15 +289,12 @@ class EventDetailsContent extends DeprecatedAsyncComponent<Props, State> {
           {isSidebarVisible && (
             <Layout.Side>
               <EventVitals event={event} />
-              {(organization.features.includes('dashboards-mep') ||
-                organization.features.includes('mep-rollout-flag')) && (
-                <EventCustomPerformanceMetrics
-                  event={event}
-                  location={location}
-                  organization={organization}
-                  isHomepage={isHomepage}
-                />
-              )}
+              <EventCustomPerformanceMetrics
+                event={event}
+                location={location}
+                organization={organization}
+                isHomepage={isHomepage}
+              />
               {event.groupID && (
                 <LinkedIssue groupId={event.groupID} eventId={event.eventID} />
               )}

+ 26 - 6
static/app/views/discover/homepage.spec.tsx

@@ -18,7 +18,7 @@ import Homepage from './homepage';
 
 describe('Discover > Homepage', () => {
   const features = ['global-views', 'discover-query'];
-  let initialData, organization, mockHomepage;
+  let initialData, organization, mockHomepage, measurementsMetaMock;
 
   beforeEach(() => {
     organization = TestStubs.Organization({
@@ -76,6 +76,11 @@ describe('Discover > Homepage', () => {
         query: 'event.type:error',
       },
     });
+    measurementsMetaMock = MockApiClient.addMockResponse({
+      url: '/organizations/org-slug/measurements-meta/',
+      method: 'GET',
+      body: {},
+    });
   });
 
   it('renders the Discover banner', async () => {
@@ -178,7 +183,7 @@ describe('Discover > Homepage', () => {
     );
   });
 
-  it('does not show an editable header or author information', () => {
+  it('does not show an editable header or author information', async () => {
     render(
       <Homepage
         organization={organization}
@@ -189,6 +194,9 @@ describe('Discover > Homepage', () => {
       />,
       {context: initialData.routerContext, organization: initialData.organization}
     );
+    await waitFor(() => {
+      expect(measurementsMetaMock).toHaveBeenCalled();
+    });
 
     // 'Discover' is the header for the homepage
     expect(screen.getByText('Discover')).toBeInTheDocument();
@@ -238,7 +246,7 @@ describe('Discover > Homepage', () => {
     expect(screen.queryByText('Set as Default')).not.toBeInTheDocument();
   });
 
-  it('Disables the Set as Default button when no saved homepage', () => {
+  it('Disables the Set as Default button when no saved homepage', async () => {
     initialData = initializeOrg({
       organization,
       router: {
@@ -269,6 +277,9 @@ describe('Discover > Homepage', () => {
 
     expect(mockHomepage).toHaveBeenCalled();
     expect(screen.getByRole('button', {name: /set as default/i})).toBeDisabled();
+    await waitFor(() => {
+      expect(measurementsMetaMock).toHaveBeenCalled();
+    });
   });
 
   it('follows absolute date selection', async () => {
@@ -307,7 +318,7 @@ describe('Discover > Homepage', () => {
     expect(screen.queryByText('14D')).not.toBeInTheDocument();
   });
 
-  it('renders changes to the discover query when no homepage', () => {
+  it('renders changes to the discover query when no homepage', async () => {
     initialData = initializeOrg({
       organization,
       router: {
@@ -362,11 +373,14 @@ describe('Discover > Homepage', () => {
         loading={false}
       />
     );
+    await waitFor(() => {
+      expect(measurementsMetaMock).toHaveBeenCalled();
+    });
 
     expect(screen.getByText('event.type')).toBeInTheDocument();
   });
 
-  it('renders changes to the discover query when loaded with valid event view in url params', () => {
+  it('renders changes to the discover query when loaded with valid event view in url params', async () => {
     initialData = initializeOrg({
       organization,
       router: {
@@ -415,11 +429,14 @@ describe('Discover > Homepage', () => {
         loading={false}
       />
     );
+    await waitFor(() => {
+      expect(measurementsMetaMock).toHaveBeenCalled();
+    });
 
     expect(screen.getByText('event.type')).toBeInTheDocument();
   });
 
-  it('overrides homepage filters with pinned filters if they exist', () => {
+  it('overrides homepage filters with pinned filters if they exist', async () => {
     ProjectsStore.loadInitialData([TestStubs.Project({id: 2})]);
     jest.spyOn(pageFilterUtils, 'getPageFilterStorage').mockReturnValueOnce({
       pinnedFilters: new Set(['projects']),
@@ -443,6 +460,9 @@ describe('Discover > Homepage', () => {
       />,
       {context: initialData.routerContext, organization: initialData.organization}
     );
+    await waitFor(() => {
+      expect(measurementsMetaMock).toHaveBeenCalled();
+    });
 
     expect(screen.getByText('project-slug')).toBeInTheDocument();
   });

+ 71 - 18
static/app/views/discover/results.spec.tsx

@@ -69,6 +69,12 @@ function renderMockRequests() {
     body: [],
   });
 
+  const measurementsMetaMock = MockApiClient.addMockResponse({
+    url: '/organizations/org-slug/measurements-meta/',
+    method: 'GET',
+    body: {},
+  });
+
   const eventsResultsMock = MockApiClient.addMockResponse({
     url: '/organizations/org-slug/events/',
     body: {
@@ -205,6 +211,7 @@ function renderMockRequests() {
     mockVisit,
     mockSaved,
     eventFacetsMock,
+    measurementsMetaMock,
   };
 }
 
@@ -437,7 +444,7 @@ describe('Results', function () {
       expect(screen.queryByText('Top 5 Period')).not.toBeInTheDocument();
     });
 
-    it('needs confirmation on long queries', function () {
+    it('needs confirmation on long queries', async function () {
       const organization = TestStubs.Organization({
         features: ['discover-basic'],
       });
@@ -468,9 +475,12 @@ describe('Results', function () {
       );
 
       expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(0);
+      await waitFor(() => {
+        expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
+      });
     });
 
-    it('needs confirmation on long query with explicit projects', function () {
+    it('needs confirmation on long query with explicit projects', async function () {
       const organization = TestStubs.Organization({
         features: ['discover-basic'],
       });
@@ -507,9 +517,12 @@ describe('Results', function () {
       );
 
       expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(0);
+      await waitFor(() => {
+        expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
+      });
     });
 
-    it('does not need confirmation on short queries', function () {
+    it('does not need confirmation on short queries', async function () {
       const organization = TestStubs.Organization({
         features: ['discover-basic'],
       });
@@ -539,10 +552,13 @@ describe('Results', function () {
         }
       );
 
+      await waitFor(() => {
+        expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
+      });
       expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(1);
     });
 
-    it('does not need confirmation with to few projects', function () {
+    it('does not need confirmation with to few projects', async function () {
       const organization = TestStubs.Organization({
         features: ['discover-basic'],
       });
@@ -578,6 +594,9 @@ describe('Results', function () {
         }
       );
 
+      await waitFor(() => {
+        expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
+      });
       expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(1);
     });
 
@@ -685,7 +704,7 @@ describe('Results', function () {
       );
     });
 
-    it('updates chart whenever yAxis parameter changes', function () {
+    it('updates chart whenever yAxis parameter changes', async function () {
       const organization = TestStubs.Organization({
         features,
       });
@@ -699,7 +718,7 @@ describe('Results', function () {
 
       ProjectsStore.loadInitialData([TestStubs.Project()]);
 
-      const {eventsStatsMock} = renderMockRequests();
+      const {eventsStatsMock, measurementsMetaMock} = renderMockRequests();
 
       const {rerender} = render(
         <Results
@@ -727,6 +746,9 @@ describe('Results', function () {
           }),
         })
       );
+      await waitFor(() => {
+        expect(measurementsMetaMock).toHaveBeenCalled();
+      });
 
       // Update location simulating a browser back button action
       rerender(
@@ -754,9 +776,12 @@ describe('Results', function () {
           }),
         })
       );
+      await waitFor(() => {
+        expect(measurementsMetaMock).toHaveBeenCalled();
+      });
     });
 
-    it('updates chart whenever display parameter changes', function () {
+    it('updates chart whenever display parameter changes', async function () {
       const organization = TestStubs.Organization({
         features,
       });
@@ -768,7 +793,7 @@ describe('Results', function () {
         },
       });
 
-      const {eventsStatsMock} = renderMockRequests();
+      const {eventsStatsMock, measurementsMetaMock} = renderMockRequests();
 
       ProjectsStore.loadInitialData([TestStubs.Project()]);
 
@@ -798,6 +823,9 @@ describe('Results', function () {
           }),
         })
       );
+      await waitFor(() => {
+        expect(measurementsMetaMock).toHaveBeenCalled();
+      });
 
       // Update location simulating a browser back button action
       rerender(
@@ -825,9 +853,12 @@ describe('Results', function () {
           }),
         })
       );
+      await waitFor(() => {
+        expect(measurementsMetaMock).toHaveBeenCalled();
+      });
     });
 
-    it('updates chart whenever display and yAxis parameters change', function () {
+    it('updates chart whenever display and yAxis parameters change', async function () {
       const organization = TestStubs.Organization({
         features,
       });
@@ -839,7 +870,7 @@ describe('Results', function () {
         },
       });
 
-      const {eventsStatsMock} = renderMockRequests();
+      const {eventsStatsMock, measurementsMetaMock} = renderMockRequests();
 
       ProjectsStore.loadInitialData([TestStubs.Project()]);
 
@@ -869,6 +900,9 @@ describe('Results', function () {
           }),
         })
       );
+      await waitFor(() => {
+        expect(measurementsMetaMock).toHaveBeenCalled();
+      });
 
       // Update location simulating a browser back button action
       rerender(
@@ -900,6 +934,9 @@ describe('Results', function () {
           }),
         })
       );
+      await waitFor(() => {
+        expect(measurementsMetaMock).toHaveBeenCalled();
+      });
     });
 
     it('appends tag value to existing query when clicked', async function () {
@@ -1308,7 +1345,7 @@ describe('Results', function () {
       expect(await screen.findByText('Set as Default')).toBeInTheDocument();
     });
 
-    it('links back to the homepage through the Discover breadcrumb', () => {
+    it('links back to the homepage through the Discover breadcrumb', async () => {
       const organization = TestStubs.Organization({
         features: ['discover-basic', 'discover-query'],
       });
@@ -1321,7 +1358,7 @@ describe('Results', function () {
       });
 
       ProjectsStore.loadInitialData([TestStubs.Project()]);
-      renderMockRequests();
+      const {measurementsMetaMock} = renderMockRequests();
 
       render(
         <Results
@@ -1334,13 +1371,17 @@ describe('Results', function () {
         {context: initialData.routerContext, organization}
       );
 
+      await waitFor(() => {
+        expect(measurementsMetaMock).toHaveBeenCalled();
+      });
+
       expect(screen.getByText('Discover')).toHaveAttribute(
         'href',
         expect.stringMatching(new RegExp('^/organizations/org-slug/discover/homepage/'))
       );
     });
 
-    it('links back to the Saved Queries through the Saved Queries breadcrumb', () => {
+    it('links back to the Saved Queries through the Saved Queries breadcrumb', async () => {
       const organization = TestStubs.Organization({
         features: ['discover-basic', 'discover-query'],
       });
@@ -1351,7 +1392,7 @@ describe('Results', function () {
           location: {query: {id: '1'}},
         },
       });
-      renderMockRequests();
+      const {measurementsMetaMock} = renderMockRequests();
 
       render(
         <Results
@@ -1364,13 +1405,17 @@ describe('Results', function () {
         {context: initialData.routerContext, organization}
       );
 
+      await waitFor(() => {
+        expect(measurementsMetaMock).toHaveBeenCalled();
+      });
+
       expect(screen.getByRole('link', {name: 'Saved Queries'})).toHaveAttribute(
         'href',
         expect.stringMatching(new RegExp('^/organizations/org-slug/discover/queries/'))
       );
     });
 
-    it('allows users to Set As Default on the All Events query', () => {
+    it('allows users to Set As Default on the All Events query', async () => {
       const organization = TestStubs.Organization({
         features: ['discover-basic', 'discover-query'],
       });
@@ -1391,7 +1436,7 @@ describe('Results', function () {
       });
 
       ProjectsStore.loadInitialData([TestStubs.Project()]);
-      renderMockRequests();
+      const {measurementsMetaMock} = renderMockRequests();
 
       render(
         <Results
@@ -1404,10 +1449,14 @@ describe('Results', function () {
         {context: initialData.routerContext, organization}
       );
 
+      await waitFor(() => {
+        expect(measurementsMetaMock).toHaveBeenCalled();
+      });
+
       expect(screen.getByTestId('set-as-default')).toBeEnabled();
     });
 
-    it("doesn't render sample data alert", function () {
+    it("doesn't render sample data alert", async function () {
       const organization = TestStubs.Organization({
         features: ['discover-basic', 'discover-query'],
       });
@@ -1425,7 +1474,7 @@ describe('Results', function () {
           },
         },
       });
-      renderMockRequests();
+      const {measurementsMetaMock} = renderMockRequests();
 
       render(
         <Results
@@ -1438,6 +1487,10 @@ describe('Results', function () {
         {context: initialData.routerContext, organization}
       );
 
+      await waitFor(() => {
+        expect(measurementsMetaMock).toHaveBeenCalled();
+      });
+
       expect(screen.queryByText(/Based on your search criteria/)).not.toBeInTheDocument();
     });
   });

+ 6 - 8
static/app/views/discover/table/columnEditModal.tsx

@@ -63,14 +63,12 @@ function ColumnEditModal(props: Props) {
     tagKeys,
     measurementKeys,
     spanOperationBreakdownKeys,
-    customMeasurements:
-      organization.features.includes('dashboards-mep') ||
-      organization.features.includes('mep-rollout-flag')
-        ? Object.values(customMeasurements ?? {}).map(({key, functions}) => ({
-            key,
-            functions,
-          }))
-        : undefined,
+    customMeasurements: Object.values(customMeasurements ?? {}).map(
+      ({key, functions}) => ({
+        key,
+        functions,
+      })
+    ),
   });
   return (
     <Fragment>