Browse Source

fix(alerts): query on demand metrics (#59825)

Ogi 1 year ago
parent
commit
9793b238ea

+ 19 - 0
static/app/actionCreators/events.spec.tsx

@@ -119,4 +119,23 @@ describe('Events ActionCreator', function () {
       })
     );
   });
+
+  it('spreads query extras', async function () {
+    await doEventsRequest(api, {
+      ...opts,
+      queryExtras: {useOnDemandMetrics: 'true'},
+      partial: true,
+    });
+
+    expect(mock).toHaveBeenLastCalledWith(
+      '/organizations/org-slug/events-stats/',
+      expect.objectContaining({
+        query: expect.objectContaining({
+          project: [project.id],
+          environment: [],
+          useOnDemandMetrics: 'true',
+        }),
+      })
+    );
+  });
 });

+ 0 - 1
static/app/actionCreators/events.tsx

@@ -54,7 +54,6 @@ type Options = {
   start?: DateString;
   team?: Readonly<string | string[]>;
   topEvents?: number;
-  useOnDemandMetrics?: boolean;
   withoutZerofill?: boolean;
   yAxis?: string | string[];
 };

+ 1 - 1
static/app/views/alerts/rules/metric/details/metricChart.tsx

@@ -577,6 +577,7 @@ class MetricChart extends PureComponent<Props, State> {
       location,
       dataset,
       newAlertOrQuery: false,
+      useOnDemandMetrics: isOnDemandAlert,
     });
 
     return isCrashFreeAlert(dataset) ? (
@@ -617,7 +618,6 @@ class MetricChart extends PureComponent<Props, State> {
         partial={false}
         queryExtras={queryExtras}
         referrer="api.alerts.alert-rule-chart"
-        useOnDemandMetrics={isOnDemandAlert}
       >
         {({loading, timeseriesData, comparisonTimeseriesData}) => (
           <Fragment>

+ 6 - 0
static/app/views/alerts/rules/metric/utils/getMetricDatasetQueryExtras.tsx

@@ -12,11 +12,13 @@ export function getMetricDatasetQueryExtras({
   location,
   dataset,
   newAlertOrQuery,
+  useOnDemandMetrics,
 }: {
   dataset: MetricRule['dataset'];
   newAlertOrQuery: boolean;
   organization: Organization;
   location?: Location;
+  useOnDemandMetrics?: boolean;
 }) {
   const hasMetricDataset =
     hasOnDemandMetricAlertFeature(organization) ||
@@ -29,5 +31,9 @@ export function getMetricDatasetQueryExtras({
       ? {dataset: getMEPAlertsDataset(dataset, newAlertOrQuery)}
       : {};
 
+  if (useOnDemandMetrics) {
+    queryExtras.useOnDemandMetrics = 'true';
+  }
+
   return queryExtras;
 }