Browse Source

ref(sampling): Update analytics desc and modal cancel logic (#36843)

Priscila Oliveira 2 years ago
parent
commit
4cc1ea7d54

+ 1 - 1
static/app/types/sampling.tsx

@@ -212,7 +212,7 @@ export type UniformModalsSubmit = (props: {
   sampleRate: number;
   uniformRateModalOrigin: boolean;
   onError?: () => void;
-  onSuccess?: () => void;
+  onSuccess?: (newRules: SamplingRule[]) => void;
   recommendedSampleRate?: boolean;
   rule?: SamplingRule;
 }) => void;

+ 14 - 14
static/app/utils/analytics/samplingAnalyticsEvents.tsx

@@ -90,7 +90,7 @@ export type SamplingEventParameters = {
 type SamplingAnalyticsKey = keyof SamplingEventParameters;
 
 export const samplingEventMap: Record<SamplingAnalyticsKey, string> = {
-  'sampling.sdk.updgrades.alert': 'Recommended SDK upgrades alert',
+  'sampling.sdk.updgrades.alert': 'Recommended sdk upgrades alert',
   'sampling.settings.modal.recommended.next.steps_back': 'Go back to uniform rate step',
   'sampling.settings.modal.recommended.next.steps_cancel':
     'Cancel at recommended next steps step ',
@@ -108,17 +108,17 @@ export const samplingEventMap: Record<SamplingAnalyticsKey, string> = {
     'Switch to current uniform rate step',
   'sampling.settings.modal.uniform.rate_switch_recommended':
     'Switch to recommended next steps step',
-  'sampling.settings.modal.specific.rule.condition_add': 'Add Sampling Condition',
-  'sampling.settings.rule.specific_create': 'Create Specific Sampling Rule',
-  'sampling.settings.rule.specific_delete': 'Delete Specific Sampling Rule',
-  'sampling.settings.rule.specific_save': 'Save Specific Sampling Rule', // fired for both create and update
-  'sampling.settings.rule.specific_update': 'Update Specific Sampling Rule',
-  'sampling.settings.rule.uniform_activate': 'Activate Uniform Sampling Rule',
-  'sampling.settings.rule.uniform_create': 'Create Uniform Sampling Rule',
-  'sampling.settings.rule.uniform_deactivate': 'Deactivate Uniform Sampling Rule',
-  'sampling.settings.rule.uniform_save': 'Save Uniform Sampling Rule', // fired for both create and update
-  'sampling.settings.rule.uniform_update': 'Update Uniform Sampling Rule',
-  'sampling.settings.view': 'View Sampling Settings',
-  'sampling.settings.view_get_started': 'Get Started with Sampling',
-  'sampling.settings.view_read_docs': 'Read Sampling Docs', // fired for all read docs buttons
+  'sampling.settings.modal.specific.rule.condition_add': 'Add sampling condition',
+  'sampling.settings.rule.specific_create': 'Create specific sampling rule',
+  'sampling.settings.rule.specific_delete': 'Delete specific sampling rule',
+  'sampling.settings.rule.specific_save': 'Save specific sampling rule', // fired for both create and update
+  'sampling.settings.rule.specific_update': 'Update specific sampling rule',
+  'sampling.settings.rule.uniform_activate': 'Activate uniform sampling rule',
+  'sampling.settings.rule.uniform_create': 'Create uniform sampling rule',
+  'sampling.settings.rule.uniform_deactivate': 'Deactivate uniform sampling rule',
+  'sampling.settings.rule.uniform_save': 'Save uniform sampling rule', // fired for both create and update
+  'sampling.settings.rule.uniform_update': 'Update uniform sampling rule',
+  'sampling.settings.view': 'View sampling settings',
+  'sampling.settings.view_get_started': 'Get started with sampling',
+  'sampling.settings.view_read_docs': 'Read sampling docs', // fired for all read docs buttons
 };

+ 4 - 1
static/app/views/settings/project/server-side-sampling/modals/recommendedStepsModal.tsx

@@ -39,6 +39,7 @@ export type RecommendedStepsModalProps = ModalRenderProps & {
   recommendedSdkUpgrades: RecommendedSdkUpgrade[];
   clientSampleRate?: number;
   onGoBack?: () => void;
+  onSetRules?: (newRules: SamplingRule[]) => void;
   onSubmit?: UniformModalsSubmit;
   recommendedSampleRate?: boolean;
   serverSampleRate?: number;
@@ -60,6 +61,7 @@ export function RecommendedStepsModal({
   uniformRule,
   projectId,
   recommendedSampleRate,
+  onSetRules,
 }: RecommendedStepsModalProps) {
   const [saving, setSaving] = useState(false);
   const {projectStats} = useProjectStats({
@@ -91,8 +93,9 @@ export function RecommendedStepsModal({
       uniformRateModalOrigin: false,
       sampleRate: serverSampleRate!,
       rule: uniformRule,
-      onSuccess: () => {
+      onSuccess: newRules => {
         setSaving(false);
+        onSetRules?.(newRules);
         closeModal();
       },
       onError: () => {

+ 10 - 4
static/app/views/settings/project/server-side-sampling/modals/uniformRateModal.tsx

@@ -1,5 +1,6 @@
 import {Fragment, useEffect, useState} from 'react';
 import styled from '@emotion/styled';
+import isEqual from 'lodash/isEqual';
 
 import Alert from 'sentry/components/alert';
 import Button from 'sentry/components/button';
@@ -70,11 +71,12 @@ function UniformRateModal({
   projectStats,
   project,
   uniformRule,
-  rules,
   onSubmit,
   onReadDocs,
   ...props
 }: Props) {
+  const [rules, setRules] = useState(props.rules);
+
   const modalStore = useLegacyStore(ModalStore);
 
   const {projectStats: projectStats30d, loading: loading30d} = useProjectStats({
@@ -98,7 +100,9 @@ function UniformRateModal({
     hasFirstBucketsEmpty(projectStats, 3);
 
   useEffect(() => {
-    if (modalStore.renderer === null) {
+    // updated or created rules will always have a new id,
+    // therefore the isEqual will always work in this case
+    if (modalStore.renderer === null && isEqual(rules, props.rules)) {
       trackAdvancedAnalyticsEvent(
         activeStep === Step.RECOMMENDED_STEPS
           ? 'sampling.settings.modal.recommended.next.steps_cancel'
@@ -109,7 +113,7 @@ function UniformRateModal({
         }
       );
     }
-  }, [activeStep, modalStore.renderer, organization, project.id]);
+  }, [activeStep, modalStore.renderer, organization, project.id, rules, props.rules]);
 
   const uniformSampleRate = uniformRule?.sampleRate;
 
@@ -192,8 +196,9 @@ function UniformRateModal({
       uniformRateModalOrigin: true,
       sampleRate: server!,
       rule: uniformRule,
-      onSuccess: () => {
+      onSuccess: newRules => {
         setSaving(false);
+        setRules(newRules);
         closeModal();
       },
       onError: () => {
@@ -229,6 +234,7 @@ function UniformRateModal({
         uniformRule={uniformRule}
         projectId={project.id}
         recommendedSampleRate={!isEdited}
+        onSetRules={setRules}
       />
     );
   }

+ 1 - 1
static/app/views/settings/project/server-side-sampling/serverSideSampling.tsx

@@ -375,7 +375,7 @@ export function ServerSideSampling({project}: Props) {
           ? t('Successfully edited sampling rule')
           : t('Successfully added sampling rule')
       );
-      onSuccess?.();
+      onSuccess?.(response.dynamicSampling?.rules ?? []);
     } catch (error) {
       addErrorMessage(
         typeof error === 'string'