testUtils.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import {InjectedRouter} from 'react-router';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import GlobalModal from 'sentry/components/globalModal';
  4. import {Organization, Project} from 'sentry/types';
  5. import {
  6. RecommendedSdkUpgrade,
  7. SamplingConditionOperator,
  8. SamplingDistribution,
  9. SamplingInnerName,
  10. SamplingInnerOperator,
  11. SamplingRule,
  12. SamplingRuleType,
  13. SamplingSdkVersion,
  14. } from 'sentry/types/sampling';
  15. import {OrganizationContext} from 'sentry/views/organizationContext';
  16. import {Outcome} from 'sentry/views/organizationStats/types';
  17. import {RouteContext} from 'sentry/views/routeContext';
  18. import ServerSideSampling from 'sentry/views/settings/project/server-side-sampling';
  19. export const outcomesWithoutClientDiscarded = {
  20. ...TestStubs.OutcomesWithReason(),
  21. groups: TestStubs.OutcomesWithReason().groups.filter(
  22. group => group.by.outcome !== Outcome.CLIENT_DISCARD
  23. ),
  24. };
  25. export const uniformRule: SamplingRule = {
  26. sampleRate: 0.5,
  27. type: SamplingRuleType.TRACE,
  28. active: false,
  29. condition: {
  30. op: SamplingConditionOperator.AND,
  31. inner: [],
  32. },
  33. id: 1,
  34. };
  35. export const specificRule: SamplingRule = {
  36. sampleRate: 0.2,
  37. active: false,
  38. type: SamplingRuleType.TRACE,
  39. condition: {
  40. op: SamplingConditionOperator.AND,
  41. inner: [
  42. {
  43. op: SamplingInnerOperator.GLOB_MATCH,
  44. name: SamplingInnerName.TRACE_RELEASE,
  45. value: ['1.2.2'],
  46. },
  47. ],
  48. },
  49. id: 2,
  50. };
  51. export const mockedProjects = [
  52. TestStubs.Project({
  53. name: 'javascript',
  54. slug: 'javascript',
  55. id: 1,
  56. }),
  57. TestStubs.Project({
  58. name: 'sentry',
  59. slug: 'sentry',
  60. platform: 'python',
  61. id: 2,
  62. }),
  63. TestStubs.Project({
  64. id: 4,
  65. dynamicSampling: {
  66. rules: [
  67. {
  68. sampleRate: 1,
  69. type: 'trace',
  70. active: false,
  71. condition: {
  72. op: 'and',
  73. inner: [],
  74. },
  75. id: 1,
  76. },
  77. ],
  78. },
  79. }),
  80. ];
  81. export const mockedSamplingSdkVersions: SamplingSdkVersion[] = [
  82. {
  83. project: mockedProjects[0].slug,
  84. latestSDKVersion: '1.0.3',
  85. latestSDKName: 'sentry.javascript.react',
  86. isSendingSampleRate: true,
  87. isSendingSource: true,
  88. isSupportedPlatform: true,
  89. },
  90. {
  91. project: mockedProjects[1].slug,
  92. latestSDKVersion: '1.0.2',
  93. latestSDKName: 'sentry.python',
  94. isSendingSampleRate: false,
  95. isSendingSource: false,
  96. isSupportedPlatform: true,
  97. },
  98. {
  99. project: 'java',
  100. latestSDKVersion: '1.0.2',
  101. latestSDKName: 'sentry.java',
  102. isSendingSampleRate: true,
  103. isSendingSource: false,
  104. isSupportedPlatform: true,
  105. },
  106. {
  107. project: 'angular',
  108. latestSDKVersion: '1.0.2',
  109. latestSDKName: 'sentry.javascript.angular',
  110. isSendingSampleRate: false,
  111. isSendingSource: false,
  112. isSupportedPlatform: false,
  113. },
  114. ];
  115. export const recommendedSdkUpgrades: RecommendedSdkUpgrade[] = [
  116. {
  117. project: mockedProjects[1],
  118. latestSDKName: mockedSamplingSdkVersions[1].latestSDKName,
  119. latestSDKVersion: mockedSamplingSdkVersions[1].latestSDKVersion,
  120. },
  121. ];
  122. export const mockedSamplingDistribution: SamplingDistribution = {
  123. project_breakdown: [
  124. {
  125. project: mockedProjects[0].slug,
  126. project_id: mockedProjects[0].id,
  127. 'count()': 888,
  128. },
  129. {
  130. project: mockedProjects[1].slug,
  131. project_id: mockedProjects[1].id,
  132. 'count()': 100,
  133. },
  134. ],
  135. sample_size: 100,
  136. null_sample_rate_percentage: 98,
  137. sample_rate_distributions: {
  138. min: 1,
  139. max: 1,
  140. avg: 1,
  141. p50: 1,
  142. p90: 1,
  143. p95: 1,
  144. p99: 1,
  145. },
  146. startTimestamp: '2017-08-04T07:52:11Z',
  147. endTimestamp: '2017-08-05T07:52:11Z',
  148. };
  149. export function getMockData({
  150. projects,
  151. access,
  152. }: {access?: string[]; projects?: Project[]} = {}) {
  153. return initializeOrg({
  154. ...initializeOrg(),
  155. organization: {
  156. ...initializeOrg().organization,
  157. features: ['server-side-sampling', 'server-side-sampling-ui'],
  158. access: access ?? initializeOrg().organization.access,
  159. projects,
  160. },
  161. projects,
  162. });
  163. }
  164. export function TestComponent({
  165. router,
  166. project,
  167. organization,
  168. withModal,
  169. }: {
  170. organization: Organization;
  171. project: Project;
  172. router: InjectedRouter;
  173. withModal?: boolean;
  174. }) {
  175. return (
  176. <RouteContext.Provider
  177. value={{
  178. router,
  179. location: router.location,
  180. params: {
  181. orgId: organization.slug,
  182. projectId: project.slug,
  183. },
  184. routes: [],
  185. }}
  186. >
  187. {withModal && <GlobalModal />}
  188. <OrganizationContext.Provider value={organization}>
  189. <ServerSideSampling project={project} />
  190. </OrganizationContext.Provider>
  191. </RouteContext.Provider>
  192. );
  193. }